How to visualize a model-bound column using angular -datatables?

Is there a way to render a column with model binding in a text box using DTColumnBuilder?

Sort of:

DTColumnBuilder.newColumn('ColumnName').withTitle('Column Name').renderWith(function (data) {
   return '<input type="text" ng-model="ColumnName" />';
}),
+4
source share
2 answers

No. You can display the table (example):

DTColumnBuilder.newColumn('firstName', 'First name')
  .renderWith(function (data) {
       return '<input type="text" ng-model="json.firstName" />'
}),

but it is ng-modelnever recognized because it is not the angular itself that renders. If you let angular render, that is, datatable="ng"and ng-repeatit works:

<table datatable="ng" dt-options="dtOptions" dt-columns="dtColumns">
   <tr ng-repeat="item in json">
       <td>{{ item.id }} </td>
       <td><input ng-model="item.firstName"/></td>
       <td>{{ item.lastName }} </td>
   </tr>
</table> 

demo → http://plnkr.co/edit/f0ycjJvsACaumY13IVUZ?p=preview note that JSON elements are updated when you edit the input fields.

+4
source

, :

  • dtInstance
  • "draw.dt" DataTable $ html angular

:

HTML:

<table datatable=""
       dt-options="vm.dtOptions"
       dt-columns="vm.dtColumns"
       dt-instance="vm.dtInstanceCallback"
       class="table table-bordered table-condensed">
</table>

JS:

renderWith(function(data, type, full) {
    return `<a class="ng-scope"><span ng-click='vm.remove("${data}")' class='fa fa-times-circle'></span></a>`
});
...
vm.dtInstanceCallback = (dtInstance) => {
    vm.dtInstance = dtInstance;
    dtInstance.DataTable.on('draw.dt', () => {
        let elements = angular.element("#" + dtInstance.id + " .ng-scope");
        angular.forEach(elements, (element) => {
            $compile(element)($scope)
        })
    });
}

, , , . Chrome Safari,

+2

Source: https://habr.com/ru/post/1614213/


All Articles