datatables 1.10.4 aoColumnsDefs

datatables 1.10.4 aoColumnsDefs

本文关键字:aoColumnsDefs datatables      更新时间:2023-09-26

//Use angularjs render data 
app.controller('ArticleListController', ['$scope', '$http', function ($scope, $http) {
    $scope.options = {
        sAjaxSource: 'api/datatable.json',
        "aoColumnDefs": [
                  { mData: 'engine', "aTargets": [0] },
                  { mData: 'browser', "aTargets": [1] },
                  { mData: 'platform', "aTargets": [2] },
                  { mData: 'version', "aTargets": [3] },
                  {
                      mData: 'grade', "aTargets": [4],
                      //Here ! It can't do work 
                      "mRender": function (data, type, full) {
                          return '<a class="glyphicon glyphicon-pencil" href="/Country/Edit/' + data + '">Edit</a><a class="glyphicon glyphicon-remove" href="/Country/Delete/' + data + '">Delete</a>';
                      }
                  },
        ] 
    } 
}]);
//this is html
<div class="bg-light lter b-b wrapper-md">
    <h1 class="m-n font-thin h3">Datatable</h1>
</div>
<div class="wrapper-md">
    <div class="panel panel-default">
        <div class="panel-heading">
            DataTables
        </div>
        <div class="table-responsive">
            <table ui-jq="dataTable" ui-options="{{options}}" class="table table-striped b-t b-b">
                <thead>
                    <tr>
                        <th style="width:20%">Rendering engine</th>
                        <th style="width:25%">Browser</th>
                        <th style="width:25%">Platform(s)</th>
                        <th style="width:15%">Engine version</th>
                        <th style="width:15%">CSS grade</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
</div>
 

我想自定义列样式,例如,我想在单元格中显示链接,但我的mRender函数无法工作,请帮助我!谢谢。。。。。。。。。。。。。。。。。。

好吧,我解决了这个问题。

angular.controller('myController', function($scope) {
  $scope.options = {
     data: dset,
     aoColumns: [
      { mData: 'title' },
      { mData: 'firstName' },
      { mData: 'lastName' },
      { mData: 'email' }
     ],
     "aoColumnDefs": [  {
      "aTargets": [ 3 ],                                                 
      "mRender": function ( data, type, full ) {
       return '<a href="/mailto/' + full[3] + '">' + data + '</a>';
      }
     }
   ]
  };
});
//Here ! the ui-options='options'
<table ui-jq="dataTable" ui-options="options" class="table table-striped m-b-none">

因此,我的代码ui options="{{options}}",正确的代码应该是ui options=‘options’