Stop server-side requests when got full data set.

Stop server-side requests when got full data set.

msaragnolimsaragnoli Posts: 9Questions: 0Answers: 1
edited March 2013 in General
Hello guys, I'm new here and using dataTables.

I've just set the server-side processing with pipelining in my application (MVC 4) and it is working as expected!!

But........, always has a but!! :)

In my situation, I've set the variable "iPipe" (from pipelining logic) to 20 so, it's returning from server 200 rows each time, it's perfect, because sometimes there is more than 3000 thousand rows on DataBase Table, but other times, I got only 100 rows in DataBase, so to those cases I would like to implement or know if exists a way to stop the server side for SEARCH and SORT, because will not make sense to keep doing that server side search or sort, once that I got all the rows from my DataBase loaded in client-side.

Basically I thought the dataTables could check the _iRecordsTotal and check the oSettings.aoData (variable where keep the loaded rows) and verify if the total data is equal to the total records, if yes, stop the server-side requests. Is there a way? Someone could point me to the right way?


Guys, really sorry about my English, I tried to be clearly!!!

Thanks,
and congratulations for the dataTables Team, It's a great tool!

Replies

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    But you never will have the full data set with server-side processing. If you user changes the sort for example then the cache needs to be cleared and new data got. You cannot change between server-side processing and client-side processing midway. Also if you are work with 3 million rows, then it is unlikely your users would ever load all rows is it not? For 3000 rows however, just use client-side processing.

    Allan
  • msaragnolimsaragnoli Posts: 9Questions: 0Answers: 1
    Thanks for answer allan,

    I'm already using client-side with the 3 thousand rows, but the users are complaining about the load time, so I decided to use the server-side.

    I made a little change on pipelining code, it's almost what I need, excepted on the page load, where it doesn't show the pagination, It brings all the data in the same page, but, as soon as I filter or sort some column, the pagination appears and everything works as client-side.

    Bellow the code changed.
    [code]
    $.getJSON(sSource, aoData, function (json) {
    /* Callback processing */
    oCache.lastJson = jQuery.extend(true, {}, json);
    [quote]
    //mine implementation
    if (json.iTotalRecords === oCache.lastJson.aaData.length) {
    fnCallback(json);
    info.oFeatures.bServerSide = false;
    }[/quote]
    else {
    //Normal usage
    if (oCache.iCacheLower !== oCache.iDisplayStart) {
    json.aaData.splice(0, oCache.iDisplayStart - oCache.iCacheLower);
    }
    json.aaData.splice(oCache.iDisplayLength, json.aaData.length);
    fnCallback(json);
    }

    }); [/code]

    I was wondering something like this.
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Did you enable deferred rendering when you had client-side processing?

    Also - no. As I say, you cannot switch between client-side and server-side processing. Simply setting the bServerSide flag would not be enough (since the old data is not retained). Indeed in general the settings object should never be altered outside of the core.

    Allan
  • msaragnolimsaragnoli Posts: 9Questions: 0Answers: 1
    Yes i tried for the client-side, is it like that?

    [code]
    pesquisa: function (opcoes) {
    $('#' + opcoes.tableId).addClass("grid_pesquisa");
    $('#' + opcoes.tableId).dataTable({
    "bRetrieve": true,
    "bFilter": false,
    "bDeferRender": true,
    "bLengthChange": false,
    "oLanguage": TraducaoGrid,
    "fnDrawCallback": function () {
    $('#' + opcoes.tableId + ' td').bind('mouseenter', function () { $(this).parent().children().each(function () { $(this).addClass('highlight'); }); });
    $('#' + opcoes.tableId + ' td').bind('mouseleave', function () { $(this).parent().children().each(function () { $(this).removeClass('highlight'); }); });
    }
    });

    }[/code]
This discussion has been closed.