ソースを参照

Merge pull request #2106 from djhvscf/develop

Added some fixes. See description
wenzhixin 9 年 前
コミット
ccfabbe11f

+ 10 - 2
docs/_i18n/en/documentation/events.md

@@ -48,7 +48,8 @@ $('#table').on('event-name.bs.table', function (e, arg1, arg2, ...) {
         <td>
         <td>
         Fires when user click a row, the parameters contain: <br>
         Fires when user click a row, the parameters contain: <br>
         row: the record corresponding to the clicked row, <br>
         row: the record corresponding to the clicked row, <br>
-        $element: the tr element.
+        $element: the tr element, <br>
+        field: the field name corresponding to the clicked cell.
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>
@@ -58,7 +59,8 @@ $('#table').on('event-name.bs.table', function (e, arg1, arg2, ...) {
         <td>
         <td>
         Fires when user double click a row, the parameters contain: <br>
         Fires when user double click a row, the parameters contain: <br>
         row: the record corresponding to the clicked row, <br>
         row: the record corresponding to the clicked row, <br>
-        $element: the tr element.
+        $element: the tr element, <br>
+        field: the field name corresponding to the clicked cell.
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>
@@ -237,5 +239,11 @@ $('#table').on('event-name.bs.table', function (e, arg1, arg2, ...) {
         <td></td>
         <td></td>
         <td>Fires when reset view of the table.</td>
         <td>Fires when reset view of the table.</td>
     </tr>
     </tr>
+    <tr>
+       <td>onRefresh</td>
+       <td>refresh.bs.table</td>
+       <td>params</td>
+       <td>Fires after the click the refresh button.</td>
+    </tr>
     </tbody>
     </tbody>
 </table>
 </table>

+ 11 - 3
docs/_i18n/es/documentation/events.md

@@ -33,7 +33,8 @@
         <td>
         <td>
         Se ejecuta cuando el usuario le da click a una fila, los parámetros contienen: <br>
         Se ejecuta cuando el usuario le da click a una fila, los parámetros contienen: <br>
         row: el registro que corresponde con la fila a la que se le dio click, <br>
         row: el registro que corresponde con la fila a la que se le dio click, <br>
-        $element: el elemento tr.
+        $element: el elemento tr, <br>
+        field: el nombre del campo correspondiente a la celda hecho clic.
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>
@@ -43,7 +44,8 @@
         <td>
         <td>
         Se ejecuta cuando el usuario le da click a una fila, los parámetros contienen: <br>
         Se ejecuta cuando el usuario le da click a una fila, los parámetros contienen: <br>
         row: el registro que corresponde con la fila a la que se le dio click, <br>
         row: el registro que corresponde con la fila a la que se le dio click, <br>
-        $element: el elemento tr.
+        $element: el elemento tr, <br>
+        field: el nombre del campo correspondiente a la celda hecho clic.
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>
@@ -202,7 +204,13 @@
        <td>onRefreshOptions</td>
        <td>onRefreshOptions</td>
        <td>refresh-options.bs.table</td>
        <td>refresh-options.bs.table</td>
        <td>options</td>
        <td>options</td>
-       <td>Se ejecuta cuando se actualiza el objeto options, este método se ejecuta antes de los eventos destroy e init</td>
+       <td>Se ejecuta cuando se actualiza el objeto options, este método se ejecuta antes de los eventos destroy e init.</td>
+    </tr>
+    <tr>
+       <td>onRefresh</td>
+       <td>refresh.bs.table</td>
+       <td>params</td>
+       <td>Se ejecuta cuando se cliquea el botón de refresh.</td>
     </tr>
     </tr>
     </tbody>
     </tbody>
 </table>
 </table>

+ 11 - 3
docs/_i18n/zh-cn/documentation/events.md

@@ -34,7 +34,8 @@
         <td>
         <td>
         当用户点击某一行的时候触发,参数包括:<br>
         当用户点击某一行的时候触发,参数包括:<br>
         row:点击行的数据,<br>
         row:点击行的数据,<br>
-        $element:tr 元素。
+        $element:tr 元素,<br>
+        field:点击列的 field 名称。
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>
@@ -44,7 +45,8 @@
         <td>
         <td>
         当用户双击某一行的时候触发,参数包括:<br>
         当用户双击某一行的时候触发,参数包括:<br>
         row:点击行的数据,<br>
         row:点击行的数据,<br>
-        $element:tr 元素。
+        $element:tr 元素,<br>
+        field:点击列的 field 名称。
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>
@@ -215,7 +217,13 @@
        <td>onRefreshOptions</td>
        <td>onRefreshOptions</td>
        <td>refresh-options.bs.table</td>
        <td>refresh-options.bs.table</td>
        <td>options</td>
        <td>options</td>
-       <td>Fires after refresh the options and before destroy and init the table</td>
+       <td>Fires after refresh the options and before destroy and init the table.</td>
+    </tr>
+    <tr>
+       <td>onRefresh</td>
+       <td>refresh.bs.table</td>
+       <td>params</td>
+       <td>Fires after the click the refresh button.</td>
     </tr>
     </tr>
     </tbody>
     </tbody>
 </table>
 </table>

+ 32 - 10
src/bootstrap-table.js

@@ -465,6 +465,9 @@
         onRefreshOptions: function (options) {
         onRefreshOptions: function (options) {
             return false;
             return false;
         },
         },
+        onRefresh: function (params) {
+          return false;
+        },
         onResetView: function () {
         onResetView: function () {
             return false;
             return false;
         }
         }
@@ -564,7 +567,8 @@
         'expand-row.bs.table': 'onExpandRow',
         'expand-row.bs.table': 'onExpandRow',
         'collapse-row.bs.table': 'onCollapseRow',
         'collapse-row.bs.table': 'onCollapseRow',
         'refresh-options.bs.table': 'onRefreshOptions',
         'refresh-options.bs.table': 'onRefreshOptions',
-        'reset-view.bs.table': 'onResetView'
+        'reset-view.bs.table': 'onResetView',
+        'refresh.bs.table': 'onRefresh'
     };
     };
 
 
     BootstrapTable.prototype.init = function () {
     BootstrapTable.prototype.init = function () {
@@ -693,7 +697,7 @@
             return;
             return;
         }
         }
 
 
-        this.fromHtml = true;
+        this.fromHtml = this.options.sidePagination === 'client';
         var m = [];
         var m = [];
         this.$el.find('>tbody>tr').each(function (y) {
         this.$el.find('>tbody>tr').each(function (y) {
             var row = {};
             var row = {};
@@ -1171,6 +1175,10 @@
                     }
                     }
                 }
                 }
 
 
+                if ($.inArray(event.keyCode, [37, 38, 39, 40]) > -1) {
+                    return;
+                }
+
                 clearTimeout(timeoutId); // doesn't matter if it's 0
                 clearTimeout(timeoutId); // doesn't matter if it's 0
                 timeoutId = setTimeout(function () {
                 timeoutId = setTimeout(function () {
                     that.onSearch(event);
                     that.onSearch(event);
@@ -1216,7 +1224,9 @@
                 this.options.customSearch.apply(this, [this.searchText]);
                 this.options.customSearch.apply(this, [this.searchText]);
                 return;
                 return;
             }
             }
-            var s = this.searchText && this.searchText.toLowerCase();
+
+            var s = !this.options.escape ? this.searchText && escapeHTML(this.searchText).toLowerCase()
+                                            : this.searchText && this.searchText.toLowerCase();
             var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
             var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
 
 
             // Check filter
             // Check filter
@@ -1785,7 +1795,7 @@
             }
             }
 
 
             that.trigger(e.type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td);
             that.trigger(e.type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td);
-            that.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr);
+            that.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr, field);
 
 
             // if click to select - then trigger the checkbox/radio click
             // if click to select - then trigger the checkbox/radio click
             if (e.type === 'click' && that.options.clickToSelect && column.clickToSelect) {
             if (e.type === 'click' && that.options.clickToSelect && column.clickToSelect) {
@@ -1903,6 +1913,8 @@
             params.pageSize = this.options.pageSize === this.options.formatAllRows() ?
             params.pageSize = this.options.pageSize === this.options.formatAllRows() ?
                 this.options.totalRows : this.options.pageSize;
                 this.options.totalRows : this.options.pageSize;
             params.pageNumber = this.options.pageNumber;
             params.pageNumber = this.options.pageNumber;
+        } else {
+            params.pageSize = this.options.totalRows;
         }
         }
 
 
         if (!this.options.url && !this.options.ajax) {
         if (!this.options.url && !this.options.ajax) {
@@ -1915,11 +1927,14 @@
                 sort: params.sortName,
                 sort: params.sortName,
                 order: params.sortOrder
                 order: params.sortOrder
             };
             };
+            params.offset = this.options.pageSize === this.options.formatAllRows() ?
+                0 : this.options.pageSize * (this.options.pageNumber - 1);
+
             if (this.options.pagination) {
             if (this.options.pagination) {
                 params.limit = this.options.pageSize === this.options.formatAllRows() ?
                 params.limit = this.options.pageSize === this.options.formatAllRows() ?
                     this.options.totalRows : this.options.pageSize;
                     this.options.totalRows : this.options.pageSize;
-                params.offset = this.options.pageSize === this.options.formatAllRows() ?
-                    0 : this.options.pageSize * (this.options.pageNumber - 1);
+            } else {
+                params.limit = this.options.totalRows;
             }
             }
         }
         }
 
 
@@ -2088,7 +2103,8 @@
             that.$header_.find(sprintf('th[data-field="%s"]', $(this).data('field'))).data($(this).data());
             that.$header_.find(sprintf('th[data-field="%s"]', $(this).data('field'))).data($(this).data());
         });
         });
 
 
-        var visibleFields = this.getVisibleFields();
+        var visibleFields = this.getVisibleFields(),
+            $ths = this.$header_.find('th');
 
 
         this.$body.find('>tr:first-child:not(.no-records-found) > *').each(function (i) {
         this.$body.find('>tr:first-child:not(.no-records-found) > *').each(function (i) {
             var $this = $(this),
             var $this = $(this),
@@ -2101,8 +2117,12 @@
                 index = i - 1;
                 index = i - 1;
             }
             }
 
 
-            that.$header_.find(sprintf('th[data-field="%s"]', visibleFields[index]))
-                .find('.fht-cell').width($this.innerWidth());
+            var $th = that.$header_.find(sprintf('th[data-field="%s"]', visibleFields[index]));
+            if ($th.length > 1) {
+                $th = $($ths[$this[0].cellIndex]);
+            }
+
+            $th.find('.fht-cell').width($this.innerWidth());
         });
         });
         // horizontal scroll event
         // horizontal scroll event
         // TODO: it's probably better improving the layout than binding to scroll event
         // TODO: it's probably better improving the layout than binding to scroll event
@@ -2680,6 +2700,7 @@
             this.options.pageNumber = 1;
             this.options.pageNumber = 1;
         }
         }
         this.initServer(params && params.silent, params && params.query);
         this.initServer(params && params.silent, params && params.query);
+        this.trigger('refresh', params);
     };
     };
 
 
     BootstrapTable.prototype.resetWidth = function () {
     BootstrapTable.prototype.resetWidth = function () {
@@ -2963,7 +2984,8 @@
         compareObjects: compareObjects,
         compareObjects: compareObjects,
         calculateObjectValue: calculateObjectValue,
         calculateObjectValue: calculateObjectValue,
         getItemField: getItemField,
         getItemField: getItemField,
-        objectKeys: objectKeys
+        objectKeys: objectKeys,
+        isIEBrowser: isIEBrowser
     };
     };
 
 
     // BOOTSTRAP TABLE INIT
     // BOOTSTRAP TABLE INIT

+ 6 - 1
src/extensions/cookie/bootstrap-table-cookie.js

@@ -1,7 +1,7 @@
 /**
 /**
  * @author: Dennis Hernández
  * @author: Dennis Hernández
  * @webSite: http://djhvscf.github.io/Blog
  * @webSite: http://djhvscf.github.io/Blog
- * @version: v1.2.0
+ * @version: v1.2.1
  *
  *
  * @update zhixin wen <wenzhixin2010@gmail.com>
  * @update zhixin wen <wenzhixin2010@gmail.com>
  */
  */
@@ -219,6 +219,11 @@
             });
             });
         }
         }
         _init.apply(this, Array.prototype.slice.apply(arguments));
         _init.apply(this, Array.prototype.slice.apply(arguments));
+
+        $.extend($.fn.bootstrapTable.utils, {
+            setCookie: setCookie,
+            getCookie: getCookie
+        });
     };
     };
 
 
     BootstrapTable.prototype.initTable = function () {
     BootstrapTable.prototype.initTable = function () {

+ 1 - 1
src/extensions/cookie/extension.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "Cookie",
   "name": "Cookie",
-  "version": "1.2.0",
+  "version": "1.2.1",
   "description": "Plugin to use the cookie of the browser.",
   "description": "Plugin to use the cookie of the browser.",
   "url": "https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/cookie",
   "url": "https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/cookie",
   "example": "http://issues.wenzhixin.net.cn/bootstrap-table/#extensions/cookie.html",
   "example": "http://issues.wenzhixin.net.cn/bootstrap-table/#extensions/cookie.html",

+ 1 - 1
src/extensions/export/bootstrap-table-export.js

@@ -91,7 +91,7 @@
                         };
                         };
 
 
                     if (that.options.exportDataType === 'all' && that.options.pagination) {
                     if (that.options.exportDataType === 'all' && that.options.pagination) {
-                        that.$el.one('load-success.bs.table page-change.bs.table', function () {
+                        that.$el.one(that.options.sidePagination === 'server' ? 'post-body.bs.table' : 'page-change.bs.table', function () {
                             doExport();
                             doExport();
                             that.togglePagination();
                             that.togglePagination();
                         });
                         });

+ 55 - 12
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -1,7 +1,7 @@
 /**
 /**
  * @author: Dennis Hernández
  * @author: Dennis Hernández
  * @webSite: http://djhvscf.github.io/Blog
  * @webSite: http://djhvscf.github.io/Blog
- * @version: v2.0.0
+ * @version: v2.1.0
  */
  */
 
 
 !function ($) {
 !function ($) {
@@ -72,6 +72,38 @@
         return searchControls;
         return searchControls;
     };
     };
 
 
+    var getCursorPosition = function(el) {
+        if ($.fn.bootstrapTable.utils.isIEBrowser()) {
+            if ($(el).is('input')) {
+                var pos = 0;
+                if ('selectionStart' in el) {
+                    pos = el.selectionStart;
+                } else if ('selection' in document) {
+                    el.focus();
+                    var Sel = document.selection.createRange();
+                    var SelLength = document.selection.createRange().text.length;
+                    Sel.moveStart('character', -el.value.length);
+                    pos = Sel.text.length - SelLength;
+                }
+                return pos;
+            } else {
+                return -1;
+            }
+        } else {
+            return -1;
+        }
+    };
+
+    var setCursorPosition = function (el, index) {
+        if ($.fn.bootstrapTable.utils.isIEBrowser()) {
+            if(el.setSelectionRange !== undefined) {
+                el.setSelectionRange(index, index);
+            } else {
+                $(el).val(el.value);
+            }
+        }
+    };
+
     var copyValues = function (that) {
     var copyValues = function (that) {
         var header = getCurrentHeader(that),
         var header = getCurrentHeader(that),
             searchControls = getCurrentSearchControls(that);
             searchControls = getCurrentSearchControls(that);
@@ -82,7 +114,8 @@
             that.options.valuesFilterControl.push(
             that.options.valuesFilterControl.push(
                 {
                 {
                     field: $(this).closest('[data-field]').data('field'),
                     field: $(this).closest('[data-field]').data('field'),
-                    value: $(this).val()
+                    value: $(this).val(),
+                    position: getCursorPosition($(this).get(0))
                 });
                 });
         });
         });
     };
     };
@@ -102,6 +135,7 @@
 
 
                 if (result.length > 0) {
                 if (result.length > 0) {
                     $(this).val(result[0].value);
                     $(this).val(result[0].value);
+                    setCursorPosition($(this).get(0), result[0].position);
                 }
                 }
             });
             });
         }
         }
@@ -125,9 +159,9 @@
         }
         }
     };
     };
 
 
-    var initFilterSelectControls = function (bootstrapTable) {
-        var data = bootstrapTable.options.data,
-            itemsPerPage = bootstrapTable.pageTo < bootstrapTable.options.data.length ? bootstrapTable.options.data.length : bootstrapTable.pageTo,
+    var initFilterSelectControls = function (that) {
+        var data = that.options.data,
+            itemsPerPage = that.pageTo < that.options.data.length ? that.options.data.length : that.pageTo,
 
 
             isColumnSearchableViaSelect = function (column) {
             isColumnSearchableViaSelect = function (column) {
                 return column.filterControl && column.filterControl.toLowerCase() === 'select' && column.searchable;
                 return column.filterControl && column.filterControl.toLowerCase() === 'select' && column.searchable;
@@ -141,10 +175,15 @@
                 return selectControl && selectControl.length > 0;
                 return selectControl && selectControl.length > 0;
             };
             };
 
 
-        for (var i = bootstrapTable.pageFrom - 1; i < bootstrapTable.pageTo; i++) {
+        var z = that.options.pagination
+                ? (that.options.sidePagination === 'server'
+                    ? that.pageTo
+                    : that.options.totalRows)
+                : that.pageTo;
 
 
-            $.each(bootstrapTable.header.fields, function (j, field) {
-                var column = bootstrapTable.columns[$.fn.bootstrapTable.utils.getFieldIndex(bootstrapTable.columns, field)],
+        for (var i = 0; i < z; i++) {
+            $.each(that.header.fields, function (j, field) {
+                var column = that.columns[$.fn.bootstrapTable.utils.getFieldIndex(that.columns, field)],
                     selectControl = $('.' + column.field);
                     selectControl = $('.' + column.field);
 
 
 
 
@@ -156,7 +195,7 @@
 
 
                     //Added a new value
                     //Added a new value
                     var fieldValue = data[i][field],
                     var fieldValue = data[i][field],
-                        formattedValue = $.fn.bootstrapTable.utils.calculateObjectValue(bootstrapTable.header, bootstrapTable.header.formatters[j], [fieldValue, data[i], i], fieldValue);
+                        formattedValue = $.fn.bootstrapTable.utils.calculateObjectValue(that.header, that.header.formatters[j], [fieldValue, data[i], i], fieldValue);
 
 
                     addOptionToSelectControl(selectControl, fieldValue, formattedValue);
                     addOptionToSelectControl(selectControl, fieldValue, formattedValue);
                 }
                 }
@@ -325,8 +364,6 @@
         },
         },
         filterShowClear: false,
         filterShowClear: false,
         alignmentSelectControlOptions: undefined,
         alignmentSelectControlOptions: undefined,
-        //internal variables
-        valuesFilterControl: [],
         filterTemplate: {
         filterTemplate: {
             input: function (that, field, isVisible) {
             input: function (that, field, isVisible) {
                 return sprintf('<input type="text" class="form-control %s" style="width: 100%; visibility: %s">', field, isVisible);
                 return sprintf('<input type="text" class="form-control %s" style="width: 100%; visibility: %s">', field, isVisible);
@@ -338,7 +375,9 @@
             datepicker: function (that, field, isVisible) {
             datepicker: function (that, field, isVisible) {
                 return sprintf('<input type="text" class="date-filter-control %s form-control" style="width: 100%; visibility: %s">', field, isVisible);
                 return sprintf('<input type="text" class="date-filter-control %s form-control" style="width: 100%; visibility: %s">', field, isVisible);
             }
             }
-        }
+        },
+        //internal variables
+        valuesFilterControl: []
     });
     });
 
 
     $.extend($.fn.bootstrapTable.COLUMN_DEFAULTS, {
     $.extend($.fn.bootstrapTable.COLUMN_DEFAULTS, {
@@ -491,6 +530,10 @@
     };
     };
 
 
     BootstrapTable.prototype.onColumnSearch = function (event) {
     BootstrapTable.prototype.onColumnSearch = function (event) {
+        if ($.inArray(event.keyCode, [37, 38, 39, 40]) > -1) {
+            return;
+        }
+
         copyValues(this);
         copyValues(this);
         var text = $.trim($(event.currentTarget).val());
         var text = $.trim($(event.currentTarget).val());
         var $field = $(event.currentTarget).closest('[data-field]').data('field');
         var $field = $(event.currentTarget).closest('[data-field]').data('field');

+ 1 - 1
src/extensions/filter-control/extension.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "Filter Control",
   "name": "Filter Control",
-  "version": "1.0.0",
+  "version": "2.1.0",
   "description": "Plugin to add input/select element on the top of the columns in order to filter the data.",
   "description": "Plugin to add input/select element on the top of the columns in order to filter the data.",
   "url": "https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/filter-control",
   "url": "https://github.com/wenzhixin/bootstrap-table/tree/master/src/extensions/filter-control",
   "example": "http://issues.wenzhixin.net.cn/bootstrap-table/#extensions/filter-control.html",
   "example": "http://issues.wenzhixin.net.cn/bootstrap-table/#extensions/filter-control.html",