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

Smart Table paging is showing more pages than expected #774

Closed mostafaasad closed 7 years ago

mostafaasad commented 7 years ago

I am using Smart table in angularjs application. In the pagination it is showing extra pages which don't have the data. How can I display the exact number of pages instead of extra pages?

For clarification, I have 94 records, 15 per page so there will be 7 pages , but the pagination is showing 10 pages, after 7th page there is no data in 8-10th pages. Please suggest how can I resolve this.

MrWook commented 7 years ago

Hello @mostafaasad,

can you provide us with more information? Like do you use a pipeline or not? A plunker with an example of your problem would be perfect

mostafaasad commented 7 years ago

Hi @MrWook, I am using st-table in angularjs view and using the pagination where the pages are being displayed more than what the actual pages are. Extra pages with empty data are being displayed. BTW, I am using server side data in the view.

Regards, Mostafa

MrWook commented 7 years ago

Hello @mostafaasad,

unfortunately this doesn't answer my question. You wrote the same things as before except that you mentioned that you get the data from a Server. This could mean that you using a pipeline or that you use a normal http request. I'm still lacking of information. I just assume that you are using a pipeline if that's the case:

you must set in your pipe function, the total number of pages as smart-table has no clue about your dataset and this information has to come from your server.

If you don't use the pipeline be sure that you are using the st-safe-src when you get the data asynchronously. Also you can set the items by page with st-items-by-page and the displayed pages with st-displayed-pages, pls look into the documentation

kvharish commented 7 years ago

Hello @mostafaasad ,

Since you are using pipeline, I would recommend you to get the total number of records from the api response.

You are showing 15 records per page so in your html you will be including st-items-by-page="15"

Say you are getting the total number of records as 94 in your api response then tableState.pagination.numberOfPages = Math.ceil(data.totalNumbersOfRecords / itemsByPage);

Hope it helps.