Salesforce - Datatables calling Controller to fill the records

Salesforce - Datatables calling Controller to fill the records

ArunProjectsArunProjects Posts: 6Questions: 1Answers: 0

I am able to load the Datatables using my controller but the problem is that it is getting called again If I sort , search or do anything on the datatable , this makes it call the fnServerData which is reloading the table . I want to skip the loading till the last page is reached . I saw lot of code and maybe I can use oSettings but which property should I check for skipping the call .

Any code example will be useful

<

script type="text/javascript">

var j$ = jQuery.noConflict();

//var fields = ['Name', 'Birthdate', 'Phone', 'Email'];

var aoColumns = [];
for (var i = 0; i < fields.length; i++) {
aoColumns.push({'mData': fields[i]});
}

j$(document).ready(function() {
j$('#myList').dataTable({
'aoColumns': aoColumns,
stateSave: true ,
"jQueryUI": false ,

    "scrollCollapse": false,
    "dom": 'Zlfrtip' ,
    "colResize": {
        "rtl": false,
        "tableWidthFixed": false
    } ,
     'bProcessing': true,
    'bServerSide': true,
    'sAjaxSource': 'fakeUrl',
    'fnServerData': function(sSource, aoData, fnCallback ,oSettings) {
        console.log(JSON.stringify(aoData));
        // Call the @RemoteAction JavaScript function
        DataController.contacts(aoData, function(result, event) {
         console.log('Reached Here Called Contacts');
            if (event.type != 'exception') {
               console.log(JSON.stringify(result));


                for (var i = 0; i < result.aaData.length; i++) {
                    var r = result.aaData[i];
                    console.log('print results ' + result.aaData[i]);
                    for (var j = 0; j < fields.length; j++) {
                        var field = fields[j];
                        console.log('print r[field] ' + r[field]);
                        if (r[field] == undefined) {
                            // DataTables pops a dialog for undefined values
                            r[field] = null;
                        } else if (field == 'Birthdate') {
                            // Dates transmitted as longs
                            var d = new Date(r[field]);
                            r[field] = ''
                                    + (d.getMonth() + 1)
                                    + '/'
                                    + d.getDate()
                                    + '/'
                                    + d.getFullYear()
                                    ;
                        }
                    }
                }
                // Call back into the DataTable function
           //     console.log('Returned to Function Result = ' + JSON.stringify(result));
                fnCallback(result);
            } else {
                alert(event.message + 'Reached  Error');
            }
        });
    }
});

});

This discussion has been closed.