Ajax call changing page

Ajax call changing page

jolio007jolio007 Posts: 5Questions: 2Answers: 0

Hello,
I have around a 1000 rows of data. I only want to do one ajax call per page. So I made an api so that I get 10 rows per page.
api/allusers?page=1 -> would give me page 1.
How can I modify the following
"ajax":{ "url" : "http://127.0.0.1:8000/api/allusers?page=1", "dataSrc": "" }
so that I get :
1. The correct amount of pages -> when I do page=1, I get only 10 data so it says that I only have one page.
2. That when I click on number X of page, it changes page= to the one selected

Thank you for you help !

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Why re-invent the wheel? DataTables does all that by default.
    https://datatables.net/examples/basic_init/zero_configuration.html

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Also, that sounds a lot like serverSide processing - see examples here.

    Cheers,

    Colin

  • jolio007jolio007 Posts: 5Questions: 2Answers: 0

    @tangerine
    If my api gives me all the data 1000 data, yes, it works really well and does it all by itself. However, it's not as fast as if I only pulled out 10 or 20 data and only asked for the next 10/20 if I needed it.

    @colin
    Thank you, I'm using it however I don't know and can't find how to customise it to how I want it

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    For server side processing, enable serverSide. The protocol is discussed here. Also see examples here.

    Cheers,

    Colin

  • jolio007jolio007 Posts: 5Questions: 2Answers: 0

    I figured it out.
    I had already serverSide enabled. However, I didn't have 'recordsTotal' and 'recordsFiltered' in the ajax.

This discussion has been closed.