Is there a way to load server-side JSON into a table using SetTimeOut?

Is there a way to load server-side JSON into a table using SetTimeOut?

saustinsaustin Posts: 7Questions: 2Answers: 0

I'm trying to load 30k rows into my data table using server side processing. Is there a way to intercept the data from the server and load it into the table manually using SetTimeOut? IE times out and give the 'long running script' error and doesn't load my data.

I'm using ASP.Net for the server code with Nhibernate for the ORM for our database.

If I could get the Scroller plugin to work and send paginated data back, it might be an alternative solution.

However, we incur a lot of overhead each time we call the server to fetch a new set of data (~18sec on the server). At this time it is not feasible to paginate the data we give to the client using a query in NHibernate, so each time we have to get the entire dataset before it gets filtered and delivered to the client via an ajax call.

Answers

  • saustinsaustin Posts: 7Questions: 2Answers: 0
    edited September 2014

    I've tried using

    var DEFAULT_CHUNK_SIZE = 200;
    
    function feedDataToDataTableInChunks(data, oSettings) {
        var chunk = data.splice(0, DEFAULT_CHUNK_SIZE);
        oSettings.oInstance.fnAddData(chunk, false);
        if (data.length !== 0) {
            setTimeout(function () {
                feedDataToDataTableInChunks(data, oSettings);
            });
        } else {
            oSettings.oApi._fnInitComplete(oSettings, oSettings.jqXHR);
            oSettings.oInstance.fnDraw();
        }
    }
    
    "sAjaxSource": ajaxUrl,
    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
        oSettings.jqXHR = $.getJSON(sSource, aoData)
            .done(function (result) {
                var recipientArray = new Array();
                $.each(result, function (key, value) {
                    if (Object.prototype.toString.call(value) === '[object Array]') {
                        $.each(value, function (newKey, newValue) {
                            recipientArray.push(newValue);
                        });
                    }
                });
                feedDataToDataTableInChunks(recipientArray, oSettings);
            });
    }
    

    For some reason it calls the server function over and over and over. I'm getting very frustrated.

    Without the ability to control how the table is loaded once the data comes back from the server I get script time out errors in IE. I'm having issues when returning 30k items from the server.

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

    I'm having issues when returning 30k items from the server.

    That's not really a lot of data, unless each record is exceptionally large. DataTables' server-side should be perfectly happy with it. I would be looking at ASP and Nhibernate - neither of which I know anything about :-) - or my database design.

  • chris_nchris_n Posts: 53Questions: 3Answers: 0

    However, we incur a lot of overhead each time we call the server to fetch a new set of data (~18sec on the server).

    Wow! That sounds like a DB problem. I can fetch nearly 100K records in well under a second. I think I'd be looking elsewhere than DT.

  • saustinsaustin Posts: 7Questions: 2Answers: 0

    NHibernate seems to be the problem. To troubleshoot I moved the repository code out of the Json controller action that Datatables calls. The timing changed from ~18sec to ~700ms. I am going to have to make our repository performant .

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    isn't NHibernate an ORM? Loading all 100K records into an object model might be fairly slow. You could look at using server-side processing or just dump the data straight out without using an ORM.

    Allan

  • saustinsaustin Posts: 7Questions: 2Answers: 0
    edited September 2014

    I currently am using serverside processing. I'm working on getting Scroller working. For some reason it doesn't want to get the next 'page' when I scroll to the end of the first result set.

    EDIT:

    Looks like I wasn't returning the correct value for iTotalDisplayRecords.

This discussion has been closed.