How to copy filtered rows from one table to another
How to copy filtered rows from one table to another
oTable_1 is the source table, populated with data. What I want is to clone this table, filter data and copy filtered rows to a new table oTable_2 which is initialized at this point.
The code could be like this :
[code]
var oTable_1Clone = $.extend({},oTable_1);
oTable_1Clone.fnFilter( $(this).val(), 3 );
var data = new Array();
for(var i=0; i < oTable_1Clone.fnSettings().aiDisplay.length; i++){
data.push(oTable_1Clone.oInit.aaData[oTable_1Clone.fnSettings().aiDisplay[i]]); //this line is wrong
}
oTable_2.fnClearTable();
oTable_2.fnAddData(data);
[/code]
There are 2 problems with this code:
1. When I filter oTable_1Clone, oTable_1 is filtedre too. I want not to change resultset of the table oTable_1.
2. How to get data from aaData in oTable_1Clone : oTable_1Clone.oInit.aaData is not a legal statement.
Any idea how to fix it ?
Regards miroko
The code could be like this :
[code]
var oTable_1Clone = $.extend({},oTable_1);
oTable_1Clone.fnFilter( $(this).val(), 3 );
var data = new Array();
for(var i=0; i < oTable_1Clone.fnSettings().aiDisplay.length; i++){
data.push(oTable_1Clone.oInit.aaData[oTable_1Clone.fnSettings().aiDisplay[i]]); //this line is wrong
}
oTable_2.fnClearTable();
oTable_2.fnAddData(data);
[/code]
There are 2 problems with this code:
1. When I filter oTable_1Clone, oTable_1 is filtedre too. I want not to change resultset of the table oTable_1.
2. How to get data from aaData in oTable_1Clone : oTable_1Clone.oInit.aaData is not a legal statement.
Any idea how to fix it ?
Regards miroko
This discussion has been closed.
Replies
[code]
var data = oTable_1._('tr', {filter:'applied'});
oTable_2.fnClearTable();
oTable_2.fnAddData( data );
[/code]
This uses the underscore function to get the data for the original original table, with the filtering applied, and then adds it to the second table.
Allan