There are a couple of plug-ins which might help you along this road: fnPageChange and fnDisplayRow ( http://datatables.net/plug-ins/api ). But there isn't a plug-in which will specifically go to page X. However, it would be fairly trivial to modify the code from the previous suggested plug-ins to do what you need.
Replies
There are a couple of plug-ins which might help you along this road: fnPageChange and fnDisplayRow ( http://datatables.net/plug-ins/api ). But there isn't a plug-in which will specifically go to page X. However, it would be fairly trivial to modify the code from the previous suggested plug-ins to do what you need.
Regards,
Allan
I found a solution that works for me in combination with a ServerSide requests.
I thought of sharing this with the community, since I guess there are alot of others who would like to know this as well.
This is the code I run:
[code]
var oTable;
function dCb() {
$("#gotoPage").remove();
$(".dataTables_wrapper .dataTables_paginate:visible").append("/"+Math.ceil(oTable.fnSettings()._iRecordsDisplay / oTable.fnSettings()._iDisplayLength)+"");
$("#gotoPage").die('change').live('change',function(){
var l = $(".dataTables_length select option")[$(".dataTables_length select")[0].selectedIndex].value;
var s = (parseInt($("#gotoPage input").val()) - 1) * oTable.fnSettings()._iDisplayLength;
var sas = oTable.fnSettings().sAjaxSource;
var a = sas.indexOf("&iDisplayStart=")+"&iDisplayStart=".length;
var b = sas.indexOf("&",a);
var url = getTableDataURL();
if (typeof oTable == "object") oTable.fnDestroy();
oTable = $("#oTable").dataTable({
iDisplayStart: s,
bServerSide: true,
sPaginationType: "full_numbers",
sAjaxSource: url,
fnDrawCallback: dCb
});
});
}
oTable = $("#oTable").dataTable({
bServerSide: true,
sPaginationType: "full_numbers",
sAjaxSource: url,
fnDrawCallback: dCb
});
[/code]
Obviously getTableDataURL is a function to gererate my url to the request backend.
[code]
function dGotoPage() {
var oSettings = oTable.fnSettings();
// Configura a exibição do campo
$("#gotoPage").remove();
$(".dataTables_wrapper .dataTables_paginate:visible")
.append("" +
Math.ceil(oSettings._iRecordsDisplay / oSettings._iDisplayLength) +
"");
// Configura o evento
$("#gotoPage").die('change').live('change',function(){
// Set new page
var iPage = (parseInt($("#gotoPage input").val()) - 1) * oSettings._iDisplayLength;
oSettings._iDisplayStart = iPage;
// Redraw table
$(oSettings.oInstance).trigger('page', oSettings);
oSettings.oApi._fnCalculateEnd( oSettings );
oSettings.oApi._fnDraw( oSettings );
});
}
[/code]
One needs just to include the option [code]"fnDrawCallback": dGotoPage[/code] to the Data Tables initialization.