list.js icon indicating copy to clipboard operation
list.js copied to clipboard

Paging plugin : next and previous button

Open fabien-h opened this issue 13 years ago • 11 comments

How would you implement a next and previous button ? It would be a nice improvement to a nice plugin :)

fabien-h avatar Jun 19 '13 11:06 fabien-h

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 ?

fabien-h avatar Jun 19 '13 12:06 fabien-h

Duplicate of #82

I'll look into this feature as soon as possible, and I'm currently working on rebuilding the plugin system.

javve avatar Sep 18 '13 21:09 javve

any progress on this one ?

Pushplaybang avatar Sep 02 '14 14:09 Pushplaybang

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');
        }
    })
})

Mat-thieu avatar Sep 23 '15 09:09 Mat-thieu

Is this for real?

p6m459 avatar Mar 04 '17 21:03 p6m459

Was hoping the latest update would have had this added. Any chance of it coming in the next update?

elixirgraphics avatar Mar 15 '17 20:03 elixirgraphics

Second this. This feature would be really useful.

hifall avatar Aug 05 '17 11:08 hifall

Hi Javve, superb work on the plugin. But, this is basic requirement !!! companies will have some standards regarding Branding.

vikramksrm avatar Aug 16 '17 10:08 vikramksrm

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.

synsa avatar Aug 21 '17 05:08 synsa

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 avatar Aug 30 '17 23:08 eduardo-haddad

@eduardo-haddad The abomination is evolving :) Good addition

Mat-thieu avatar Feb 03 '18 21:02 Mat-thieu