Occurence of Word Stats from Filtered
Occurence of Word Stats from Filtered
hackerseraph
Posts: 5Questions: 0Answers: 0
Team,
Is there a way to pull stats for items that are filtered. Take for instance Filter for word giraffe. In my stats div I can have Legs Occurs: 5 Times because there may be 5 different cells that have the word "legs" showing.
Is there a way to pull stats for items that are filtered. Take for instance Filter for word giraffe. In my stats div I can have Legs Occurs: 5 Times because there may be 5 different cells that have the word "legs" showing.
This discussion has been closed.
Replies
Allan
[code]
$(document).ready(function() {
var oTable = $('#tablesorter').dataTable();
// Get the data from the filtered table rows
var ptwo = oTable._('tr', {"filter": "applied"});
var ptwofind = ptwo.match(/findthisword/g);
var ptwocount = ptwofind.length;
alert( "Total is"+ptwocount);
} );
[/code]
on a table initialised with
[code]
$(document).ready(function() {
$('#tablesorter').dataTable(
{
"iDisplayLength": 150,
"aaSorting": [[2,'asc'], [0,'asc']],
"aLengthMenu": [[150, 25, 50, -1], [150, 25, 50, "All"]],
"sDom": 'T<"top"if>rtl<"bottom"p><"clear">',
"oLanguage": {
"oPaginate": {
"sNext": "Next page",
"sPrevious": "Previous page | "
}},
"bJQueryUI": false,
"aoColumnDefs": [{ "bVisible": false, "aTargets": [19, 18, 17, 16, 15, 14, 13, 12,] }],
});
});
[/code]
to find a specific word, the following console errors
[code]
Uncaught TypeError: Object [object Array] has no method 'match'
[/code]
Am I taking the long way around just to have it output how many times a word shows up in filtered results?
[code]
$(document).ready(function() {
var oTable = $('#tablesorter').dataTable();
// Get the data from the filtered table rows
var ptwo = oTable._('tr', {"filter": "applied"});
var ptwofind = ptwo.toString().match(/P2/gi);
var ptwocount = ptwofind.length;
alert( "Total is"+ptwocount);
} );
[/code]
The above can be modified, to have javascript output the amount to a div on the fly :) enjoy
[code]
$(document).ready(function() {
var oTable = $('#tablesorter').dataTable();
// Get the data from the filtered table rows
var ptwo = oTable._('tr', {"filter": "applied"});
var ptwofind = ptwo.toString().match(/P2/gi);
var ptwocount = ptwofind.length;
document.getElementById('stats').innerHTML="P2 Total is:"+ptwocount;
} );
[/code]
[code]
// Get the XXXXX from filtered results
var oTable = $('#yourTable').dataTable();
var xxxfind = tableFilter.toString().match(/xxx/gi);
if ( xxxfind != undefined ){
var xxxcount = xxxfind.length;
document.getElementById('statsDiv').innerHTML+="xxx total is: "+xxxcount+"
";
}
else {
document.getElementById('statsDiv').innerHTML+="xxx total is: 0
";
}
});
});
[/code]
Use the `filter` event - http://datatables.net/docs/DataTables/1.9.4/#filter . (note in DataTables 1.10 this is called `search` and must be used with a `.dt` namespace when attaching a jQuery event listener!).
Allan