Pagination and bInfo not working while using AJAX calls

Pagination and bInfo not working while using AJAX calls

SriramTSriramT Posts: 2Questions: 0Answers: 0
edited January 2014 in DataTables 1.9
Hi All,
I am a novice to the data tables. In my company I have a requirement for pagination on the data tables from the server side and apart from displaying the results I need to display the check box and the link to the YYYNbr.

The approach I am following is

I am calling the Ajax call first and trying to append the results to the data table. For each click on the data table (like sorting, default page size, page numbers ), the data base is queried and the results are displayed based on the action performed.

the code in .js file is like this

when the search button is clicked this is the function called.

function searchCriteria(){

$.ajax({
type : "GET",
contentType : 'application/json',
async: "false",
data : $('#MODELATTRIBUTE').serialize(),
url : "Results",
success : function(response) {
if (response.errorCode == 0) {
$("#DDD").empty();
var list = response.RESULTLIST;

var totalRecords = response.totalRecords;

$
.each(
list ,
function(key, value) {

var tableRow = ""+value.YYYNbr+""
+ value.YYYNbr

+ ">";

$("").html(tableRow)
.appendTo("#DDD");
}
});


genericCalls(totalRecords, response.list);

}
},
});
}
}

function genericCalls(totalRecords, list){
var oTable = $('#example').dataTable({"bPaginate": true, "sPaginationType": "full_numbers", "bFilter" : false,
"bInfo":true,"iDeferLoading": totalRecords,"bServerSide": true,"sAjaxSource": "{{ajax funtion}}", "iTotalRecords":totalRecords
});

oTable.fnAddData(list); //Add data list to the table

$(document).off().on('click','.paginate_button',function() {
var pageNumber=$('.paginate_active').text();
function1(pageNumber); // requesting the Ajax call based on the page number clicked
});

$('#example_length select').on('change', function () {
function2(this.value);// requesting the Ajax call based on the Page Size (drop down - 10, 25, 50, 100) number selected

});
}

only first time the page is set like(by default 10 records are set and the number of pages are 5 for 62 records displayed) and aftert that wven when I change the page size to 25 or 50 or 100, the results are displayed but the page size drop down is getting reset to 10 and pagination is not working. Any help in this regard will be highly appreciated.

Please contact me if you need more information.

Thanks,
Sriram.T

Replies

  • allanallan Posts: 63,493Questions: 1Answers: 10,470 Site admin
    See the top FAQ: http://datatables.net/faqs#events .

    Allan
This discussion has been closed.