client side sorting, filtering but server side paging

client side sorting, filtering but server side paging

frankzhangfrankzhang Posts: 3Questions: 0Answers: 0
edited October 2013 in General
Hi, I googled this for a while but cannot find a clear answer.

I use server side processing but want sorting and filtering happen on client side for data that have been gotten. In another thread allan states that once bServer is set to true all works(paging, sorting, filtering) are handled by server, it seems there is no official way for my requirement.

so I am wondering is there a way that I can hook to pagination? for example, register a callback to pagination button and feed datatables more data each time user clicks 'Next'? however, this also requires ability to tell datatables the total number of records so it can populate pagination button properly.

Can anyone share some ideas? I think my requirement is very common, there should be a way in datatables given it's a very mature project.

thanks

Replies

  • frankzhangfrankzhang Posts: 3Questions: 0Answers: 0
    OK. I got clear answer there is no way for this(http://82.113.152.82/forums/discussion/10614/how-to-enjoy-both-server-side-paging-and-client-side-sortingfiltering-etc./p1)

    Allan mentions that for records < 50000, put all data in client side is efficient. However, I am using angularjs with datatables, and do some post-processing work in fnCreatedRow. In my testing, 3000 records start leading a significant no response time when drawing tables.

    I tried to set bDeferRender = true, then fnCreatedRow is only called for rows on first page.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    No - this is not possible. I don't see how it would be possible, since in order to sort or filter, you need the full data set, which in server-side processing is only available at the server.

    Allan
  • frankzhangfrankzhang Posts: 3Questions: 0Answers: 0
    I went through a few similar topics in forum and fully understood your point that client side search cannot search full data set in server-side processing, it makes none sense to user.

    However, I don't think it's 100% true.

    First, I would call it 'filter' instead of 'search'. It's the first impression datatables gives me when I play with the search input box of example in front page. because it responses so quickly and responses each time I type, I feel it's filtering some data set it already has.

    The instant filtering is appealing, but it's too expensive to server-side processing if the web page/application is open to public which may receive tens of thousands of requests(let's assume the web application has data changing frequently, for example, your virtual instances status in Amazon EC2 cloud). Then, you have to type the entire search/filtering string and type enter to instruct a search/filtering.

    In the later case, I think datatables's default search box may be no use.

    First, for full text search, lots of web sites/applications use full text search engine like solr, elasticsearch, they usually have separate API to query search engine, but for normal data fetching it often goes to databases directly. The difference is, full text search engines are not realtime, they often has a lag of databases change. That's why two sets of API exist(one for search, one for query).

    but in server side processing, search and query use the same request. We can hack this in fnServerData, but it still has some flaw I am talking below.

    for a sophisticated search box, it may have lots of options rather than a single string that can only do fuzzy match if there is no other options along. To add additional search options, I don't know if datatables has a way to enhance default search box with complex DOM. And I also don't know how to pass these additional search options to fnServerData as extra information to send in XHR request.

    Given above, I change default's search box to filter box, this implies user it filters data on the page. For search, I do it all out of datatables.

    Now to continue using sorting/filtering at client side with paging at server side, I follow pipeline example and implement my own sorting/filtering in fnServerData.


    The only problem is I have to tell user that no data found by filtering doesn't mean the data is not available at server side. This is a little weird. But I can't find a better way to have both instant filtering on page while a large data set at server side, and the server may handle large concurrent requests.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > The instant filtering is appealing, but it's too expensive to server-side processing

    Agreed! There is a plug-in to debounce the key input for exactly this reason: http://datatables.net/plug-ins/api#fnSetFilteringDelay

    > The only problem is I have to tell user that no data found by filtering doesn't mean the data is not available at server side. This is a little weird.

    This is my problem with this method. I think it will lead to confused users, hence my reluctance to put it into DataTables core. If it were to be done, join client-side and server-side, I'd use an ajax sourced table (not server-side processing) with fnReloadAjax to load in new data when needed. You wouldn't be able to use the built in paging methods though.

    Long and short - split client-side and server-side processing is just not designed to work with DataTables, and likely won't be, due to the confusion it will cause. As such, other methods such as the key debounce need to be employed.

    Allan
This discussion has been closed.