I've made a simple scroll content loading feature based on primefaces datatable:
PF('tableWidget').jq.bind("scrollstop", function() {
var t = PF('tableWidget');
if(t.jq.scrollTop() + t.jq.height() >= t.jq.children().height()) {
var rows = t.jq.find('tr'); //save current rows
$.ajaxSetup({async: false}); //ajax set sync
t.paginator.setPage(t.paginator.cfg.page + 1); //framework pagination function with an ajax call inside (and other stuff) to get new rows
rows.prependTo(t.jq.find('tbody')); //AFTER pagination, add old rows
$.ajaxSetup({async: true}); //ajax set async again
}
});
Explanation: When a user scrolls down to the bottom of the dataTable, I just use the pagination, but save the old rows before. After finishing the pagination, I add the rows again. This leaves to a super cool scroll based loading, where only new data needs to be loaded from the server, and not the old content again.
But as I read in other questions, using synchronized ajax calls is bad practice.
It's not easy to override the "t.paginator.setPage(x)" function, because in this function there is anywhere an ajax call.
Is there a way, to wrap that whole function, and add some success callback to it, without digging down to the real basic ajax call?
Thanks a lot!