Reputation: 77
I am developing a web application that having a datatable plugin.
I am fetching table rows as Datatable Dynamically with ajax.
Each row contains an edit button and delete button.
For Ex: when I switch to page 3 and click the edit button its gone to the edit page.
After submitting the page system will force to redirect to table list page.
On that time datatable showing from the first page in datatble. I want to show the 3 rd page.
How can I change this from page 3 ?
var oTable = $('.dataTable').DataTable( {
"processing": true,
"serverSide": true,
"bLengthChange": false,
'iDisplayLength':5,
"bSort": false,// disable sort options
"aoColumnDefs": [{ "bSortable": false, "aTargets": [ "_all" ],"sClass": "hide_me", "aTargets": [ 6,7,8 ] }],
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$('td:eq(5)', nRow).addClass( "text-right" );
},
"ajax":{
url :"get-model-datatble.php", // json datasource
async:false,
dataType:'json',
type: "post", // method , by default get
}
});
Thanks
Upvotes: 1
Views: 180
Reputation: 872
Try this script
var oTable = $('.dataTable').DataTable();
oTable.fnPageChange(2,true);
Or
https://datatables.net/reference/option/displayStart
Add the displayStart option
var oTable = $('.dataTable').DataTable( {
"processing": true,
"serverSide": true,
"bLengthChange": false,
'iDisplayLength':5,
"displayStart": 20,
"bSort": false,// disable sort options
"aoColumnDefs": [{ "bSortable": false, "aTargets": [ "_all" ],"sClass": "hide_me", "aTargets": [ 6,7,8 ] }],
"fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$('td:eq(5)', nRow).addClass( "text-right" );
},
"ajax":{
url :"get-model-datatble.php", // json datasource
async:false,
dataType:'json',
type: "post", // method , by default get
}
});
Upvotes: 1