JQuery: Accessing Table Rows Of Second And Further Pages Of A Datatable
I am retrieving table row data like this from a HTML table. var descriptions = []; var testRows = $('#tbl').find('tbody').find('tr'); $this = $(this); testRows.each(function () {
Solution 1:
I retrieved the data using fnGetNodes API method.
Correct version (Aug 1 2013)
var descriptions = [];
var _testDesc;
var dt = $("tbl").dataTable();
var dtNodes = dt.fnGetNodes;
var dtNodeCount = dtNodes.length;
for (var i = 0; i < dtNodeCount; i++) {
var description = $(dtNodes[i].cells[2].innerHTML).val();
descriptions.push(description);
}
Wrong version ( Jul 31 2013)
var descriptions = [];
var _testDesc;
var dt = $("tbl").dataTable();
var dtElementCollection = dt.DataTable.settings[0].aoData;
var dtECLength = dtElementCollection.length;
for (var i = 0; i < dtECLength; i++) {
var description = dtElementCollection[i]._aData[2];
_testDesc = $(description).val();
descriptions.push(_testDesc);
}
Solution 2:
If you use an older version of jQuery you can use .live() function. With newer version you should switch to .on(). But you can always make a function from what you wrote:
function example() {
var testRows = $('#tbl').find('tbody').find('tr');
$this = $(this);
testRows.each(function () {
var description = $this.find('[id^="Desc"]').text();
descriptions.push(description);
}
}
and run it every time you operate on your table:
function removeTr() {
$('tr').remove();
example();
}
Post a Comment for "JQuery: Accessing Table Rows Of Second And Further Pages Of A Datatable"