Recently, I am developing Apps by using angular datatables.
The followings are some issues or note that I have to record.
Datatable Options
Selected datatable options…
vm.dtOptions = DTOptionsBuilder.newOptions() |
More options and instruction can refer datatable options.
Reloading Datatable
Calling dtInstance..rerender()
…
<table datatable="ng" dt-options="ps.dtOptions" dt-instance="ps.dtInstance"> |
$scope.reloadData = function () { |
Create a New Filter
Create a new filter for datatable by calling function $.fn.dataTableExt.afnFiltering.push(function (oSettings, aData, iDataIndex) {}
.
Then, redraw the table, dtInstance.dataTable.fnDraw()
, to apply the filter.
For example:vm.reloadDataByFilter = function () {
$.fn.dataTableExt.afnFiltering.push(function (oSettings, aData, iDataIndex) {
// `aData` returns current data array in the table
{ // some logic here...
var val = aData.slice(5);
var res = false;
angular.forEach(val, function (v, k) {
v = Number(v.replace(/[^0-9\.]+/g, "")); //remove currency symbol
res = vm.checkValue(v, aData[4], aData[3]) || res;
if (res) return res;
});
return res;
}
});
vm.dtInstance.dataTable.fnDraw();
};
<%--angular-datatables - v0.5.2--%> |
When the data is changed, the buttons such as ‘Copy’, ‘Print’ and ‘CSV’ from datatable-buttons plugin disappear.
Cause: It seems the datatable dose not redraw the options like button plugin after data change.
Solution:
We can manually add button-options by using angular-datatable drawCallback function, where the function is called every time DataTables performs a draw.
var buttonsOpt = [ |
Ref: