浏览代码

Add toolbar option.

zhixin 11 年之前
父节点
当前提交
f1e5141e8b
共有 3 个文件被更改,包括 13 次插入2 次删除
  1. 2 2
      docs/examples.html
  2. 1 0
      src/bootstrap-table.css
  3. 10 0
      src/bootstrap-table.js

+ 2 - 2
docs/examples.html

@@ -116,7 +116,7 @@
                     <h1 id="transform-table">Transform Table</h1>
                 </div>
                 <div class="bs-example">
-                    <div class="btn-group btn-default">
+                    <div id="transform-buttons" class="btn-group btn-default">
                         <button class="btn btn-default" id="transform">
                             <i class="glyphicon glyphicon-transfer"></i> Transform
                         </button>
@@ -124,7 +124,7 @@
                             <i class="glyphicon glyphicon-trash"></i> Destroy
                         </button>
                     </div>
-                    <table id="table-transform" data-url="data1.json" data-height="246">
+                    <table id="table-transform" data-url="data1.json" data-height="246" data-toolbar="#transform-buttons">
                         <thead>
                             <tr>
                                 <th data-field="id">Item ID</th>

+ 1 - 0
src/bootstrap-table.css

@@ -129,6 +129,7 @@
     line-height: 1.428571429;
 }
 
+.fixed-table-toolbar .bars,
 .fixed-table-toolbar .search,
 .fixed-table-toolbar .columns {
     position: relative;

+ 10 - 0
src/bootstrap-table.js

@@ -82,6 +82,7 @@
         idField: undefined,
         cardView: false,
         clickToSelect: false,
+        toolbar: undefined,
 
         rowStyle: function(row, index) {return {};},
 
@@ -320,6 +321,12 @@
 
         this.$toolbar = this.$container.find('.fixed-table-toolbar');
 
+        if (typeof this.options.toolbar === 'string') {
+            $('<div class="bars pull-left"></div>')
+                .appendTo(this.$toolbar)
+                .append($(this.options.toolbar));
+        }
+
         if (this.options.showColumns) {
             html = [];
             html.push('<div class="columns pull-right keep-open">',
@@ -844,8 +851,11 @@
     };
 
     BootstrapTable.prototype.destroy = function() {
+        var $toolbar = $(this.options.toolbar).clone(true, true);
+
         this.$container.next().remove();
         this.$container.replaceWith(this.$el_);
+        $toolbar.insertBefore(this.$el_);
         return this.$el_;
     };