2

I have created a new custom data source which extends the local Data Source. So that I am able to get all the records in the database. But that's not the case, because I have a thousand records in my database. So the above implementation is not efficient.

Now I tried to implement the server side pagination to it. I have gone through the GitHub ng2-smart-table issues(https://github.com/akveo/ng2-smart-table/issues/30). But I couldn't find the correct solution to it. So could you please help with it.

Thanks in advance.

grk
  • 31
  • 1
  • 3
  • which database are you using? what have you already tried? any code? – jcuypers Mar 19 '19 at 22:46
  • This is my solution https://stackoverflow.com/questions/44669968/ng2-smart-table-with-paging-from-back-end-spring/55606968#55606968 – boyukbas Apr 10 '19 at 10:43
  • anyone here pls help me out with this question I too have a scenario where I need to change my component to server-side pagination, unable to find the solution pls help thanks in advance – Ram Oct 29 '20 at 11:35

3 Answers3

1

This is my solution for server side pagination

ng2-smart-table with paging from back-end (Spring)

I have a filter which contains startIndex and recordCount information. You should make sure that you only return requested amount of data from your API/DB/etc.

boyukbas
  • 1,137
  • 16
  • 24
1

This was my solution..

  1. Return your data from the DB or API like this.
data: [{,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}, {,…}] total: 10
  1. Fetch the data like this while specifying the datakey and totalkey names exactly how they were returned in the 1st step.
return new ServerDataSource(this.http, {
  endPoint: endpointUrl,
  dataKey: 'data',
  totalKey: 'total',
});
  1. In your table settings, show pager and set perPage < expected total for the paginator shows up.
settings = {
  pager: {
    display: true,
    perPage: 5,
  }
}
George Trad
  • 51
  • 1
  • 1
  • 5
0

your database will probably support something like skip/limit functionality. based on this the client code can make requests to the database in order to return partial results.

jcuypers
  • 1,774
  • 2
  • 14
  • 23
  • I am using mysql databse. so i can do skip/limit functioality. But my problem is to implement the same functionality in the ng2-smart-table. Because i have written my own DataSource which extends the LocalDataSource for it as i mentioned above github link. But i couldn't figure it out, how he has done the pagination. – grk Mar 20 '19 at 07:50