fnAddTr() Plugin - nTr.getElementsByTagName is not a function
fnAddTr() Plugin - nTr.getElementsByTagName is not a function
I would like to use the fnAddTr() Plugin
I receive "nTr.getElementsByTagName is not a function" Javascript error.
[code]
$('#rTable').dataTable().fnClearTable();
var oTable = $('#rTable').dataTable();
oTable.fnAddTr("TEST");
[/code]
Any ideas?
I receive "nTr.getElementsByTagName is not a function" Javascript error.
[code]
$('#rTable').dataTable().fnClearTable();
var oTable = $('#rTable').dataTable();
oTable.fnAddTr("TEST");
[/code]
Any ideas?
This discussion has been closed.
Replies
[code]
$('#rTable').dataTable().fnClearTable();
var oTable = $('#rTable').dataTable();
var row= "TEST";
oTable.fnAddTr($(row)[0]);
[/code]
Allan
It works in my development mode on rails, but fails on production; the only other difference I can see is that the js files are all joined together into one cache file.
Are you able to give me a link to the production system?
Allan
However, I also can't explain by fnAddTr would be called when parsed. There must be a call to it somewhere, but I can't think of what it would be from your description. Might be worth grepping the code just to make sure you know where all calls to it are.
Allan
See below:
[code]
$.fn.dataTableExt.oApi.fnAddTr = function (oSettings, oData, bRedraw) {
if (typeof bRedraw == 'undefined') {
bRedraw = true;
}
var nTrs = oData.getElementsByTagName('tr');
for (var y = 0; y < nTrs.length; y++) {
//var nTds = nTr.getElementsByTagName('td');
var nTds = nTrs[y].getElementsByTagName('td');
if (nTds.length != oSettings.aoColumns.length) {
alert('Warning: not adding new TR - columns and TD elements must match');
return;
}
var aData = [];
for (var i = 0; i < nTds.length; i++) {
aData.push(nTds[i].innerHTML);
}
/* Add the data and then replace DataTable's generated TR with ours */
var iIndex = this.oApi._fnAddData(oSettings, aData);
oData._DT_RowIndex = iIndex;
//oSettings.aoData[iIndex].oData = nTrs[y];
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
if (bRedraw) {
this.oApi._fnReDraw(oSettings);
}
}
}
[/code]
I simply call an MVC View that returns an entire table as follows:
[code]
var onSuccess = function (newRows) {
oTable.fnClearTable();
if (newRows.length > 0) {
oTable.fnAddTr($(newRows)[0]);
}
$("button").button();
};
$.ajax({
url: "/Home/GetTableWithRows",
data: data,
success: onSuccess,
dataType: "html"
});
[/code]
Let me know if this helps you.
Allan