How to select and copy sorted rows?

How to select and copy sorted rows?

raycistraycist Posts: 7Questions: 0Answers: 0
edited October 2009 in General
Hi Allan,

First of all, I just want to say that your work is amazing.
I am a newbie in js and JQuery, but your plugin is so easy to use, that a newbie like me can play around with it in just a few days.

My question is regarding selecting sorted rows.
I've used your example on http://datatables.net/examples/api/select_row.html

I've also implemented a "select all function" which basically marks every row with "row_selected" class. And a copy button, which copies every row with the "row_selected" class.
However the trouble comes when I sort the table, select all, and then perform the copy. What ended up getting copied is the table in its original unsorted order.

My copy function uses this function to grab all selected node.

[code]
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();

for ( var i=0 ; i

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Hi Ray,

    The reason it is being copied unsorted is that you are using fnGetNodes() which doesn't return the sorted data. What to do instead is to make use of aiDisplayData, which is an array of integers, pointing at indexes in aoData (after sorting and filtering). So:

    [code]
    function fnGetSelected( oTableLocal )
    {
    var aReturn = new Array();
    var oSettings = oTableLocal.fnSettings();
    var aTrs = oTableLocal.fnGetNodes();

    for ( var i=0, iLen=oSettings.aiDisplay.length ; i
This discussion has been closed.