浏览代码

Add selectPage method, update prevPage and nextPage methods.

zhixin 11 年之前
父节点
当前提交
e9dc85a2df

+ 5 - 0
docs/_i18n/en/documentation/methods.md

@@ -152,6 +152,11 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         <td>(Can use only in client-side)Filter data in table, eg. you can filter <code>{age: 10}</code> to show the data only age is equal to 10.</td>
     </tr>
     <tr>
+        <td>selectPage</td>
+        <td>page</td>
+        <td>Go to the a specified page.</td>
+    </tr>
+    <tr>
         <td>prevPage</td>
         <td>none</td>
         <td>Go to previous page.</td>

+ 5 - 0
docs/_i18n/es/documentation/methods.md

@@ -152,6 +152,11 @@ Sintaxis para llamar a un método: `$('#table').bootstrapTable('method', paramet
         <td>(Solo se puede usar en client-side)Filtra los datos en la tabla, ejm. se puede filtrar <code>{age: 10}</code> para mostrar los daros solo con la edad igual a 10.</td>
     </tr>
     <tr>
+        <td>selectPage</td>
+        <td>page</td>
+        <td>Go to the a specified page.</td>
+    </tr>
+    <tr>
         <td>prevPage</td>
         <td>none</td>
         <td>Ir a la página anterior.</td>

+ 5 - 0
docs/_i18n/fr/documentation/methods.md

@@ -152,6 +152,11 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         <td>(Can use only in client-side)Filter data in table, eg. you can filter <code>{age: 10}</code> to show the data only age is equal to 10.</td>
     </tr>
     <tr>
+        <td>selectPage</td>
+        <td>page</td>
+        <td>Go to the a specified page.</td>
+    </tr>
+    <tr>
         <td>prevPage</td>
         <td>none</td>
         <td>Go to previous page.</td>

+ 5 - 0
docs/_i18n/zh-cn/documentation/methods.md

@@ -152,6 +152,11 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         <td>(Can use only in client-side)Filter data in table, eg. you can filter <code>{age: 10}</code> to show the data only age is equal to 10.</td>
     </tr>
     <tr>
+        <td>selectPage</td>
+        <td>page</td>
+        <td>Go to the a specified page.</td>
+    </tr>
+    <tr>
         <td>prevPage</td>
         <td>none</td>
         <td>Go to previous page.</td>

+ 17 - 5
src/bootstrap-table.js

@@ -781,6 +781,7 @@
         this.totalPages = 0;
         if (this.options.totalRows) {
             this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1;
+            this.options.totalPages = this.totalPages;
         }
         if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) {
             this.options.pageNumber = this.totalPages;
@@ -1595,14 +1596,25 @@
         }
     };
 
+    BootstrapTable.prototype.selectPage = function (page) {
+        if (page > 0 && page <= this.options.totalPages) {
+            this.options.pageNumber = page;
+            this.updatePagination();
+        }
+    };
+
     BootstrapTable.prototype.prevPage = function () {
-        this.options.pageNumber > 1 ? this.options.pageNumber-- : null;
-        this.updatePagination();
+        if (this.options.pageNumber > 1) {
+            this.options.pageNumber--;
+            this.updatePagination();
+        }
     };
 
     BootstrapTable.prototype.nextPage = function () {
-        this.options.pageNumber < this.options.pageSize ? this.options.pageNumber++ : null;
-        this.updatePagination();
+        if (this.options.pageNumber < this.options.totalPages) {
+            this.options.pageNumber++;
+            this.updatePagination();
+        }
     };
 
     // BOOTSTRAP TABLE PLUGIN DEFINITION
@@ -1623,7 +1635,7 @@
         'showColumn', 'hideColumn',
         'filterBy',
         'scrollTo',
-        'prevPage', 'nextPage',
+        'selectPage', 'prevPage', 'nextPage',
         'togglePagination'
     ];