recordsDisplay (or page.info()) to get filtered counts
Hello,
Is it possible to display filtered records as a separate object when used in "Angular way"?
With the requirements for not to show the page info (.withOption('info', false)), I'm stuck with the issue that when user tries to filter (.withOption('filter', true)), the total number of filtered records should be displayed.
Traditional ng-repeat has this option:
<div ng-repeat="person in filtered = (data | filter: query)"></div>
and to display:
<p ng-bind="filtered.length"></p>
but how to get the same when using angular-datatables angular way?
After doing some research, i found out that in traditional datatables, we have make use of page.info() API method call to get the information and then do recordsDisplay to get the filtered count. Is there an elegant way to do it? If so, can anyone please show me how?
Thank you.
If you can fetch it with page.info() then you can use the dtInstance directive:
<div ng-controller="YourCtrl as showCase">
<button ng-click="showCase.showPageInfo()">Show page info</button>
<table datatable dt-options="showCase.dtOptions" dt-instance="showCase.dtInstance">
</table>
</div>
angular.module('yourApp', ['datatables'])
.controller('YourCtrl', YourCtrl);
function YourCtrl(DTOptionsBuilder) {
var vm = this;
vm.dtOptions = DTOptionsBuilder.newOptions()...
vm.dtInstance = {};
vm.showPageInfo = showPageInfo;
function showPageInfo() {
console.log(vm.dtInstance.DataTable.page.info());
}
}
Yes sir, it worked. In my case, I cannot trigger the pageInfo on click but got it to work when the datatable is rendered.
Thank you.
How does one watch to get the pageInfo counts automatically instead of having to press a button to do so>
Just set dt-instance="c.dtInstance" like this
ng-controller="ArtikelCtrl as c"
...
<table datatable="" dt-instance="c.dtInstance" class="row-border hover">
...
<div>Page {{c.dtInstance.DataTable.page.info()}}</div>
`