Initialization on page init

Initialization on page init

mirko3350mirko3350 Posts: 2Questions: 0Answers: 0
edited December 2013 in DataTables 1.9
Hello,

I am evaluating DataTables. I have been able to get a server side sample going. Now I want to integrate with other pages. Why does datatables need to be initialized on document ready? Could it be initialized on page init? See example below:

[code]

$(document).on('pageinit', '#bookpg', function (e, data) {


var aSelected = [];

var oTable = $('#example').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../Bookings.aspx?depot=100",

"fnServerParams": function (aoData) {
aoData.push({ "name": "vendor", "value": "230" })
},

"bJQueryUI": true,
"sPaginationType": "full_numbers",

"fnRowCallback": function (nRow, aData, iDisplayIndex) {
if (jQuery.inArray(aData.DT_RowId, aSelected) !== -1) {
$(nRow).addClass('row_selected');
}
}

});

});

[/code]

What other options do I have? I am planning on using a jquery/jquery mobile implementation.

thanks

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    > Why does datatables need to be initialized on document ready? Could it be initialized on page init?

    Because if it is initialised before the script might be run before the HTML for the table is ready! You can initialise it any time you want, after the HTML for the table has loaded, if your pageinit event is occurring after that, then go for it! Using document ready is normally a decent fail safe option.

    Allan
This discussion has been closed.