I did it
in the View initialize
function
I call
this.reloadCustomPages();
here its implementation
reloadCustomPages: function(options) {
var self = this;
self.block();
self.customPages.fetch({data: $.param(options)}).always(function () {
self.unblock();
});
}
in the server side (java spring) I modified the api to accept new query strings
@RequestParam(value = "pageNumber", defaultValue = "1"),
@RequestParam(value = "perPage", defaultValue = "10")
and instead of returning the list directly it returns useful pagination info like
- total number of items in database
- current page nuber
- page size
- and the items itself
check this server-side snippet (I know it's not related but worthy to look at)
@RequestMapping(value = "/editor/pages", method = RequestMethod.GET)
public void listPages(@RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
@RequestParam(value = "perPage", defaultValue = "10") Integer perPage,
HttpServletResponse httpResp) throws IOException {
Long recordsTotal = pageSvc.findTotalNumberOfPages();// select count(*) from table_name
List<PbCustomPage> pages = pageSvc.findPages(pageNumber, perPage);// server side query that gets a pagenated data
BackbonePaginatorResponse response = new BackbonePaginatorResponse();// I created this simple class
response.setTotalCount(recordsTotal);
response.setPageNumber(pageNumber);
response.setPerPage(perPage);
response.setItems(pages);
httpResp.setContentType("application/json");
json.createCustomPageSerializer().addProperties().serialize(response, httpResp.getWriter());// just make your server send that obkect
}
now back the function call it will till the server to get page 1 with a page size of 10
in my template, I have this
<div class="pagination clear" style="text-align: center;">
<%= customPages.paginationHtml %>
</div>
let me tell you how I populate it
customPages.paginationHtml = this.generatePagination(customPages);
and here is the most important part
generatePagination: function (paginationResponse) {
var currentPage = paginationResponse.pageNumber,
lastPage = paginationResponse.totalCount==0?1:Math.ceil(paginationResponse.totalCount/paginationResponse.perPage);
var html = '<ul class="pagination">';
html += '<li class="'+(currentPage == 1?"disabled":"")+'" data-pb-page-number="1"><a href="#" class="first">««</a></li>';
html += '<li class="'+(currentPage == 1?"disabled":"")+'" data-pb-page-number="'+(currentPage==1?1:currentPage-1)+'"><a href="#" class="prev">«</a></li>';
for (var i = 1; i <= lastPage; i++) {
html += '<li class="'+(currentPage == i?"active":"")+'" data-pb-page-number="'+i+'"><a href="#" class="page">'+ i +'</a></li>';
}
html += '<li class="'+(lastPage == currentPage?"disabled":"")+'" data-pb-page-number="'+(currentPage==lastPage?lastPage:currentPage+1)+'"><a href="#" class="next">»</a></li>';
html += '<li class="'+(lastPage == currentPage?"disabled":"")+'" data-pb-page-number="'+(lastPage)+'"><a href="#" class="last">»»</a></li>';
html += '</ul>';
return html;
},
each li I create it has data-pb-page-number
to be used later
one more thing, how to make new requests to other pages
in the View initialize
function
this.el.on('click', 'ul.pagination li:not(.disabled,.active)', this.getCustomPagesPagination);
here its implementation
getCustomPagesPagination: function (e) {
e.preventDefault();
var $el = $(e.target).closest("li");
this.reloadCustomPages({pageNumber:$el.data("pb-page-number")})
},
the the result is like this

this how I solved my problem but the question still not answered