Please mention in the documentation of sUrl that initialization will be delayed

Please mention in the documentation of sUrl that initialization will be delayed

jmeilejmeile Posts: 28Questions: 4Answers: 0
edited January 2014 in Bug reports
Hi

First of all, thanks for this nice code. It is really useful.

Actually it isn't a bug, it is something that you should include in the documentation of sUrl.

It took me a while to figure this out:

I was using the "sUrl" attribute to load my translations, like this:

var oTable = $(data_table_id).dataTable({
"oLanguage": {
"sUrl": "my_file.txt"
},
});

After the whole table initialization a needed to add a floated div after the search filter, so, I appended the div to the dataTables_filter as follows:

$(function()
{
var oTable = $(data_table_id).dataTable({
"oLanguage": {
"sUrl": "my_file.txt"
}
});
$('.dataTables_filter').append($('#action-buttons'));
});

But it didn't worked. Then I realized that if I remove the sUrl attribute, then it worked. I tried different things till I found this message:
https://datatables.net/forums/discussion/15540/sdom-with-additional-div-and-not-empty-olanguage-surl/p1

The reply from Allan describes the problem textually:
"Use fnInitComplete when sUrl is used, since it requires an async Ajax load, so the DOM is not complete until fnInitComplete"

So, I changed the code by this:
$(function()
{
var oTable = $(data_table_id).dataTable({
"oLanguage": {
"sUrl": "my_file.txt"
},
"fnInitComplete": function(oSettings, json) {
$('.dataTables_filter').append($('#action-buttons'));
});
});

Now it works. I think you should mention that initialization will be delayed when using the sUrl attribute and also mention the fnInitComplete attribute as a workarround here:
http://datatables.net/plug-ins/i18n#how_to

For people like me, it isn't clear that an Ajax request will delay the initialization. It will save the time of many people.

Best regards
Josef

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    Hi Josef,

    Good point. I've added it tot he documentation that I'm working on for 1.10 now: https://github.com/DataTables/DataTablesSrc/commit/7eabff1cd3970cf6b19451a545f7801572cf0589 . It will be on the new site when it launches :-)

    Allan
This discussion has been closed.