Paul Paul - 2 months ago 37
jQuery Question

How to get current page number of Bootstrap DataTable using jQuery

I want to get the current page number of Bootstrap dataTable. So after I edit or delete a data it will return to the page where it is being located.

function deleteID(searchs){
$('#tblAccount').dataTable().fnDestroy();
$('#tblAccount').dataTable({
"sDom": 'rtp',
"bServerSide": true,
"sAjaxSource": "ajax-accounts?type=Delete&search="+searchs,
"lengthMenu": [[ 8, 5], [ 10, 25,50,"ALL"]],
"autoWidth" : false,
"aoColumnDefs": [
{ "aTargets": [ 0 ], "bSortable": false},
{ "aTargets": [ 1 ], "bSortable": false},
{ "aTargets": [ 2 ], "bSortable": false},
{ "aTargets": [ 3 ], "bSortable": false}

],

});
}

Answer

You can use page.info() for getting all page related information.

Usage :

var table = $('#tblAccount').dataTable({
    "sDom": 'rtp',
    "bServerSide": true,
    "sAjaxSource": "ajax-accounts?type=Delete&search="+searchs,
    "lengthMenu": [[ 8, 5], [ 10, 25,50,"ALL"]],
    "autoWidth" : false,
    "aoColumnDefs": [
        { "aTargets": [ 0 ], "bSortable": false},
        { "aTargets": [ 1 ], "bSortable": false},
        { "aTargets": [ 2 ], "bSortable": false},
        { "aTargets": [ 3 ], "bSortable": false}

       ],

    });
var info = table.page.info();
console.log(info.page);

I hope this is what you want. Please follow the linked document for more details.