浏览代码

Merge pull request #693 from djhvscf/master

getData parameter
文翼 10 年之前
父节点
当前提交
2cb5e876ac

+ 6 - 2
src/bootstrap-table.js

@@ -1681,10 +1681,14 @@
         $tableContainer.css('padding-bottom', padding + 'px');
         $tableContainer.css('padding-bottom', padding + 'px');
     };
     };
 
 
-    BootstrapTable.prototype.getData = function () {
+    BootstrapTable.prototype.getData = function (useCurrentPage) {
         return (this.searchText
         return (this.searchText
             || !$.isEmptyObject(this.filterColumns)
             || !$.isEmptyObject(this.filterColumns)
-            || !$.isEmptyObject(this.filterColumnsPartial)) ? this.data : this.options.data;
+            || !$.isEmptyObject(this.filterColumnsPartial)) ?
+            (useCurrentPage ? this.data.slice(this.pageFrom -1, this.pageTo)
+                : this.data) :
+            (useCurrentPage ? this.options.data.slice(this.pageFrom - 1, this.pageTo)
+                : this.options.data);
     };
     };
 
 
     BootstrapTable.prototype.load = function (data) {
     BootstrapTable.prototype.load = function (data) {

+ 2 - 2
src/extensions/flatJSON/bootstrap-table-flatJSON.js

@@ -44,8 +44,6 @@
 
 
     BootstrapTable.prototype.initData = function () {
     BootstrapTable.prototype.initData = function () {
 
 
-        _initData.apply(this, Array.prototype.slice.apply(arguments));
-
         //If the flat is true
         //If the flat is true
         if (this.options.flat) {
         if (this.options.flat) {
             this.options.data = sd.flatHelper(this.options.data);
             this.options.data = sd.flatHelper(this.options.data);
@@ -53,6 +51,8 @@
         if (this.options.sidePagination === 'server') {
         if (this.options.sidePagination === 'server') {
             this.data = this.options.data;
             this.data = this.options.data;
         }
         }
+
+        _initData.apply(this, Array.prototype.slice.apply(arguments));
     };
     };
 
 
     //Main functions
     //Main functions

+ 13 - 0
src/extensions/naturalsorting/README.md

@@ -0,0 +1,13 @@
+# Table Natural Sorting
+
+Use Plugin: [bootstrap-table-naturalsorting](https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/naturalsorting)
+
+## Usage
+
+```html
+<script src="extensions/naturalsorting/bootstrap-table-naturalsorting.js"></script>
+```
+
+### Options
+
+* Just add data-sorter="alphanum" to any th

+ 47 - 0
src/extensions/naturalsorting/bootstrap-table-naturalsorting.js

@@ -0,0 +1,47 @@
+/**
+ * @author: Brian Huisman
+ * @webSite: http://www.greywyvern.com
+ * @version: v1.0.0
+ * JS function to allow natural sorting on bootstrap-table columns
+ * just add data-sorter="alphanum" to any th
+ *
+ * @update Dennis Hernández <http://djhvscf.github.io/Blog>
+ */
+
+function alphanum(a, b) {
+  function chunkify(t) {
+    var tz = [],
+        x = 0,
+        y = -1,
+        n = 0,
+        i,
+        j;
+
+    while (i = (j = t.charAt(x++)).charCodeAt(0)) {
+      var m = (i === 46 || (i >= 48 && i <= 57));
+      if (m !== n) {
+        tz[++y] = "";
+        n = m;
+      }
+      tz[y] += j;
+    }
+    return tz;
+  }
+
+  var aa = chunkify(a);
+  var bb = chunkify(b);
+
+  for (x = 0; aa[x] && bb[x]; x++) {
+    if (aa[x] !== bb[x]) {
+      var c = Number(aa[x]),
+          d = Number(bb[x]);
+
+      if (c == aa[x] && d == bb[x]) {
+        return c - d;
+      } else {
+          return (aa[x] > bb[x]) ? 1 : -1;
+      }
+    }
+  }
+  return aa.length - bb.length;
+}

+ 35 - 0
src/extensions/reorder/README.md

@@ -0,0 +1,35 @@
+# Table Reorder
+
+Use Plugin: [bootstrap-table-reorder](https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/reorder) </br>
+Dependence: [dragTable](https://github.com/akottr/dragtable/) v2.0.14 (must include the css file), </br>
+[jquery-ui](https://code.jquery.com/ui/) v1.11
+
+
+## Usage
+
+```html
+<link rel="stylesheet" href=".../dragtable.css">
+<script src=".../jquery-ui.js"></script>
+<script src=".../jquery.dragtable.js"></script>
+<script src="extensions/cookie/bootstrap-table-reorder.js"></script>
+```
+
+## Options
+
+### reorderable
+
+* type: Boolean
+* description: Set true to allow the reorder feature.
+* default: `false`
+
+### maxMovingRows
+
+* type: Integer
+* description: Moving only the header. Recommended for very large tables (cells > 1000)
+* default: `10`
+
+## Events
+
+### onReorder(reorder.bs.table)
+
+Fired when the column was dropped, receive as parameter the new header fields order

+ 54 - 0
src/extensions/reorder/bootstrap-table-reorder.js

@@ -0,0 +1,54 @@
+/**
+ * @author: Dennis Hernández
+ * @webSite: http://djhvscf.github.io/Blog
+ * @version: v1.0.0
+ */
+
+!function ($) {
+
+    'use strict';
+
+    $.extend($.fn.bootstrapTable.defaults, {
+        reorderable: false,
+        maxMovingRows: 10,
+        onReorder: function (headerFields) {
+            return false;
+        }
+    });
+
+    $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
+        'reorder.bs.table': 'onReorder'
+    });
+
+    var BootstrapTable = $.fn.bootstrapTable.Constructor,
+        _initHeader = BootstrapTable.prototype.initHeader;
+
+    BootstrapTable.prototype.initHeader = function () {
+        _initHeader.apply(this, Array.prototype.slice.apply(arguments));
+
+        if (!this.options.reorderable) {
+            return;
+        }
+
+        this.makeColumnsReorderable();
+    };
+
+    BootstrapTable.prototype.makeColumnsReorderable = function () {
+
+        var that = this;
+        $(this.$el).dragtable({
+            maxMovingRows: that.options.maxMovingRows,
+            clickDelay:200,
+            beforeStop: function() {
+                var ths = [];
+                that.$header.find('th').each(function (i) {
+                    ths.push($(this).data('field'));
+                });
+
+                that.header.fields = ths;
+                that.resetView();
+                that.trigger('reorder', ths);
+            }
+        });
+    };
+}(jQuery);

+ 10 - 1
src/extensions/resizable/bootstrap-table-resizable.js

@@ -45,7 +45,8 @@
     var BootstrapTable = $.fn.bootstrapTable.Constructor,
     var BootstrapTable = $.fn.bootstrapTable.Constructor,
         _init = BootstrapTable.prototype.init,
         _init = BootstrapTable.prototype.init,
         _toggleColumn = BootstrapTable.prototype.toggleColumn,
         _toggleColumn = BootstrapTable.prototype.toggleColumn,
-        _toggleView = BootstrapTable.prototype.toggleView;
+        _toggleView = BootstrapTable.prototype.toggleView,
+        _resetView = BootstrapTable.prototype.resetView;
 
 
     BootstrapTable.prototype.init = function () {
     BootstrapTable.prototype.init = function () {
         _init.apply(this, Array.prototype.slice.apply(arguments));
         _init.apply(this, Array.prototype.slice.apply(arguments));
@@ -75,4 +76,12 @@
             initResizable(this);
             initResizable(this);
         }
         }
     };
     };
+
+    BootstrapTable.prototype.resetView = function () {
+        _resetView.apply(this, Array.prototype.slice.apply(arguments));
+
+        if (this.options.resizable) {
+            initResizable(this);
+        }
+    };
 })(jQuery);
 })(jQuery);

+ 0 - 32
src/extensions/sorting/bootstrap-table_natural-sorting.js

@@ -1,32 +0,0 @@
-//JS function to allow natural sorting on bootstrap-table columns
-//just add data-sorter="alphanum" to any th
-//Thanks to Brian Huisman: http://www.greywyvern.com
-
-function alphanum(a, b) {
-  function chunkify(t) {
-    var tz = [], x = 0, y = -1, n = 0, i, j;
-
-    while (i = (j = t.charAt(x++)).charCodeAt(0)) {
-      var m = (i == 46 || (i >=48 && i <= 57));
-      if (m !== n) {
-        tz[++y] = "";
-        n = m;
-      }
-      tz[y] += j;
-    }
-    return tz;
-  }
-
-  var aa = chunkify(a);
-  var bb = chunkify(b);
-
-  for (x = 0; aa[x] && bb[x]; x++) {
-    if (aa[x] !== bb[x]) {
-      var c = Number(aa[x]), d = Number(bb[x]);
-      if (c == aa[x] && d == bb[x]) {
-        return c - d;
-      } else return (aa[x] > bb[x]) ? 1 : -1;
-    }
-  }
-  return aa.length - bb.length;
-}