Keep selected rows when I go to another page

Keep selected rows when I go to another page

jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
edited July 2013 in TableTools
Hi Allan
I want to select mutiple rows that are in different pages of my datatable. I use multiselect TableTools. I select some rows in the page I see in this moment (page A), then I go to another page (page B) and when I return to page A all the rows I selected in this page are deselected.
I need to select multiple rows in different pages in order to generate a unique csv file.

Is possible to do this ? How ?

Thanks

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    This should be working already, unless you are you using server-side processing possibly? TableTools keeps track of selected rows based on their DOM node, but since server-side processing requires that each page has a new DOM nodes for the rows displayed, this method simply doesn't work :-(.

    What I'll do is look at introducing a new mode into TableTools which can use the row ID of rows to retain select - a bit like this method: http://datatables.net/release-datatables/examples/server_side/select_rows.html . That should be in TableTools 3, although that won't be until after DataTables 1.10 is released.

    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    Yes, server-side.
    I´ll wait Table Tools 3 and DataTables 1.10. (without drinking, eating, ... jaja)

    Thanks Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    I try to implement this http://datatables.net/release-datatables/examples/server_side/select_rows.html but it doesn,t works in my page. I think because I use TableTools + Datatables and in this method only use Datatables.
  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Yes - the method shown in the DataTables explain isn't compatible directly with TableTools. You could use the TableTools API (fnSelect etc) rather than adding a class as is done in the example though - that would work.

    Allan
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    I follow your instructions. I achieved maintain selected rows when I move through the pages of my datatables with this

    oTable = $('#example').dataTable( {
    ..... ,
    "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
    if ( jQuery.inArray(aData.DT_RowId, aSelected) !== -1 ) {
    // Si la fila esta en el array de filas seleccionadas, la muestro como seleccionada
    oTT.fnSelect( $('#example tbody tr')[iDisplayIndex] ) ;
    }
    }
    } );

    ..................

    /* Click event handler */
    $(document).on( 'click', '#example tbody tr', function () {
    var id = this.id;
    var index = jQuery.inArray(id, aSelected);
    var rowIndex = $('#example tbody tr').index(this);

    if ( index === -1 ) {
    aSelected.push( id );
    oTT.fnSelect( $('#example tbody tr')[rowIndex] ) ;
    } else {
    aSelected.splice( index, 1 );
    oTT.fnDeselect( $('#example tbody tr')[rowIndex] ) ;
    }

    } );

    but when I export to excel, csv or pdf with "bSelectedOnly": true, only export selected rows in the page I see in this moment. How can I fix this ? Is possible ?
    Also I would need that "Select All" and "Deselect All" TableTools buttons, fill or empty aSelected array. Is this possible ? How ?
  • jgcaudetjgcaudet Posts: 82Questions: 7Answers: 0
    Thanks
This discussion has been closed.