浏览代码

Smart display pagination and per page section.

- Added smart-display option as table param.
- Hide pagination when there is only one page and smart-display is set on true.
- Hide per-page section when there no more options to change and smart-display is set on true.
- For per-page section, showing only options which make a seans and smart-display is set on true.
Slawomir Sawicki 11 年之前
父节点
当前提交
7fb85411e2
共有 1 个文件被更改,包括 13 次插入2 次删除
  1. 13 2
      src/bootstrap-table.js

+ 13 - 2
src/bootstrap-table.js

@@ -140,6 +140,7 @@
         showColumns: false,
         showRefresh: false,
         showToggle: false,
+        smartDisplay: false,
         minimumCountColumns: 1,
         idField: undefined,
         cardView: false,
@@ -710,8 +711,10 @@
         }
 
         $.each(pageList, function (i, page) {
-            var active = page === that.options.pageSize ? ' class="active"' : '';
-            pageNumber.push(sprintf('<li%s><a href="javascript:void(0)">%s</a></li>', active, page));
+            if (that.options.smartDisplay === false || that.options.totalRows >= page || page == pageList[0]) {
+                var active = page === that.options.pageSize ? ' class="active"' : '';
+                pageNumber.push(sprintf('<li%s><a href="javascript:void(0)">%s</a></li>', active, page));
+            }
         });
         pageNumber.push('</ul></span>');
 
@@ -768,6 +771,14 @@
             $next.addClass('disabled');
             $last.addClass('disabled');
         }
+        if (this.options.smartDisplay) {
+            if (this.totalPages <= 1) {
+                this.$pagination.find('div.pagination').hide();
+            }
+            if (this.options.totalRows <= this.options.pageList[1]) {
+                this.$pagination.find('div.pagination-detail').hide();
+            }
+        }
         $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
         $first.off('click').on('click', $.proxy(this.onPageFirst, this));
         $pre.off('click').on('click', $.proxy(this.onPagePre, this));