josecebe / twbs-pagination

jQuery pagination plugin (bootstrap powered)
http://josecebe.github.io/twbs-pagination/
Other
1.1k stars 401 forks source link

Introduce get current info for pagination #60

Closed pavelthq closed 7 years ago

pavelthq commented 8 years ago

Referers to: #59 Would be nice if we have a methods to get data about current state.

Examples:

var pagination = jQuery('#pagination').data('twbsPagination');
console.log( { 
 'currentPage': pagination.getCurrentPage(),
 'nextPageNumber': pagination.getNextPage(),
 'prevPageNumber': pagination.getPrevPage(),
 'lastPageNumber': pagination.getLastPage(),
 'firstPageNumber': pagination.getFirstPage(),
 ///... more else
  'isNextAllowed': pagination.isNextAllowed(),
  'isPrevAllowed': pagination.isPrevAllowed(),
  'isLastAllowed': pagination.isLastAllowed(),
  'isFirstAllowed': pagination.isFirstAllowed(),
  'showNext': ...
  'showPrev': ...
  'showFirst': ...
  'showLast': ...
  ''

some of them can be combined to one, for example isAllowed('next'), isAllowed('prev').. or show('next')/ show('+1'), show('first') / show(0)?

pavelthq commented 8 years ago

getCurrentPage is also would be helpfull in #61

versute commented 8 years ago

once the twbsPagination has been called on the page, is it possible to call it again, with different values for the totalPages and such? I am trying to use it within a page where I'm doing a search via AJAX, and based on the number of records that are in the result set, I need to update the pager. It's not working by calling twbsPagination on the jQuery element again

pavelthq commented 8 years ago

Yes it is possible. You need to destroy call before new initialization.

versute commented 8 years ago

Thanks, please provide example of using destroy().

pavelthq commented 8 years ago
$('#pagination').twbsPagination('destroy');

And then use initialization as usual.

joeybuddy commented 8 years ago

Experiencing the same problem, glad to see this, really helped! Another question here is how to check if the object is a TwbsPagination instance?

pavelthq commented 8 years ago

You can check by class for example. Or if pagination is initialized you can use jQuery(youelememt).data('twbsPagination')