Browse Source

Merge pull request #67 from wenzhixin/master

Update my repo
Dennis Hernández 10 years ago
parent
commit
8124db796e

+ 12 - 0
CHANGELOG.md

@@ -1,5 +1,17 @@
 ## ChangeLog
 
+### 1.8.2
+
+- [enh] Update bootstrap-table-cookie.js.
+- [enh] Use options for detailView's open/close icons.
+- [enh] Added `refreshOptions` and `gtHiddenColumns` method.
+- [enh] Added `datepicker` option to Filter Control.
+- [bug] Fix #936 Sort carets shouldn't be inline-styled by JS.
+- [bug] Fix table header width bug when setting table to no bordered.
+- [bug] Fix #938, fix #940: Multiple Sort and Hide/Show column.
+- [bug] Fix #970: click and dblclick bug on no-rows table.
+- [bug] Fix #967: unselected column while column sorted display error.
+
 ### 1.8.1
 
 - [enh] Accessing field name in formatter.

+ 14 - 1
docs/_i18n/en/documentation/localizations.md

@@ -82,4 +82,17 @@ And then use JavaScript to switch locale:
 $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['en-US']);
 // $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['zh-CN']);
 // ...
-```
+```
+
+Or use data attributes to set locale for table:
+
+```html
+<table data-toggle="table" data-locale="en-US">
+</table>
+```
+
+Or use JavaScript to set locale for table:
+
+```js
+$('table').bootstrapTable({locale:'en-US'});
+```

+ 20 - 1
docs/_i18n/en/documentation/table-options.md

@@ -489,5 +489,24 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
         Support all custom attributes.
         </td>
     </tr>
-    </tbody>
+     <tr>
+        <td>locale</td>
+        <td>data-locale</td>
+        <td>string</td>
+        <td>undefined</td>
+        <td>
+        Sets the locale to use (i.e. <code>'fr-CA'</code>). Locale files must be pre-loaded.
+        Allows for fallback locales, if loaded, in the following order:<br>
+        <ol>
+        <li>First tries for the locale as specified,</li>
+        <li>Then tries the locale with <code>'_'</code> translated to 
+        <code>'-'</code> and the region code upper cased,</li>
+        <li>Then tries the the short locale code (i.e. <code>'fr'</code> instead of <code>'fr-CA'</code>),</li>
+        <li>And finally will use the last locale file loaded (or the default locale if no locales loaded).</li>
+        </ol>
+        If left undfined or an empty string, uses the last locale loaded (or <code>'en-US'</code>
+        if no locale files loaded).
+        </td>
+    </tr>
+   </tbody>
 </table>

+ 23 - 5
docs/_i18n/en/extensions/cookie.md

@@ -10,23 +10,41 @@ Use Plugin: [bootstrap-table-cookie](https://github.com/wenzhixin/bootstrap-tabl
 
 ## Options
 
-### stateSave
+### cookie
 
 * type: Boolean
 * description: Set true to save the state of a table (its paging position, ordering state, records per page).
 * default: `false`
 
-### stateSaveExpire
+### cookieExpire
 
 * type: String
-* description: You must set this property if stateSave is enable to know when will expire the cookie created. Must use this format: 'number{letter}' like '2h', in the letter position
+* description: You must set this property if cookie option is enable to know when will expire the cookie created. Must use this format: 'number{letter}' like '2h', in the letter position
                		you can use: 's','mi','h','d','m','y', these means: 'seconds', 'minutes', 'hours', 'days', 'months', 'years'.
 * default: `2h`
 
-### stateSaveIdTable
+### cookiePath
 
 * type: String
-* description: You must set this property if stateSave is enable to sets an unique cookie with an identifier for each table in your page or project. You must set this property because we need create cookies with an identifier.
+* description: you can tell the browser what path the cookie belongs to. By default, the cookie belongs to the current page.
+* default: `null`
+
+### cookieDomain
+
+* type: String
+* description: This is the website domain, with the www. prefix removed.
+* default: `null`
+
+### cookieSecure
+
+* type: Boolean
+* description: This property keeps cookie communication limited to encrypted transmission, directing browsers to use cookies only via secure/encrypted connections.
+* default: `null`
+
+### cookieIdTable
+
+* type: String
+* description: You must set this property if the cookie property is enabled to set an unique cookie with an identifier for each table in your page or project. You must set this property because we need create cookies with an identifier.
 * default: ``
 
 ## This plugin saves

+ 6 - 0
docs/_i18n/en/extensions/export.md

@@ -16,6 +16,12 @@ Use Plugin: [tableExport.jquery.plugin](https://github.com/hhurz/tableExport.jqu
 * description: set `true` to show export button.
 * default: `false`
 
+### exportDataType
+
+* type: String
+* description: export data type, support: 'basic', 'all', 'selected'.
+* default: `basic`
+
 ### exportTypes
 
 * type: Array

+ 2 - 2
docs/_i18n/en/extensions/filter-control.md

@@ -1,6 +1,6 @@
 # Table Filter Control
 
-Use Plugin: [bootstrap-table-filter-control](https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/filter-control)
+Use Plugin: [bootstrap-table-filter-control](https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/filter-control) </br>
 Dependence if you use the datepicker option: [bootstrap-datepicker](https://github.com/eternicode/bootstrap-datepicker) v1.4.0
 
 ## Usage
@@ -22,7 +22,7 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith
 ### filterControl
 
 * type: String
-* description: Set `input`: show an input control, `select`: show a select control, 'datepicker': show a datepicker control.
+* description: Set `input`: show an input control, `select`: show a select control, `datepicker`: show a datepicker control.
 * default: `undefined`
 
 ### filterDatepickerOptions

+ 6 - 0
docs/_i18n/en/extensions/flat-json.md

@@ -15,3 +15,9 @@ Use Plugin: [bootstrap-table-flat-json](https://github.com/djhvscf/bootstrap-tab
 * type: Boolean
 * description: Set true to flat the JSON object.
 * default: `false`
+
+### flatSeparator
+
+* type: String
+* description: Set the default separator between object levels.
+* default: `.`

+ 6 - 0
docs/_i18n/en/extensions/reorder-columns.md

@@ -28,6 +28,12 @@ Dependence: [dragTable](https://github.com/akottr/dragtable/) v2.0.14 (must incl
 * description: Moving only the header. Recommended for very large tables (cells > 1000)
 * default: `10`
 
+### dragaccept
+
+* type: String
+* description: Allow to drag only the rows that have the css class as attribute.
+* default: `null`
+
 ## Events
 
 ### onReorderColumn(reorder-column.bs.table)

+ 23 - 5
docs/_i18n/es/extensions/cookie.md

@@ -10,23 +10,41 @@ Use Plugin: [bootstrap-table-cookie](https://github.com/wenzhixin/bootstrap-tabl
 
 ## Options
 
-### stateSave
+### cookie
 
 * type: Boolean
 * description: Set true to save the state of a table (its paging position, ordering state, records per page).
 * default: `false`
 
-### stateSaveExpire
+### cookieExpire
 
 * type: String
-* description: You must set this property if stateSave is enable to know when will expire the cookie created. Must use this format: 'number{letter}' like '2h', in the letter position
+* description: You must set this property if cookie option is enable to know when will expire the cookie created. Must use this format: 'number{letter}' like '2h', in the letter position
                		you can use: 's','mi','h','d','m','y', these means: 'seconds', 'minutes', 'hours', 'days', 'months', 'years'.
 * default: `2h`
 
-### stateSaveIdTable
+### cookiePath
 
 * type: String
-* description: You must set this property if stateSave is enable to sets an unique cookie with an identifier for each table in your page or project. You must set this property because we need create cookies with an identifier.
+* description: you can tell the browser what path the cookie belongs to. By default, the cookie belongs to the current page.
+* default: `null`
+
+### cookieDomain
+
+* type: String
+* description: This is the website domain, with the www. prefix removed.
+* default: `null`
+
+### cookieSecure
+
+* type: Boolean
+* description: This property keeps cookie communication limited to encrypted transmission, directing browsers to use cookies only via secure/encrypted connections.
+* default: `null`
+
+### cookieIdTable
+
+* type: String
+* description: You must set this property if the cookie property is enabled to set an unique cookie with an identifier for each table in your page or project. You must set this property because we need create cookies with an identifier.
 * default: ``
 
 ## This plugin saves

+ 6 - 0
docs/_i18n/es/extensions/export.md

@@ -16,6 +16,12 @@ Use Plugin: [tableExport.jquery.plugin](https://github.com/hhurz/tableExport.jqu
 * description: set `true` to show export button.
 * default: `false`
 
+### exportDataType
+
+* type: String
+* description: export data type, support: 'basic', 'all', 'selected'.
+* default: `basic`
+
 ### exportTypes
 
 * type: Array

+ 2 - 2
docs/_i18n/es/extensions/filter-control.md

@@ -1,6 +1,6 @@
 # Table Filter Control
 
-Use Plugin: [bootstrap-table-filter-control](https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/filter-control)
+Use Plugin: [bootstrap-table-filter-control](https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/filter-control) </br>
 Dependence if you use the datepicker option: [bootstrap-datepicker](https://github.com/eternicode/bootstrap-datepicker) v1.4.0
 
 ## Usage
@@ -22,7 +22,7 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith
 ### filterControl
 
 * type: String
-* description: Set `input`: show an input control, `select`: show a select control, 'datepicker': show a datepicker control.
+* description: Set `input`: show an input control, `select`: show a select control, `datepicker`: show a datepicker control.
 * default: `undefined`
 
 ### filterDatepickerOptions

+ 6 - 0
docs/_i18n/es/extensions/flat-json.md

@@ -15,3 +15,9 @@ Use Plugin: [bootstrap-table-flat-json](https://github.com/djhvscf/bootstrap-tab
 * type: Boolean
 * description: Set true to flat the JSON object.
 * default: `false`
+
+### flatSeparator
+
+* type: String
+* description: Set the default separator between object levels.
+* default: `.`

+ 6 - 0
docs/_i18n/es/extensions/reorder-columns.md

@@ -28,6 +28,12 @@ Dependence: [dragTable](https://github.com/akottr/dragtable/) v2.0.14 (must incl
 * description: Moving only the header. Recommended for very large tables (cells > 1000)
 * default: `10`
 
+### dragaccept
+
+* type: String
+* description: Allow to drag only the rows that have the css class as attribute.
+* default: `null`
+
 ## Events
 
 ### onReorderColumn(reorder-column.bs.table)

+ 23 - 5
docs/_i18n/zh-cn/extensions/cookie.md

@@ -10,23 +10,41 @@ Use Plugin: [bootstrap-table-cookie](https://github.com/wenzhixin/bootstrap-tabl
 
 ## Options
 
-### stateSave
+### cookie
 
 * type: Boolean
 * description: Set true to save the state of a table (its paging position, ordering state, records per page).
 * default: `false`
 
-### stateSaveExpire
+### cookieExpire
 
 * type: String
-* description: You must set this property if stateSave is enable to know when will expire the cookie created. Must use this format: 'number{letter}' like '2h', in the letter position
+* description: You must set this property if cookie option is enable to know when will expire the cookie created. Must use this format: 'number{letter}' like '2h', in the letter position
                		you can use: 's','mi','h','d','m','y', these means: 'seconds', 'minutes', 'hours', 'days', 'months', 'years'.
 * default: `2h`
 
-### stateSaveIdTable
+### cookiePath
 
 * type: String
-* description: You must set this property if stateSave is enable to sets an unique cookie with an identifier for each table in your page or project. You must set this property because we need create cookies with an identifier.
+* description: you can tell the browser what path the cookie belongs to. By default, the cookie belongs to the current page.
+* default: `null`
+
+### cookieDomain
+
+* type: String
+* description: This is the website domain, with the www. prefix removed.
+* default: `null`
+
+### cookieSecure
+
+* type: Boolean
+* description: This property keeps cookie communication limited to encrypted transmission, directing browsers to use cookies only via secure/encrypted connections.
+* default: `null`
+
+### cookieIdTable
+
+* type: String
+* description: You must set this property if the cookie property is enabled to set an unique cookie with an identifier for each table in your page or project. You must set this property because we need create cookies with an identifier.
 * default: ``
 
 ## This plugin saves

+ 6 - 0
docs/_i18n/zh-cn/extensions/export.md

@@ -16,6 +16,12 @@ Use Plugin: [tableExport.jquery.plugin](https://github.com/hhurz/tableExport.jqu
 * description: set `true` to show export button.
 * default: `false`
 
+### exportDataType
+
+* type: String
+* description: export data type, support: 'basic', 'all', 'selected'.
+* default: `basic`
+
 ### exportTypes
 
 * type: Array

+ 2 - 2
docs/_i18n/zh-cn/extensions/filter-control.md

@@ -1,6 +1,6 @@
 # Table Filter Control
 
-Use Plugin: [bootstrap-table-filter-control](https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/filter-control)
+Use Plugin: [bootstrap-table-filter-control](https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/filter-control) </br>
 Dependence if you use the datepicker option: [bootstrap-datepicker](https://github.com/eternicode/bootstrap-datepicker) v1.4.0
 
 ## Usage
@@ -22,7 +22,7 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith
 ### filterControl
 
 * type: String
-* description: Set `input`: show an input control, `select`: show a select control, 'datepicker': show a datepicker control.
+* description: Set `input`: show an input control, `select`: show a select control, `datepicker`: show a datepicker control.
 * default: `undefined`
 
 ### filterDatepickerOptions

+ 6 - 0
docs/_i18n/zh-cn/extensions/flat-json.md

@@ -15,3 +15,9 @@ Use Plugin: [bootstrap-table-flat-json](https://github.com/djhvscf/bootstrap-tab
 * type: Boolean
 * description: Set true to flat the JSON object.
 * default: `false`
+
+### flatSeparator
+
+* type: String
+* description: Set the default separator between object levels.
+* default: `.`

+ 6 - 0
docs/_i18n/zh-cn/extensions/reorder-columns.md

@@ -28,6 +28,12 @@ Dependence: [dragTable](https://github.com/akottr/dragtable/) v2.0.14 (must incl
 * description: Moving only the header. Recommended for very large tables (cells > 1000)
 * default: `10`
 
+### dragaccept
+
+* type: String
+* description: Allow to drag only the rows that have the css class as attribute.
+* default: `null`
+
 ## Events
 
 ### onReorderColumn(reorder-column.bs.table)

+ 36 - 9
src/bootstrap-table.js

@@ -185,6 +185,7 @@
 
     BootstrapTable.DEFAULTS = {
         classes: 'table table-hover',
+        locale: undefined,
         height: undefined,
         undefinedText: '-',
         sortName: undefined,
@@ -347,7 +348,7 @@
 
     BootstrapTable.LOCALES = [];
 
-    BootstrapTable.LOCALES['en-US'] = {
+    BootstrapTable.LOCALES['en-US'] = BootstrapTable.LOCALES['en'] = {
         formatLoadingMessage: function () {
             return 'Loading, please wait...';
         },
@@ -439,6 +440,7 @@
     };
 
     BootstrapTable.prototype.init = function () {
+        this.initLocale();
         this.initContainer();
         this.initTable();
         this.initHeader();
@@ -450,6 +452,24 @@
         this.initServer();
     };
 
+    BootstrapTable.prototype.initLocale = function () {
+        if (this.options.locale) {
+            var parts = this.options.locale.split(/-|_/);
+            parts[0].toLowerCase();
+            parts[1] && parts[1].toUpperCase();
+            if ($.fn.bootstrapTable.locales[this.options.locale]) {
+                // locale as requested
+                $.extend(this.options, $.fn.bootstrapTable.locales[this.options.locale]);
+            } else if ($.fn.bootstrapTable.locales[parts.join('-')]) {
+                // locale with sep set to - (in case original was specified with _)
+                $.extend(this.options, $.fn.bootstrapTable.locales[parts.join('-')]);
+            } else if ($.fn.bootstrapTable.locales[parts[0]]) {
+                // short locale language code (i.e. 'en')
+                $.extend(this.options, $.fn.bootstrapTable.locales[parts[0]]);
+            }
+        }
+    };
+    
     BootstrapTable.prototype.initContainer = function () {
         this.$container = $([
             '<div class="bootstrap-table">',
@@ -1035,10 +1055,11 @@
                 this.options.pageSize = this.options.totalRows;
                 $allSelected = true;
             } else if (this.options.pageSize === this.options.totalRows) {
-                // Fix #667 Table with pagination, multiple pages and a search that matches to one page throws exception
+                // Fix #667 Table with pagination,
+                // multiple pages and a search that matches to one page throws exception
                 var pageLst = typeof this.options.pageList === 'string' ?
-                    this.options.pageList.replace('[', '').replace(']', '').replace(/ /g, '').toLowerCase().split(',') :
-                    this.options.pageList;
+                    this.options.pageList.replace('[', '').replace(']', '')
+                        .replace(/ /g, '').toLowerCase().split(',') : this.options.pageList;
                 if (pageLst.indexOf(this.options.formatAllRows().toLowerCase()) > -1) {
                     $allSelected = true;
                 }
@@ -1067,9 +1088,12 @@
         html.push('<span class="page-list">');
 
         var pageNumber = [
-                sprintf('<span class="btn-group %s">', this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
+                sprintf('<span class="btn-group %s">',
+                    this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
                     'dropdown' : 'dropup'),
-                '<button type="button" class="btn btn-default ' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">',
+                '<button type="button" class="btn btn-default ' +
+                    (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) +
+                    ' dropdown-toggle" data-toggle="dropdown">',
                 '<span class="page-size">',
                 $allSelected ? this.options.formatAllRows() : this.options.pageSize,
                 '</span>',
@@ -1080,7 +1104,8 @@
             pageList = this.options.pageList;
 
         if (typeof this.options.pageList === 'string') {
-            var list = this.options.pageList.replace('[', '').replace(']', '').replace(/ /g, '').split(',');
+            var list = this.options.pageList.replace('[', '').replace(']', '')
+                .replace(/ /g, '').split(',');
 
             pageList = [];
             $.each(list, function (i, value) {
@@ -1449,8 +1474,10 @@
             // if click to select - then trigger the checkbox/radio click
             if (e.type === 'click' && that.options.clickToSelect) {
                 if (that.header.clickToSelects[$tr.children().index($(this))]) {
-                    $tr.find(sprintf('[name="%s"]',
-                        that.options.selectItemName))[0].click(); // #144: .trigger('click') bug
+                    var $selectItem = $tr.find(sprintf('[name="%s"]', that.options.selectItemName));
+                    if ($selectItem.length) {
+                        $selectItem[0].click(); // #144: .trigger('click') bug
+                    }
                 }
             }
         });

+ 6 - 0
src/extensions/export/README.md

@@ -16,6 +16,12 @@ Use Plugin: [tableExport.jquery.plugin](https://github.com/hhurz/tableExport.jqu
 * description: set `true` to show export button.
 * default: `false`
 
+### exportDataType
+
+* type: String
+* description: export data type, support: 'basic', 'all', 'selected'.
+* default: `basic`
+
 ### exportTypes
 
 * type: Array

+ 23 - 4
src/extensions/export/bootstrap-table-export.js

@@ -21,6 +21,7 @@
 
     $.extend($.fn.bootstrapTable.defaults, {
         showExport: false,
+        exportDataType: 'basic', // basic, all, selected
         // 'json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'powerpoint', 'pdf'
         exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
         exportOptions: {}
@@ -73,10 +74,28 @@
                 });
 
                 $menu.find('li').click(function () {
-                    that.$el.tableExport($.extend({}, that.options.exportOptions, {
-                        type: $(this).data('type'),
-                        escape: false
-                    }));
+                    var type = $(this).data('type'),
+                        doExport = function () {
+                            that.$el.tableExport($.extend({}, that.options.exportOptions, {
+                                type: type,
+                                escape: false
+                            }));
+                        };
+
+                    if (that.options.exportDataType === 'all' && that.options.pagination) {
+                        that.togglePagination();
+                        doExport();
+                        that.togglePagination();
+                    } else if (that.options.exportDataType === 'selected') {
+                        var data = that.getData(),
+                            selectedData = that.getAllSelections();
+
+                        that.load(selectedData);
+                        doExport();
+                        that.load(data);
+                    } else {
+                        doExport();
+                    }
                 });
             }
         }

+ 27 - 5
src/extensions/mobile/bootstrap-table-mobile.js

@@ -53,10 +53,24 @@
         that.toggleView();
     };
 
+    var debounce = function(func,wait) {
+        var timeout;
+        return function() {
+            var context = this, args = arguments;
+            var later = function() {
+                timeout = null;
+                func.apply(context,args);
+            };
+            clearTimeout(timeout);
+            timeout = setTimeout(later,wait);
+        };
+    };
+
     $.extend($.fn.bootstrapTable.defaults, {
         mobileResponsive: false,
         minWidth: 562,
         minHeight: undefined,
+        heightThreshold: 100, // just slightly larger than mobile chrome's auto-hiding toolbar
         checkOnInit: true,
         toggled: false
     });
@@ -75,13 +89,21 @@
             return;
         }
 
-        var that = this;
-        $(window).resize(function () {
-            changeView(that, $(this).width(), $(this).height())
-        });
+        var that = this, old = { w: $(window).width(), h: $(window).height() };
+
+        $(window).on('resize orientationchange',debounce(function (evt) {
+            // reset view if height has only changed by at least the threshold.
+            var h = $(this).height(), w = $(this).width();
+            if (Math.abs(old.h - h) > that.options.heightThreshold || old.w != w) {
+                changeView(that, w, h);
+                old = { w: w, h: h };
+            }
+        },200));
 
         if (this.options.checkOnInit) {
-            changeView(this, $(window).width(), $(window).height());
+            var h = $(window).height(), w = $(window).width();
+            changeView(this, w, h);
+            old = { w: w, h: h };
         }
     };
 }(jQuery);

+ 3 - 3
src/extensions/multiple-sort/bootstrap-table-multiple-sort.js

@@ -220,8 +220,8 @@
         _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
 
         if (this.options.showMultiSort) {
-            var $btnGroup = this.$toolbar.find('>.btn-group'),
-                $multiSortBtn = $btnGroup.find('div.multi-sort');
+            var $btnGroup = this.$toolbar.find('>.btn-group').first(),
+                $multiSortBtn = this.$toolbar.find('div.multi-sort');
 
             if (!$multiSortBtn.length) {
                 $multiSortBtn = '  <button class="multi-sort btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" data-toggle="modal" data-target="' + sortModalId + '" title="' + this.options.formatMultipleSort() + '">';
@@ -375,4 +375,4 @@
             this.$sortModal.find('#delete').attr('disabled', 'disabled');
         }
     };
-})(jQuery);
+})(jQuery);