Paging plugin : next and previous button
How would you implement a next and previous button ? It would be a nice improvement to a nice plugin :)
I see a really ugly of doing it :
var addEvent = function(elm, i, page) {
ListJsHelpers.addEvent(elm, 'click', function() {
list.show((i-1)*page + 1, page);
});
};
Would become something like that:
var addEvent = function(elm, i, page) {
if( elm.getID === 'prev' ){
ListJsHelpers.addEvent(elm, 'click', function() {
if( getCurrentPageID-- > 0 )list.show( getCurrentPageID--, page);
});
}else if( elm.getID === 'next' ){
ListJsHelpers.addEvent(elm, 'click', function() {
if( getCurrentPageID-- < pageCount ) list.show( getCurrentPageID++, page);
});
}else {
ListJsHelpers.addEvent(elm, 'click', function() {
list.show((i-1)*page + 1, page);
});
}
};
And the prev and next elements would have been created first.
But this is soooooo ugly.
Better idea ?
Duplicate of #82
I'll look into this feature as soon as possible, and I'm currently working on rebuilding the plugin system.
any progress on this one ?
Using jQuery, I found a rather disgusting way to fix this
$('.btn-next').on('click', function(){
var list = $('.pagination').find('li');
$.each(list, function(position, element){
if($(element).is('.active')){
$(list[position+1]).trigger('click');
}
})
})
$('.btn-prev').on('click', function(){
var list = $('.pagination').find('li');
$.each(list, function(position, element){
if($(element).is('.active')){
$(list[position-1]).trigger('click');
}
})
})
Is this for real?
Was hoping the latest update would have had this added. Any chance of it coming in the next update?
Second this. This feature would be really useful.
Hi Javve, superb work on the plugin. But, this is basic requirement !!! companies will have some standards regarding Branding.
This feature is almost a requirement for most pagination plugins.
It would be nice to have a solution implemented in order to display prev/next buttons along with the default page numbers. ( << 1 2 3 4 5 >>)
Would love to hear any sort of update on this feature.
adaptation of @Mat-thieu's code so that clicking "next" on last item returns to the first (the opposite for "prev"):
$('.btn-next').on('click', function(){
var list = $('.pagination').find('li');
$.each(list, function(position, element){
if($(element).is('.active')){
$(list[position+1]).trigger('click');
if(!$(list[position+1]).length) {
$(list[position - (list.length-1)]).trigger('click');
}
}
})
})
$('.btn-prev').on('click', function(){
var list = $('.pagination').find('li');
$.each(list, function(position, element){
if($(element).is('.active')){
$(list[position-1]).trigger('click');
if(!$(list[position-1]).length) {
$(list[position + (list.length-1)]).trigger('click');
}
}
})
})
@eduardo-haddad The abomination is evolving :) Good addition