javascriptangularjspaginationngtable

How to set/get number of displayed rows on ng-table


The AngularJS ng-table offers a pagination functionality by default. On the bottom right there are buttons where the number of displayed records per page can be selected.

Example for the pagination

Is there a possibility to get the selected number and also set the number which is selected?


Solution

  • After defining the parameters for the table:

    var tableParams = new NgTableParams({}, {
        counts: [10, 20, 30, 50, 100],          // custom number of records options
        dataset: ...
    });
    
    You can get and set the number of records with the following code:
    tableParams.count()   // get
    tableParams.count(25) // set
    

    By the way: In the same way you can get and set the number of the current page:

    tableParams.page()    // get
    tableParams.page(2)   // set