How to copy filtered rows from one table to another

How to copy filtered rows from one table to another

mirokomiroko Posts: 8Questions: 0Answers: 0
edited July 2012 in General
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

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Try this:

    [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
This discussion has been closed.