Get ALL filtered rows across ALL pages
Get ALL filtered rows across ALL pages
Smallzoo
Posts: 7Questions: 0Answers: 0
I cant seem to solve this simple problem. I know I can use the following to loop through all the rows :-
[code]
var rows = $("#myTable").dataTable().fnGetNodes();
for (var i = 0; i < rows.length; i++) {
var v1 = $(rows[i]).find("td:eq(1)").text();
}
[/code]
I also know you can get the filtered rows by :-
[code]
var rows = $("#myTable").dataTable()._('tr', {"filter":"applied"});
[/code]
BUT how do I combine BOTH. ie lopp thorugh all the rows in a paginated tabled but ONLY the filtered ones
Thanks
[code]
var rows = $("#myTable").dataTable().fnGetNodes();
for (var i = 0; i < rows.length; i++) {
var v1 = $(rows[i]).find("td:eq(1)").text();
}
[/code]
I also know you can get the filtered rows by :-
[code]
var rows = $("#myTable").dataTable()._('tr', {"filter":"applied"});
[/code]
BUT how do I combine BOTH. ie lopp thorugh all the rows in a paginated tabled but ONLY the filtered ones
Thanks
This discussion has been closed.
Replies
Allan
var rows = $("#myTable").dataTable().$('tr', {"filter":"applied"});
[/code]
Allan
First I create a simple table
[code]
$('#cfulltable').dataTable({
"aoColumnDefs": [
{ "asSorting": [ "desc", "asc", "asc" ], "aTargets": [ 1,2,3,4,5,6, ] }
],
"bProcessing": true,
"sPaginate": true,
"iDisplayLength": 20
});
[/code]
on data ( simplified of course...)
[code]
ID
Name
5684
NAME
[/code]
I then filter with a textbox for name which works well
( textbox is say called "fname" and you click a button to filter which runs the following script..)
[code]
function filter(){
var oTable = $('#cfulltable').dataTable();
oTable.fnDraw();
}
[/code]
This then runs the filtering routine automatically. I then check to see if the name matches. I'm sure the way I am matching the name is too convoluted but it works..
[code]
$.fn.dataTableExt.afnFiltering.push(
function (oSettings, aData, iDataIndex) {
var rt1 = false;
var isName = document.getElementById('fname').value;
var iaName = aData[1];
if (isName == '') { rt1 = true; }
else {
var inamelen = iaName.length;
var inamesub = iaName.substring(iaName.indexOf('') + 1;
var nme = inamesub.indexOf('');
var iname = inamesub.substring(nms, nme);
if (iname.substring(0, inamelen).toLowerCase().indexOf(isName) >= 0)
{ rt1 = true; }
else
{ rt1 = false; }
}
);
[/code]
This filtering works over all pages great...but as I said when I then try and read the records I can only seem to either loop through the whole table
[code]
var rows = $("#cfulltable").dataTable().fnGetNodes();
for (var i = 0; i < rows.length; i++) {
var v1 = $(rows[i]).find("td:eq(1)").text();
}
[/code]
or the filtered ones
[code]
var rows = $("#cfulltable").dataTable()._('tr', {"filter":"applied"});
for (var i = 0; i < rows.length; i++) {
var v1 = $(rows[i]).find("td:eq(1)").text();
}
[/code]
BUT NOT BOTH ?
Does this make sense ?
Thanks
Try:
[code]
$("#cfulltable").dataTable().$('tr', {"filter":"applied"}).each( function () {
var v1 = $(this).find("td:eq(1)").text();
...
} );
[/code]
I presume there is meant to be more code after the find row.
Allan