Obtain number page
Obtain number page
gerenne
Posts: 30Questions: 0Answers: 0
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.
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.
This discussion has been closed.
Replies
Can you link to a test case so I can see exactly what is happening please?
Allan
This is my link:
http://live.datatables.net/ovutek/edit#javascript,html,live
Thanks!!
> ReferenceError: Can't find variable: iId
Allan
http://live.datatables.net/ovutek/3/edit
Thanks.
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
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.