ソースを参照

Merge pull request #3 from wenzhixin/master

Get the lastest version
Dennis Hernández 11 年 前
コミット
569a09e6a9

+ 7 - 6
README.md

@@ -1,22 +1,23 @@
 # [Bootstrap Table](http://bootstrap-table.wenzhixin.net.cn)
 
-[![Build Status](https://travis-ci.org/wenzhixin/bootstrap-table.png)](https://travis-ci.org/wenzhixin/bootstrap-table)
+[![Build Status](https://travis-ci.org/wenzhixin/bootstrap-table.png)](https://travis-ci.org/wenzhixin/bootstrap-table) 
+[![GitHub version](https://badge.fury.io/gh/wenzhixin%2Fbootstrap-table.png)](http://badge.fury.io/gh/wenzhixin%2Fbootstrap-table)
+[![Bower version](https://badge.fury.io/bo/bootstrap-table.svg)](http://badge.fury.io/bo/bootstrap-table)
+[![Views in the last 24 hours](https://sourcegraph.com/api/repos/github.com/wenzhixin/bootstrap-table/.counters/views-24h.png)](https://github.com/wenzhixin/bootstrap-table)
+[![Gratipay](https://img.shields.io/gratipay/wenzhixin.svg)](https://gratipay.com/wenzhixin/)
 
 An extended Bootstrap table with radio, checkbox, sort, pagination, and other added features.
 
 To get started, check out http://bootstrap-table.wenzhixin.net.cn!
 
-## Latest release
-
-1.4.0 (2014-11-21)
-
 ## LICENSE
 
 **NOTE:** Bootstrap Table is licensed under the [The MIT License](https://github.com/wenzhixin/bootstrap-table/blob/master/LICENSE). Completely free, you can arbitrarily use and modify this plugin. If this plugin is useful to you, you can **Star** this repo, your support is my biggest motive force, thanks.
 
 ## Bugs & Enhancements (next version)
 
-- [ ] Fix #144: `onCheck` and `onUncheck` method are reversed when using `clickToSelect` option. (jQuery 1.7.2 bug).
+- [x] Fix #144: `onCheck` and `onUncheck` events are reversed when using `clickToSelect` option. (jQuery 1.7.2 bug).
+- [x] Fix #261: add namespace to `.table` style.
 
 ## Features
 

ファイルの差分が大きいため隠しています
+ 2 - 2
dist/bootstrap-table.min.js


+ 13 - 1
docs/_includes/documentation/events.md

@@ -118,5 +118,17 @@
         <td>text</td>
         <td>Fires when search the table.</td>
     </tr>
+    <tr>
+        <td>onPreBody</td>
+        <td>pre-body.bs.table</td>
+        <td>data</td>
+        <td>Fires before the table body is rendered</td>
+    </tr>
+    <tr>
+        <td>onPostBody</td>
+        <td>post-body.bs.table</td>
+        <td>none</td>
+        <td>Fires after the table body is rendered and available in the DOM</td>
+    </tr>
     </tbody>
-</table>
+</table>

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

@@ -111,5 +111,15 @@ 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>
+    <tr>
+        <td>filterBy</td>
+        <td>params</td>
+        <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>
     </tbody>
-</table>
+</table>

+ 5 - 0
docs/_includes/header.html

@@ -42,3 +42,8 @@
   ga('create', 'UA-36708951-1', 'wenzhixin.net.cn');
   ga('send', 'pageview');
 </script>
+
+<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
+
+<!-- 将此标记放置在 head 中,或放置在结束 body 标记之前,并使其紧邻此标记。 -->
+<script src="https://apis.google.com/js/platform.js" async defer></script>

+ 31 - 11
docs/_includes/social-buttons.html

@@ -1,13 +1,33 @@
 <div class="bs-docs-social">
-  <ul class="bs-docs-social-buttons">
-    <li>
-      <iframe class="github-btn" src="http://ghbtns.com/github-btn.html?user=wenzhixin&repo=bootstrap-table&type=watch&count=true" width="100" height="20" title="Star on GitHub"></iframe>
-    </li>
-    <li>
-      <iframe class="github-btn" src="http://ghbtns.com/github-btn.html?user=wenzhixin&repo=bootstrap-table&type=fork&count=true" width="102" height="20" title="Fork on GitHub"></iframe>
-    </li>
-    <li>
-      <iframe class="github-btn" src="http://ghbtns.com/github-btn.html?user=wenzhixin&type=follow&count=true" width="175" height="20" title="Follow on GitHub"></iframe>
-    </li>
-  </ul>
+    if you like bootstrap table - help:
+    <ul class="bs-docs-social-buttons">
+        <li>
+            <iframe class="github-btn"
+                    src="http://ghbtns.com/github-btn.html?user=wenzhixin&repo=bootstrap-table&type=watch&count=true"
+                    width="100" height="20" title="Star on GitHub"></iframe>
+        </li>
+        <li>
+            <iframe class="github-btn"
+                    src="http://ghbtns.com/github-btn.html?user=wenzhixin&repo=bootstrap-table&type=fork&count=true"
+                    width="102" height="20" title="Fork on GitHub"></iframe>
+        </li>
+        <li>
+            <iframe class="github-btn" src="http://ghbtns.com/github-btn.html?user=wenzhixin&type=follow&count=true"
+                    width="175" height="20" title="Follow on GitHub"></iframe>
+        </li>
+        <li>
+            <!-- https://about.twitter.com/resources/buttons#tweet -->
+            <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://wenzhixin.net.cn/p/bootstrap-table" data-via="BootstrapTable" data-related="BootstrapTable">Tweet</a>
+        </li>
+        <!--<li>-->
+            <!--<a href="https://twitter.com/BootstrapTable" class="twitter-follow-button" data-show-count="false">Follow @BootstrapTable</a>-->
+        <!--</li>-->
+        <li>
+            <!-- 将此标记放置在你希望显示+1 按钮的位置。 -->
+            <div class="g-plusone" data-annotation="inline" data-width="120"></div>
+        </li>
+        <li>
+            <script data-gratipay-username="wenzhixin" data-gratipay-widget="button" src="//gttp.co/v1.js"></script>
+        </li>
+    </ul>
 </div>

+ 4 - 0
docs/_layouts/default.html

@@ -18,6 +18,10 @@
       </div>
     </div>
 
+    {% include social-buttons.html %}
+
+    <hr>
+
     <div class="container bs-docs-container">
 
       <div class="row">

ファイルの差分が大きいため隠しています
+ 2 - 2
docs/dist/bootstrap-table.min.js


+ 3 - 3
src/bootstrap-table.css

@@ -1,4 +1,4 @@
-.table {
+.bootstrap-table .table {
     margin-bottom: 0 !important;
     border-bottom: 1px solid #dddddd;
     border-collapse: collapse !important;
@@ -207,13 +207,13 @@
     border-bottom-right-radius: 4px;
 }
 
-.table>thead>tr>th {
+.bootstrap-table .table>thead>tr>th {
     vertical-align: bottom;
     border-bottom: 2px solid #ddd;
 }
 
 /* support bootstrap 3 */
-.table thead>tr>th {
+.bootstrap-table .table thead>tr>th {
     padding: 0;
     margin: 0;
 }

+ 58 - 15
src/bootstrap-table.js

@@ -207,7 +207,9 @@
         onLoadError: function (status) {return false;},
         onColumnSwitch: function (field, checked) {return false;},
         onPageChange: function (number, size) {return false;},
-        onSearch: function (text) {return false;}
+        onSearch: function (text) {return false;},
+        onPreBody: function (data) {return false;},
+        onPostBody: function () {return false;}
     };
 
     BootstrapTable.COLUMN_DEFAULTS = {
@@ -245,7 +247,9 @@
         'load-error.bs.table': 'onLoadError',
         'column-switch.bs.table': 'onColumnSwitch',
         'page-change.bs.table': 'onPageChange',
-        'search.bs.table': 'onSearch'
+        'search.bs.table': 'onSearch',
+        'pre-body.bs.table': 'onPreBody',
+        'post-body.bs.table': 'onPostBody'
     };
 
     BootstrapTable.prototype.init = function () {
@@ -468,6 +472,14 @@
                     return order * value;
                 }
 
+                // Convert numerical values form string to float.
+                if ($.isNumeric(aa)) {
+                    aa = parseFloat(aa);
+                }
+                if ($.isNumeric(bb)) {
+                    bb = parseFloat(bb);
+                }
+
                 // Fix #161: undefined or null string sort bug.
                 if (aa === undefined || aa === null) {
                     aa = '';
@@ -651,8 +663,19 @@
 
         if (this.options.sidePagination !== 'server') {
             var s = this.searchText && this.searchText.toLowerCase();
+            var f = $.isEmptyObject(this.filterColumns) ? null: this.filterColumns;
 
-            this.data = s ? $.grep(this.options.data, function (item, i) {
+            // Check filter
+            this.data = f ? $.grep(this.options.data, function (item, i) {
+                for (var key in f) {
+                    if (item[key] !== f[key]) {
+                        return false;
+                    }
+                }
+                return true;
+            }) : this.options.data;
+
+            this.data = s ? $.grep(this.data, function (item, i) {
                 for (var key in item) {
                     key = $.isNumeric(key) ? parseInt(key, 10) : key;
                     var value = item[key];
@@ -670,7 +693,7 @@
                     }
                 }
                 return false;
-            }) : this.options.data;
+            }) : this.data;
         }
     };
 
@@ -803,6 +826,9 @@
             if (this.options.pageList.length < 2 || this.options.totalRows <= this.options.pageList[1]) {
                 this.$pagination.find('span.page-list').hide();
             }
+
+            // when data is empty, hide the pagination
+            this.$pagination[this.getData().length ? 'show' : 'hide']();
         }
         $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
         $first.off('click').on('click', $.proxy(this.onPageFirst, this));
@@ -874,6 +900,8 @@
             html = [],
             data = this.getData();
 
+        this.trigger('pre-body', data);
+
         this.$body = this.$el.find('tbody');
         if (!this.$body.length) {
             this.$body = $('<tbody></tbody>').appendTo(this.$el);
@@ -914,8 +942,8 @@
 
             html.push('<tr',
                 sprintf(' %s', htmlAttributes.join(' ')),
-                sprintf(' id="%s"', item._id),
-                sprintf(' class="%s"', style.classes || item._class),
+                sprintf(' id="%s"', $.isArray(item) ? undefined : item._id),
+                sprintf(' class="%s"', style.classes || $.isArray(item) ? undefined : item._class),
                 sprintf(' data-index="%s"', i),
                 '>'
             );
@@ -1019,7 +1047,7 @@
         this.$body.html(html.join(''));
 
         if (!fixedScroll) {
-            this.$container.find('.fixed-table-body').scrollTop(0);
+            this.scrollTo(0);
         }
 
         // click to select by column
@@ -1030,7 +1058,7 @@
             if (that.options.clickToSelect) {
                 if (that.header.clickToSelects[$tr.children().index($(this))]) {
                     $tr.find(sprintf('[name="%s"]',
-                        that.options.selectItemName)).trigger('click');
+                        that.options.selectItemName))[0].click(); // #144: .trigger('click') bug
                 }
             }
         });
@@ -1042,11 +1070,6 @@
         this.$selectItem.off('click').on('click', function (event) {
             event.stopImmediatePropagation();
 
-            // radio trigger click event bug!
-            if ($(this).is(':radio')) {
-                $(this).prop('checked', true);
-            }
-
             var checkAll = that.$selectItem.filter(':enabled').length ===
                     that.$selectItem.filter(':enabled').filter(':checked').length,
                 checked = $(this).prop('checked'),
@@ -1096,6 +1119,8 @@
 
         this.updateSelected();
         this.resetView();
+
+        this.trigger('post-body');
     };
 
     BootstrapTable.prototype.initServer = function (silent) {
@@ -1310,7 +1335,7 @@
     };
 
     BootstrapTable.prototype.getData = function () {
-        return this.searchText ? this.data : this.options.data;
+        return (this.searchText || !$.isEmptyObject(this.filterColumns)) ? this.data : this.options.data;
     };
 
     BootstrapTable.prototype.load = function (data) {
@@ -1442,6 +1467,22 @@
         this.toggleColumn(getFieldIndex(this.options.columns, field), false, true);
     };
 
+    BootstrapTable.prototype.filterBy = function (columns) {
+        this.filterColumns = $.isEmptyObject(columns) ? {}: columns;
+        this.options.pageNumber = 1;
+        this.initSearch();
+        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
     // =======================
@@ -1456,7 +1497,9 @@
         'resetView',
         'destroy',
         'showLoading', 'hideLoading',
-        'showColumn', 'hideColumn'
+        'showColumn', 'hideColumn',
+        'filterBy',
+        'scrollTo'
     ];
 
     $.fn.bootstrapTable = function (option, _relatedTarget) {

+ 8 - 0
src/extensions/editable/README.md

@@ -23,3 +23,11 @@ Use Plugin: [x-editable](https://github.com/vitalets/x-editable)
 * type: Object
 * description: Configuration of x-editable. Full list of options: http://vitalets.github.io/x-editable/docs.html#editable
 * default: `undefined`
+
+## Events
+
+### onEditableInit(editable-init.bs.table)
+
+Fired when all columns was initialized by `$().editable()` method.
+
+

+ 14 - 2
src/extensions/editable/bootstrap-table-editable.js

@@ -8,7 +8,12 @@
     'use strict';
 
     $.extend($.fn.bootstrapTable.defaults, {
-        editable: true
+        editable: true,
+        onEditableInit: function () {return false;}
+    });
+
+    $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
+        'editable-init.bs.table': 'onEditableInit'
     });
 
     var BootstrapTable = $.fn.bootstrapTable.Constructor,
@@ -54,8 +59,15 @@
                 return;
             }
 
-            that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable);
+            that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
+                .off('save').on('save', function (e, params) {
+                    var data = that.getData(),
+                        row = data[$(this).parents('tr[data-index]').data('index')];
+
+                    row[column.field] = params.submitValue;
+                });
         });
+        this.trigger('editable-init');
     };
 
 }(jQuery);

+ 0 - 1
src/locale/README.md

@@ -94,7 +94,6 @@ hi-IN
 hr-BA
 hr-HR
 hsb-DE
-hu-HU
 hy-AM
 id-ID
 ig-NG

+ 4 - 3
src/locale/bootstrap-table-fr-FR.js

@@ -1,19 +1,20 @@
 /**
  * Bootstrap Table French (France) translation
  * Author: Dennis Hernández (http://djhvscf.github.io/Blog/)
+ * Modification: Tidalf (https://github.com/TidalfFR)
  */
 (function ($) {
     'use strict';
 
     $.extend($.fn.bootstrapTable.defaults, {
         formatLoadingMessage: function () {
-            return 'Chargement en cours, s´il vous plaît patienter ...';
+            return 'Chargement en cours, patientez, s´il vous plaît ...';
         },
         formatRecordsPerPage: function (pageNumber) {
-            return pageNumber + ' dossiers par page';
+            return pageNumber + ' lignes par page';
         },
         formatShowingRows: function (pageFrom, pageTo, totalRows) {
-            return 'Affichage de ' + pageFrom + ' à ' + pageTo + ' dossiers ' + totalRows + ' dossiers au total';
+            return 'Affichage des lignes ' + pageFrom + ' à ' + pageTo + ' sur ' + totalRows + ' lignes au total';
         },
         formatSearch: function () {
             return 'Rechercher';

+ 34 - 0
src/locale/bootstrap-table-hu-HU.js

@@ -0,0 +1,34 @@
+/**
+ * Bootstrap Table Hungarian translation
+ * Author: Nagy Gergely <info@nagygergely.eu>
+ */
+(function ($) {
+    'use strict';
+
+    $.extend($.fn.bootstrapTable.defaults, {
+        formatLoadingMessage: function () {
+            return 'Betöltés, kérem várjon…';
+        },
+        formatRecordsPerPage: function (pageNumber) {
+            return pageNumber + ' rekord per oldal';
+        },
+        formatShowingRows: function (pageFrom, pageTo, totalRows) {
+            return 'Megjelenítve ' + pageFrom + ' - ' + pageTo + ' / ' + totalRows + ' összesen';
+        },
+        formatSearch: function () {
+            return 'Keresés';
+        },
+        formatNoMatches: function () {
+            return 'Nincs találat';
+        },
+        formatRefresh: function () {
+            return 'Frissítés';
+        },
+        formatToggle: function () {
+            return 'Váltás';
+        },
+        formatColumns: function () {
+            return 'Oszlopok';
+        }
+    });
+})(jQuery);