Obtain number page

Obtain number page

gerennegerenne Posts: 30Questions: 0Answers: 0
edited January 2013 in DataTables 1.9
Hi all,

I have a table, in this table, I can select a row, and then I do one action, the table is loaded again, and the row that I had selected, It must appear selected again.
It work correctly, but my problem is the number of page, for exemple...If the row selected is in the page one, when I reload the table, the row is selected, but the number page is other, I make a function that select the row, and the page, but the problem is that when the table is reloading the order of records is different to when the table is loaded.

This is my function:

$('#table tbody tr').each( function(i) {

var aData=$('td', this);
var iIdRow=$(aData[1]).text();
if (i%10==0){
nMod=i;
}
if (iId==iIdRow){ //iId is the identificator of the row

$('#table tbody tr:eq('+i+')').addClass('row_selected'); //select the row
nPageIni=nMod; //store the ini page

}

} );

Then:

oTable =$('#table ').dataTable( {
"bRetrieve": true,
"bDestroy": true,
"iDisplayStart": nPageIni,
"fnDrawCallback":
function() {
clickRowHandler();
},
"aoColumnDefs": [
{"bVisible": false,
"aTargets": [ 9 ]
}],
"aaSorting": [ [9,'asc']],
"aoColumns": [
null,
null,
null,
null,
null,
null,
null,
{"sType": "date-euro"},
null,
null]

} );

Please, somebody could you help me?

Thanks in advance.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Ordering in DataTables is entirely determined by the sorting applied to the table. If you have sorting enabled, then it will be applied to the table and your data sorted.

    Can you link to a test case so I can see exactly what is happening please?

    Allan
  • gerennegerenne Posts: 30Questions: 0Answers: 0
    Hi Allan,

    This is my link:

    http://live.datatables.net/ovutek/edit#javascript,html,live

    Thanks!!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    There is a script error on the page stopping it from doing anything:

    > ReferenceError: Can't find variable: iId

    Allan
  • gerennegerenne Posts: 30Questions: 0Answers: 0
    The iId, is the id of row (column1), that has been selected, I've deleted this function for that don't launch a error.

    http://live.datatables.net/ovutek/3/edit

    Thanks.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Now it reports an error about the `nPageIni` variable :-). If I set that to `10` then I get an error about the number of columns from aoColumns (10) not matching the number in the HTML (9).

    Fixing that I get an error about the use of column index 9 (i.e. column 10) since there are only 9 columns. That is in aoColumnDefs and aaSorting.

    Fixing that I get and error about clickRowHandler not existing.

    Fixing that it appears to work fine for me (the 10 for iDisplayStart is ignored since there are only 10 records so starting at 10 isn't going to work): http://live.datatables.net/ovutek/4/edit

    So I'm still not quite sure what the problem is I'm afraid?

    Allan
  • gerennegerenne Posts: 30Questions: 0Answers: 0
    Hi Allan!

    The problem is that is difficult to do a test case, because is a dinamic process, I have the clickrowhandle, and I have more of 10 rows, but these are loaded with struts2 iterator... I try to explain, because my english is a little bad :):

    1- Load rows with struts2 iterator . (OK)
    2- Load dataTables with: (OK)

    [code]
    oTable =$('#ticketsTable').dataTable( {
    "bRetrieve": true,
    "bDestroy": true,
    "fnDrawCallback":
    function() {
    clickRowHandler();
    },
    "aoColumnDefs": [
    {"bVisible": false,
    "aTargets": [ 9 ]
    }],
    "aaSorting": [ [9,'asc']],
    "aoColumns": [
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    {"sType": "date-euro"},
    null,
    null]

    } );
    [/code]
    (Load about 30 records).

    3- Click in the table (for example second page):
    [code]
    $('#ticketsTable tbody tr').bind('click', function ()
    {
    if ( $(this).hasClass('row_selected') ) {
    $(this).removeClass('row_selected');
    }
    else {
    oTable.$('tr.row_selected').removeClass('row_selected');
    $(this).addClass('row_selected');
    }
    var aData = oTable.fnGetData( this );
    iId = aData[1]; /

    });
    [/code] in the iId save the id of the column one.(OK)

    4- I do a action in this record and update the database, I want reload the table and that the table appear en the page where is the row.

    I find in the table my row, and the page:
    [code]
    $('#ticketsTable tbody tr').each( function(i) {

    var aData=$('td', this);
    var iIdRow=$(aData[1]).text();
    if (i%10==0){
    nMod=i;
    }
    if (iId==iIdRow){
    $('#ticketsTable tbody tr:eq('+i+')').addClass('row_selected');
    nPageIni=nMod; //npage ini is not correct
    idMaxRow=iIdRow;
    }

    } );
    [/code]
    Load the table:
    [code]
    oTable =$('#ticketsTable').dataTable( {
    "bRetrieve": true,
    "bDestroy": true,
    "iDisplayStart": nPageIni,
    "fnDrawCallback":
    function() {
    clickRowHandler();
    },
    "aoColumnDefs": [
    {"bVisible": false,
    "aTargets": [ 9 ]
    }],
    "aaSorting": [ [9,'asc']],
    "aoColumns": [
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    {"sType": "date-euro"},
    null,
    null]

    } );

    Result: The row is selected correctly, but the page is other.

    [/code]

    Load the table , the row is selected ok, but appear in other page.
  • gerennegerenne Posts: 30Questions: 0Answers: 0
    By the way, the column 9 exist, but is invisible, this is a number column and when I do query, I order by this column and in the table too.
This discussion has been closed.