angular-datatables icon indicating copy to clipboard operation
angular-datatables copied to clipboard

recordsDisplay (or page.info()) to get filtered counts

Open srikarshastry opened this issue 11 years ago • 4 comments

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.

srikarshastry avatar Sep 02 '15 17:09 srikarshastry

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());
    }
}

l-lin avatar Sep 03 '15 15:09 l-lin

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.

srikarshastry avatar Sep 03 '15 15:09 srikarshastry

How does one watch to get the pageInfo counts automatically instead of having to press a button to do so>

nigel-dewar avatar Oct 10 '16 04:10 nigel-dewar

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> `

ivanstojkovicapps avatar Jan 24 '17 16:01 ivanstojkovicapps