Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination issue #3

Open
ghost opened this issue Jan 4, 2013 · 3 comments
Open

Pagination issue #3

ghost opened this issue Jan 4, 2013 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 4, 2013

Hi,

I have really big data to be send to the datagrid and I display them per 50 in each page. My problem is that I have "<< 1 2 3 ... 40 >>" and this is taking more than a line and getting ugly on my page.

Do you already have a solution to have "<< ... 25 26 ... >>" instead for example or any idea about how doing it ?

Thank you

@loicfrering
Copy link
Owner

Hi, this is indeed a known problem, I am working for the next version on alternative pagination controls. Right now you can override Backbone.Datagrid.Pagination view or Backbone.Datagrid.prototype.renderPagination.

Thanks for reporting.

@Filirom1
Copy link

Thank you for the explanation.

It's quite simple to only keeps the arrows :

  Backbone.Datagrid.Pagination.prototype.render = function(){
    var $ul = $('<ul></ul>'), $li;

    $li = $('<li class="prev"><a href="#">«</a></li>');
    if (!this.pager.hasPrev()) {
      $li.addClass('disabled');
    }
    $ul.append($li);

    $li = $('<li class="next"><a href="#">»</a></li>');
    if (!this.pager.hasNext()) {
      $li.addClass('disabled');
    }
    $ul.append($li);

    this.$el.append($ul);
    return this;
  };

@tikal
Copy link

tikal commented May 2, 2014

I needed a sort of truncated pager, here is a rough render function that does not fully display the pager by adding some disabled ... cases.
The pager is "truncated" only if the truncated parameter is set to true. Else the rendering is full.

render: function() {
    var $ul = $('<ul></ul>'), $li;

    $li = $('<li class="prev"><a href="#">«</a></li>');
    if (!this.pager.hasPrev()) {
      $li.addClass('disabled');
    }
    $ul.append($li);

    if(this.pager.get('truncated')) {
        var previousIsHidden = false;
    }
    if (this.pager.hasTotal()) {
      for (var i = 1; i <= this.pager.get('totalPages'); i++) {
        $li = $('<li></li>');
        var current = this.pager.get('currentPage');
        if (i === current) {
          $li.addClass('active');
        }

        if(this.pager.get('truncated')) {
            var max = this.pager.get('totalPages');
            if(i == 1 || i == 2 || i == max || i == max - 1 || i == current 
                    || i == current - 1 || i == current -2 || i == current + 1 || i == current + 2) {
                $li.append('<a href="#">' + i + '</a>');
                $ul.append($li);
                previousIsHidden = false;
            }
            else {
                if(!previousIsHidden) {
                    $li.append('<a href="#">...</a>');
                    $li.addClass('disabled');
                    $ul.append($li);
                    previousIsHidden = true;
                }
            }
        }
        else {
            $li.append('<a href="#">' + i + '</a>');
            $ul.append($li);
        }
      }
    }

    $li = $('<li class="next"><a href="#">»</a></li>');
    if (!this.pager.hasNext()) {
      $li.addClass('disabled');
    }
    $ul.append($li);

    this.$el.append($ul);
    return this;
  },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants