浏览代码

Add scrollTo method.

zhixin 11 年之前
父节点
当前提交
0ede824b81
共有 2 个文件被更改,包括 19 次插入3 次删除
  1. 6 1
      docs/_includes/documentation/methods.md
  2. 13 2
      src/bootstrap-table.js

+ 6 - 1
docs/_includes/documentation/methods.md

@@ -111,5 +111,10 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         <td>field</td>
         <td>Hide the specified column.</td>
     </tr>
+    <tr>
+        <td>scrollTo</td>
+        <td>value</td>
+        <td>Scroll to the number value position, set 'bottom' means scroll to the bottom.</td>
+    </tr>
     </tbody>
-</table>
+</table>

+ 13 - 2
src/bootstrap-table.js

@@ -1033,7 +1033,7 @@
         this.$body.html(html.join(''));
 
         if (!fixedScroll) {
-            this.$container.find('.fixed-table-body').scrollTop(0);
+            this.scrollTo(0);
         }
 
         // click to select by column
@@ -1458,6 +1458,16 @@
         this.updatePagination();
     };
 
+    BootstrapTable.prototype.scrollTo = function (value) {
+        var $tbody = this.$container.find('.fixed-table-body');
+        if (typeof value === 'string') {
+            value = value === 'bottom' ? $tbody[0].scrollHeight : 0;
+        }
+        if (typeof value === 'number') {
+            $tbody.scrollTop(value);
+        }
+    };
+
     // BOOTSTRAP TABLE PLUGIN DEFINITION
     // =======================
 
@@ -1472,7 +1482,8 @@
         'destroy',
         'showLoading', 'hideLoading',
         'showColumn', 'hideColumn',
-        'filterBy'
+        'filterBy',
+        'scrollTo'
     ];
 
     $.fn.bootstrapTable = function (option, _relatedTarget) {