1

I am facing an issue in javascript datatables. I want to add pagination in table

My Code

// i want to pass get api in datatable .. how should i do

 $('#example').dataTable( {
  "pagingType": "simple",
  "searching": false,
  "bFilter": false,
  "ajax": 'https://gencomp.com/api/v2/emails',   //not working
   "order": [[ 0, "desc" ]]
 } );

API:

`https://gencomp.com/api/v2/emails?per_page=100&page=${page}`;

i want to display my page1 and page2 and so on.. previous and next can't move on page2

how can i do? anyone please help me?

Screenshot

enter image description here

Community
  • 1
  • 1
adnan khan
  • 101
  • 1
  • 3
  • 7
  • You need to include `"serverSide": true` - see [here](https://datatables.net/examples/data_sources/server_side.html). DataTables automatically sends a request to your server whenever you click on a page button, or you perform a sort or a filter. The server then needs to read this request to assemble the correct response. Full details are [here](https://datatables.net/manual/server-side), where you can see the info DataTables sends, and how the server is expected to respond. – andrewJames May 21 '20 at 17:43
  • See also this question and [answer](https://stackoverflow.com/questions/60801535/how-can-i-load-a-set-number-of-rows-from-a-table-on-pageload-and-only-load-furth/60804184#60804184) for an example. – andrewJames May 21 '20 at 17:45
  • how should i pass my api data in datatables [@](https://stackoverflow.com/users/12567365/andrewjames) – adnan khan May 21 '20 at 17:47
  • You don't. DataTables does it for you. See the above comments. Perhaps you are asking a different question from the one I think you are asking. If so, I'm sorry, but I'm not sure what exactly you are asking. – andrewJames May 21 '20 at 18:01
  • ok i look your above comment [@](https://stackoverflow.com/users/12567365/andrewjames) – adnan khan May 21 '20 at 18:03
  • i just ask how i pass my `url: 'http://localhost:7000/data'` [@](https://stackoverflow.com/users/12567365/andrewjames) – adnan khan May 21 '20 at 18:03
  • Take a look at the example in the answer I linked to above. – andrewJames May 21 '20 at 18:10
  • yes thanks your answer it will help me [@](https://stackoverflow.com/users/12567365/andrewjames) – adnan khan May 21 '20 at 18:15
  • one more thing i ask? why we use `post` in url ? explain plz? [@](https://stackoverflow.com/users/12567365/andrewjames) – adnan khan May 21 '20 at 18:16
  • That is a great question. There are several answers & viewpoints (and some disagreements) - take a look [here](https://stackoverflow.com/questions/504947/when-should-i-use-get-or-post-method-whats-the-difference-between-them) for a start. – andrewJames May 21 '20 at 18:37

0 Answers0