Reputation: 1551
We need to change text dynamically "zeroRecords" in Language.
I have tried in fnDrawCallback
:
userTable.fnSettings().language= {"zeroRecords":"Now empty"};
Edit :
I need to display message like " something {variable} something {variable 2}, where variable value are picked from hidden input or pass through response.
Upvotes: 0
Views: 2307
Reputation: 85538
At the time this is written, referring to latest version 1.10.12, you still cannot change none plugin language strings without reinitialising the dataTable. But since you are referring to zeroRecords
you can change the content dynamically. dataTables inserts a special <tr>
containing only one <td>
:
<td colspan="#colcount" class="dataTables_empty">...</td>
So you can easily overwrite the content in a draw.dt
event handler :
var someVar = 'this is a dynamic variable';
table.on('draw.dt', function() {
var $empty = $('#example').find('.dataTables_empty');
if ($empty) $empty.html('Now empty : ' + someVar)
})
see http://jsfiddle.net/1273zafx/ and click clear.
Upvotes: 2
Reputation: 2645
Do you want this:
This is a example.
var langFile = "../Scripts/jquery.dataTables.en-US.txt";
var oTable = $('.gvDataTable').dataTable({
"oLanguage": {
"sUrl": langFile
},
"sScrollX": "99%",
"fnDrawCallback": function (oSettings) {/*Re-Create serial no for the table*/
/* Need to redo the counters if filtered or sorted */
if (oSettings.bSorted || oSettings.bFiltered) {
for (var i = 0, iLen = oSettings.aiDisplay.length; i < iLen; i++) {
$('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[i]].nTr).html(i + 1);
}
}
/*Put checkboxlist after filter to show/hide columns after excel export*/
$('.cbShowOrHideGvCols').appendTo('div.DTTT_container');
},
});
Refer:http://asp-tech.blogspot.com/2013/11/jquery-datatables-change-language.html
Upvotes: 0