Get all visible rows, even if they are not drawn yet?
Get all visible rows, even if they are not drawn yet?
cmstreet72
Posts: 2Questions: 0Answers: 0
First - DataTables is amazing - not only the product but the support. This is the first time I have ever posted because one can always find the solution in the forum with a little reading. Which, speaking off, I have been doing for 2 days now with no luck.
I am currently returning all of the table initilization information back up to the client form the server in a JSON object.
What I am trying to accomplish is a post back to the server of only the visible records when they are filtered and when I say visible I mean that they can be drawn, not necessarily that they are drawn.
The example I am using has 8K records in the record set. When I check the count of
[code]var rows = oTable.fnGetData()[/code]
it will give me back the 8K rows I expect. Here is where I am getting lost - I have read that the way to get the filtered rows is by doing a
[code]var myFilteredRows = otable._('tr', {"filter":"applied"});[/code]
Well, applying a filter that brings the 8000 rows down to say, 4000 or so, and checking the value of myFilteredRows only shows me 198. When I check the DOM that number is spot on, there are only 198 rows in the DOM so it aint lying! I removed bDeferRender, but same thing, just 198 rows. I have tried multiple suggestions from these fine forums but sill no luck. Here was another good lead that didn't pann out:
[code]
var anNodes = $('#thisTable tbody tr');
var rowData = [];
for (var i = 0; i < anNodes.length; ++i){
rowData.push(otable.fnGetData(anNodes[i]));
}
[/code]
The reason for all of this is that I have record sets of 100K plus records that I need to provide users with the ability to export to Excel. TableTools did not pan out because it chokes hard for me on record sets that large, even in Chrome and FF. So what I built was the ability to post a json string of the records to the server via AJAX and then in Perl the server will build the XLS file and post the file name back up to the client, which then runs a nice js script https://github.com/johnculviner/jquery.fileDownload to perform a very AJAX-ish call back to the server to grab the file.
All working good if I can only get to all the visible records!
Here is the DataTable initilisation:
[code]
var json = JSON.parse('{bDeferRender:"false",
bStateSave:"true",
bSortClasses:"false",
bScrollCollapse:"false",
bProcessing:"true",
bAutoWidth:"false",
aoColumns:[{sTitle:"ID", sWidth:"20px"}, {sTitle:"1", sWidth:"320px"}, {sTitle:"2", sWidth:"380px"}, {sTitle:"3", sWidth:"110px"}, {sTitle:"4", sWidth:"30px"}, {sTitle:"5", sWidth:"20px"}, {sTitle:"6", sWidth:"20px"}, {sTitle:"7", sWidth:"20px"}, {sTitle:"8", sWidth:"20px"}, {sTitle:"9", sWidth:"100px"}, {sTitle:"10", sWidth:"100px"}, {sTitle:"11", sWidth:"60px"}, {sTitle:"12", sWidth:"190px"}, {sTitle:"13", sWidth:"190px"}],
sHeightMatch:"none",
sScrollX:"1580px",
aaData:[["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"], [etc],[etc],[etc]],
sScrollY:"435px",
sDom:"<\"refreshWrapper_allAssetsTbl\"f>rtiS"}');
var oTable = $('#thisTable').dataTable(json);
[/code]
Thanks in advance!!!!
Chris
I am currently returning all of the table initilization information back up to the client form the server in a JSON object.
What I am trying to accomplish is a post back to the server of only the visible records when they are filtered and when I say visible I mean that they can be drawn, not necessarily that they are drawn.
The example I am using has 8K records in the record set. When I check the count of
[code]var rows = oTable.fnGetData()[/code]
it will give me back the 8K rows I expect. Here is where I am getting lost - I have read that the way to get the filtered rows is by doing a
[code]var myFilteredRows = otable._('tr', {"filter":"applied"});[/code]
Well, applying a filter that brings the 8000 rows down to say, 4000 or so, and checking the value of myFilteredRows only shows me 198. When I check the DOM that number is spot on, there are only 198 rows in the DOM so it aint lying! I removed bDeferRender, but same thing, just 198 rows. I have tried multiple suggestions from these fine forums but sill no luck. Here was another good lead that didn't pann out:
[code]
var anNodes = $('#thisTable tbody tr');
var rowData = [];
for (var i = 0; i < anNodes.length; ++i){
rowData.push(otable.fnGetData(anNodes[i]));
}
[/code]
The reason for all of this is that I have record sets of 100K plus records that I need to provide users with the ability to export to Excel. TableTools did not pan out because it chokes hard for me on record sets that large, even in Chrome and FF. So what I built was the ability to post a json string of the records to the server via AJAX and then in Perl the server will build the XLS file and post the file name back up to the client, which then runs a nice js script https://github.com/johnculviner/jquery.fileDownload to perform a very AJAX-ish call back to the server to grab the file.
All working good if I can only get to all the visible records!
Here is the DataTable initilisation:
[code]
var json = JSON.parse('{bDeferRender:"false",
bStateSave:"true",
bSortClasses:"false",
bScrollCollapse:"false",
bProcessing:"true",
bAutoWidth:"false",
aoColumns:[{sTitle:"ID", sWidth:"20px"}, {sTitle:"1", sWidth:"320px"}, {sTitle:"2", sWidth:"380px"}, {sTitle:"3", sWidth:"110px"}, {sTitle:"4", sWidth:"30px"}, {sTitle:"5", sWidth:"20px"}, {sTitle:"6", sWidth:"20px"}, {sTitle:"7", sWidth:"20px"}, {sTitle:"8", sWidth:"20px"}, {sTitle:"9", sWidth:"100px"}, {sTitle:"10", sWidth:"100px"}, {sTitle:"11", sWidth:"60px"}, {sTitle:"12", sWidth:"190px"}, {sTitle:"13", sWidth:"190px"}],
sHeightMatch:"none",
sScrollX:"1580px",
aaData:[["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"], [etc],[etc],[etc]],
sScrollY:"435px",
sDom:"<\"refreshWrapper_allAssetsTbl\"f>rtiS"}');
var oTable = $('#thisTable').dataTable(json);
[/code]
Thanks in advance!!!!
Chris
This discussion has been closed.
Replies
and the other "booleans". That's a string, not a boolean!! That will actually be enabling deferred rendering... I suspect that's your problem there.
I think you might need to use the DataTables 1.10 API if you want to get the data in this manner, using deferred rendering. In 1.10 you would use `table.row( { filter: 'applied' } ).data()` . Or it will probably work in 1.9- if you disable deferred rendering.
Allan
Spot on, just like every other post from you in the forums, thank you Allen! (Both worked a charm BTW)
Allan