Reputation: 1391
I am trying to read the contents of a jQuery datatable. I was able to loop through the rows, but I don't know how to get the content.
Here's what I have done so far:
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
var d = this.data();
var item = {
id: // Get first column content
description: //Get second column content
}
});
Upvotes: 0
Views: 36
Reputation: 1206
There are two ways you can use:
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
var nodes = this.nodes().to$();
var item = {
id: nodes.find('td:eq(0)').text(), // Get first column content
description: nodes.find('td:eq(1)').text() // Get second column content
};
});
OR
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
var item = {
id: this.cell(rowIdx,0).data(), // Get first column content
description: this.cell(rowIdx,1).data() // Get second column content
};
});
You can find more details here.
Upvotes: 2
Reputation: 1178
I had used the following code somewhere. Maybe this can work for you.
table.rows().iterator('row', function(context, rowIdx){
var item = {
id: $(this.row(rowIdx).node());
description: $(this.row(rowIdx).node());
}
});
Upvotes: 1