Partial server-side dataset fetched from server but ordering and paging on client side

Partial server-side dataset fetched from server but ordering and paging on client side

GyőzőGyőző Posts: 3Questions: 1Answers: 0

Hi,
I would like to have such a feature or a workaround to let DataTables do the paging and ordering on the client side but whenever a new search term is typed in it fetches the matching result set from the remote server.

The documentation states this is not the case at least right now:

"When using server-side processing, DataTables will make an Ajax request to the server for each draw of the information on the page (i.e. when paging, ordering, searching, etc.)."

We have a REST endpoint for full-text search in place but there is no way to configure for ordering and pagination could be also a bit difficult to add. It would be very handy if I could use the best of both sides.

Or should I switch client-side processing where data source is updated separately on demand?

This question has an accepted answers - jump to answer

Answers

  • GyőzőGyőző Posts: 3Questions: 1Answers: 0

    Another argument would be the considerably high cost of calculating recordsFiltered response field.

    Actually, it means all matching records should be filtered and then most would be neglected on the server-side because of paging. Unfortunately, the full-text index cannot benefit from start and length parameters either.

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

    Hi @Győző ,

    If you've only got a few thousand records, then client side should be fine. It would be worth trying it out seeing if the performance is adequate. This section of the FAQ should also help, it discusses various techniques to improve performance,

    Cheers,

    Colin

  • GyőzőGyőző Posts: 3Questions: 1Answers: 0
    edited August 2019

    So for the record, let me share how I resolve my issue. It might help others.

    Unfortunately, I was totally obsessed with the server-side feature but what I was really looking for is simple ajax. I put a separate search input text box on the page of which event handler manages when the table content should be reloaded:

            var dataTable;
            $(document).ready(function() {
                dataTable = $('#sources').DataTable( {
                    "ajax": {
                        "data": function ( d ) {
                                    return JSON.stringify({"query": $(' #input').val()}); }
                                }
                        });
    
                var typingTimer;
                var doneTypingInterval = 700;
    
                $('#input').on('input', function() {
                    clearTimeout(typingTimer);
                    if ($('#input').val()) {
                        typingTimer = setTimeout(dataTable.ajax.reload, doneTypingInterval);
                    }
                });
    

    This way I have full control over when to fetch new data from backend (ie. when the main search term is changed) but all the rest (paging, ordering, further search in the result maybe) can be done on the client-side.

This discussion has been closed.