Datatable- pagination,sorting on client json object

Datatable- pagination,sorting on client json object

roshantarudkarroshantarudkar Posts: 2Questions: 1Answers: 0

Hi,

I have json object which has almost 40k json array which is available at client side.. out of that I am taking only 1000 records from json object and again storing in another json object i.e abcJson then i am assigning that abcJson object to datatable..so far so good..i am able to see 1000 records on datatable...using data: abcJson .
Now i want to do pagination/sorting..on pagination/sorting it should lookup on 40k json object available at client and then filter out 1000 records and reassign to datatable..

Note: all these is happening at client side..i dont want to connect to server side...all i need to do filter 1000 records from available 40k records..at bind only 1000 records at a time to datatable so that datatable wont choke.

I read some thread about datatable but couldnt find answer which suits my requirement.

Any solutions,Pls?

Thanks,
Roshan

Answers

  • allanallan Posts: 63,765Questions: 1Answers: 10,510 Site admin

    You would need to implement server-side processing on the client-side with ajax as a function. However, that would mean reimplementing search, sort and paging on the client-side, rather than just using DataTables to do it. You can do that if you want, but it won't be easy :-).

    DataTables should cope okay with 40k records - perhaps you can link to a page showing that many records so I can profile it in your configuration.

    Allan

  • roshantarudkarroshantarudkar Posts: 2Questions: 1Answers: 0
    edited March 2016

    @allan -If i use ajax options , it means i will be connecting to server/external urls..In my case i have json object sitting at client side..and i want to make use of that object but want to show only 1000 records at a time from master json object...
    if i use ajax function then how will i do that?

    var completJson=[blah blah] ==> it has 40k records in the completJson variable..
    var sortedRecords =[blah blah] === > 1000 records out of 40k. thats also in one variable..
    how will i get these object values through ajax function could you pls provide sample code snippet...

    i see below sample code but whats my data ,callback settings?

    $('#example').dataTable( {
      "ajax": function (data, callback, settings) {
        callback(
          sortedRecords
        );
      }
    } );
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,765Questions: 1Answers: 10,510 Site admin

    The code you show above is basically exactly what you need. I'm afraid I can't implement a demo script that will do the sorting, filtering and paging for you - that would likely take several hours to do, but basically you need to use the information in data to get the rows to be displayed.

    I still don't really see that there will be much benefit in writing your own sorting, filtering and paging code rather than using DataTables' code to do exactly the same thing - but that's up to you :-)

    Allan

This discussion has been closed.