fnGetData of visible rows only
fnGetData of visible rows only
Hello everyone. My question might be really simple and already solved, however I couldn't find the solution within the API docs and forum.
Is there an API method to simply retrieve the aoData of the visible rows? (possibly, fnGetVisibleData )
My task is simple: I have a relatively large table (10k rows, 15 cols) and I have some complicated server-side processing of the rows. Therefore I want to retrive data from the currently visible columns and process only them (50 rows). The solution could be as follows:
- fngetNodes is used for the rows that I currently see and then query them in the datatable
- fnFindCellRowIndexes is used based on the retrived tr nodes
- aoData is retrieved based on found row indexes
this could be absolutely fine, but the column with unique values for selection can be hidden by ColVis. and therefore instead of selecting only 50 rows, I can recieve nearly 5000 of them.
So, is there an easier implemented way, or I should make my own indexing variable and embed it into fnRowCallback?
Is there an API method to simply retrieve the aoData of the visible rows? (possibly, fnGetVisibleData )
My task is simple: I have a relatively large table (10k rows, 15 cols) and I have some complicated server-side processing of the rows. Therefore I want to retrive data from the currently visible columns and process only them (50 rows). The solution could be as follows:
- fngetNodes is used for the rows that I currently see and then query them in the datatable
- fnFindCellRowIndexes is used based on the retrived tr nodes
- aoData is retrieved based on found row indexes
this could be absolutely fine, but the column with unique values for selection can be hidden by ColVis. and therefore instead of selecting only 50 rows, I can recieve nearly 5000 of them.
So, is there an easier implemented way, or I should make my own indexing variable and embed it into fnRowCallback?
This discussion has been closed.
Replies
[code]
var oTable = $("#example").dataTable();
var anNodes = $("#example tbody tr");
for (var i = 0; i < anNodes.length; ++i)
{
var rowData = oTable.fnGetData( anNodes[i] );
//some stuff with the obtained data
//...
}
[/code]
Strange, but I can't feed the DOM array from the selector to the fnGetData, cause it causes an error. Yet, an element-wise cycle is fine.
The selector is simple yet powerfull, taking into account only the truly shown tr-s, regarding the filtering, sorting, pagination and column-visibility.
[code]
var data = oTable._('tr', {"filter":"applied"});
[/code]
The $ and _ API methods are really useful for parsing through the nodes and data of the table :-)
Allan
i guess kinda like
[code]
var oTT = TableTools.fnGetInstance( 'example1' );
var data = oTable._('tr', {"filter":"applied"});
for(var i = 0; i< data.length; i++)
{
oTT.fnSelect(data[i]);
}
[/code]
[code]
var oTT = TableTools.fnGetInstance( 'example1' );
oTT.fnSelect( oTable.$('tr', {"filter":"applied"}) );
[/code]
This is possible because TableTools 2.1.1 adds the ability to accept jQuery objects for fnSelect (and fnDeselect).
Allan - trying to make life easier ;-)
I was getting unexpected results when calling oTable.$('tr', {"filter":"applied"}) or oTable._('tr', {"filter":"applied"}). It ended up being that I had bDeferRender set to true, although I double and triple checked that.