ソースを参照

added new method to order columns programatically

Dustin Utecht 6 年 前
コミット
e94a52a541

+ 11 - 0
site/docs/extensions/reorder-columns.md

@@ -56,6 +56,17 @@ Dependence:
 
 - **Default:** `null`
 
+## Methods
+
+### orderColumns
+
+- **parameters:** `object`
+
+- **Detail:**
+
+   Reorders the the columns by the given object.   
+   The Object key has to be the [field](https://bootstrap-table.com/docs/api/column-options/#field) and the value is the column index (starts by 0).
+
 ## Events
 
 ### onReorderColumn(reorder-column.bs.table)

+ 7 - 0
src/extensions/reorder-columns/bootstrap-table-reorder-columns.js

@@ -53,6 +53,8 @@ $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
   'reorder-column.bs.table': 'onReorderColumn'
 })
 
+$.fn.bootstrapTable.methods.push('orderColumns')
+
 const BootstrapTable = $.fn.bootstrapTable.Constructor
 const _initHeader = BootstrapTable.prototype.initHeader
 const _toggleColumn = BootstrapTable.prototype._toggleColumn
@@ -181,3 +183,8 @@ BootstrapTable.prototype.makeRowsReorderable = function () {
     }
   })
 }
+
+BootstrapTable.prototype.orderColumns = function (order) {
+  $(this.$el).dragtable('destroy').dragtable({restoreState: (order)})
+  this.makeRowsReorderable()
+}