lorenzofox3 / Smart-Table

Code source of Smart Table module: a table/grid for Angularjs
http://lorenzofox3.github.io/smart-table-website/
1.8k stars 513 forks source link

Update dynamically the number of rows to display and the total number of pages #759

Closed kvharish closed 7 years ago

kvharish commented 7 years ago

I am using angular smart table to display a list of user information along with the custom pagination to navigate between the pages.

You can find the example code at the end of the smart table documentation under the heading Custom pagination http://lorenzofox3.github.io/smart-table-website/

I am getting the list of users from an api call. Along with that I will be also getting the total number of users available in the database and calculate the total number of pages it will take to display it so that I can display it on the pagination like 1 of 100 or 1 of 200.

For this purpose I want to dynamically set the number of rows displayed and also the total number of pages.

I am using st-items-by-page="10" in my template to limit the number of rows displayed in my list.

I am using st-pipe="updateList" in my template to call the function updateList and inside the function I am assigning tableState.pagination.numberOfPages = 100;

Both are working fine separately but when I use them together, the total number of pages on the pagination gets updated but the limit breaks and all the data is showed at a single stretch.

I used tableState.pagination.number = 10; in my function instead of st-items-by-page="10" but still it does not work.

I used st-displayed-pages="100" in my template instead of tableState.pagination.numberOfPages = 100; but did not work.

Is there a way I can update the total number of pages showed on the pagination and also limit the number of rows to be shown per page?

MrWook commented 7 years ago

Hello @kvharish,

i can't really help you to find a mistake in your code if you don't provide us with a plunk but here is a snippet from my code for the number of pages:

 <div st-pagination="" st-items-by-page="items_by_page" class="col-md-6"></div>
  ....
  $scope.items_by_page = 20;
  var numberOfPages = 0;
  this.callServer = function callServer(tableState) {
        ....
        if(typeof pagination == 'undefined')
            var pagination = tableState.pagination;
        //SmartTable options
        $scope.options = {
            start: pagination.start,
            number: pagination.number,
            ....
            numberOfPages: numberOfPages
        };
        ....
        //request to get the data from database DON'T TOUCH IT
        SmartTable_pipeline.getPage(tableState, $scope.options).then(function (result) {
            numberOfPages = result.numberOfPages;
            ....
            //set table pagination parameters
            tableState.pagination = {
                start: $scope.options.start, // start index
                number: $scope.options.number, //number of item on a page
                numberOfPages: result.numberOfPages //total number of pages
            };
        ....
        });
    };
....
kvharish commented 7 years ago

Hi I understood what the problem is. I was having data more than my items per page. we have to get data which we are showing in a single page alone. Closing this issue.