diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d38793f01a..72172d54d9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -200,9 +200,8 @@ includes code changes) and under the terms of the ## Code guidelines - Readability -- Need semicolons -- 4 spaces (no tabs) -- strict mode +- [no semicolons](https://github.com/wenzhixin/bootstrap-table/pull/4218#issuecomment-475822706) +- 2 spaces (no tabs) - "Attractive" diff --git a/site/docs/api/table-options.md b/site/docs/api/table-options.md index 4e6a4959f0..4806e224a1 100644 --- a/site/docs/api/table-options.md +++ b/site/docs/api/table-options.md @@ -578,7 +578,7 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`. - **Detail:** - When set pagination property, initialize the page size selecting list. If you include the `'All'` or `'Unlimited'` option, all the records will be shown in your table. + When set pagination property, initialize the page size selecting list. If you include the `'all'` or `'unlimited'` option, all the records will be shown in your table. - **Default:** `[10, 25, 50, 100]` @@ -705,6 +705,14 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`. - **Detail:** Enable the search input. + + There are 3 ways to search: + - The value contains the search query (Default). + Example: Github contains git. + - The value must be identical to the search query. + Example: Github (value) and Github (search query). + - Comparsions (<, >, <=, =<, >=, =>) + Example: 4 is larger than 3. - **Default:** `false` @@ -732,7 +740,8 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`. - **Detail:** - Enable the strict search. + Enable the strict search. + Disables the comparison checks. - **Default:** `false` @@ -996,7 +1005,7 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`. - **Detail:** - Indicate which field is an identity field. + Indicate which field will be used as checkbox/radiobox value, its the counterpart to [selectItemName](https://bootstrap-table.com/docs/api/table-options/#selectitemname). - **Default:** `undefined` diff --git a/site/docs/extensions/editable.md b/site/docs/extensions/editable.md index 85e5d1aa09..71ae35bf42 100644 --- a/site/docs/extensions/editable.md +++ b/site/docs/extensions/editable.md @@ -69,7 +69,7 @@ Fired when all columns was initialized by `$().editable()` method. Fired when an editable cell is saved. -parameters: field, row, oldValue, $el +parameters: field, row, rowIndex, oldValue, $el ### onEditableShown(editable-shown.bs.table) diff --git a/site/docs/extensions/filter-control.md b/site/docs/extensions/filter-control.md index a313e7a371..55205e0a41 100644 --- a/site/docs/extensions/filter-control.md +++ b/site/docs/extensions/filter-control.md @@ -162,3 +162,7 @@ Dependence if you use the datepicker option: [bootstrap-datepicker](https://gith ### triggerSearch * Trigger manually the search action + +### clearFilterControl + +* Clear all the controls added by this plugin (similar to filterShowClear option). diff --git a/site/docs/getting-started/introduction.md b/site/docs/getting-started/introduction.md index 618f65daf0..6b95591e13 100644 --- a/site/docs/getting-started/introduction.md +++ b/site/docs/getting-started/introduction.md @@ -45,12 +45,11 @@ Put it all together and your pages should look like this: + Hello, Bootstrap Table! - - Hello, Bootstrap Table! diff --git a/src/bootstrap-table.js b/src/bootstrap-table.js index 57ffc19850..880b59ced8 100644 --- a/src/bootstrap-table.js +++ b/src/bootstrap-table.js @@ -1401,7 +1401,43 @@ return true } } else { - if ((`${value}`).toLowerCase().includes(s)) { + const largerSmallerEqualsRegex = /(?:(<=|=>|=<|>=|>|<)(?:\s+)?(\d+)?|(\d+)?(\s+)?(<=|=>|=<|>=|>|<))/gm + const matches = largerSmallerEqualsRegex.exec(s) + let comparisonCheck = false + + if (matches) { + const operator = matches[1] || matches[5] + 'l' + const comparisonValue = matches[2] || matches[3] + const int = parseInt(value, 10) + const comparisonInt = parseInt(comparisonValue, 10) + + switch (operator) { + case '>': + case ' comparisonInt + break + case '<': + case '>l': + comparisonCheck = int < comparisonInt + break + case '<=': + case '=<': + case '>=l': + case '=>l': + comparisonCheck = int <= comparisonInt + break + case '>=': + case '=>': + case '<=l': + case '== comparisonInt + break + default: + break + } + } + + if (comparisonCheck || (`${value}`).toLowerCase().includes(s)) { return true } } @@ -1495,8 +1531,8 @@ pageList = [] for (const value of list) { pageList.push( - (value.toUpperCase() === o.formatAllRows().toUpperCase() || - value.toUpperCase() === 'UNLIMITED') + (value.toLowerCase() === o.formatAllRows().toLowerCase() || + ['all', 'unlimited'].includes(value.toLowerCase())) ? o.formatAllRows() : +value) } } @@ -1625,18 +1661,19 @@ $next = this.$pagination.find('.page-next') $number = this.$pagination.find('.page-item').not('.page-next, .page-pre') + if (this.totalPages <= 1) { + this.$pagination.find('div.pagination').hide() + } + if (o.smartDisplay) { - if (this.totalPages <= 1) { - this.$pagination.find('div.pagination').hide() - } if (pageList.length < 2 || o.totalRows <= pageList[0]) { this.$pagination.find('span.page-list').hide() } - - // when data is empty, hide the pagination - this.$pagination[this.getData().length ? 'show' : 'hide']() } + // when data is empty, hide the pagination + this.$pagination[this.getData().length ? 'show' : 'hide']() + if (!o.paginationLoop) { if (o.pageNumber === 1) { $pre.addClass('disabled') @@ -2077,6 +2114,10 @@ this.updateSelected() this.resetView() + if (this.options.sidePagination !== 'server') { + this.options.totalRows = data.length + } + this.trigger('post-body', data) } diff --git a/src/extensions/editable/bootstrap-table-editable.js b/src/extensions/editable/bootstrap-table-editable.js index 134b5546ca..cb988e4ce3 100644 --- a/src/extensions/editable/bootstrap-table-editable.js +++ b/src/extensions/editable/bootstrap-table-editable.js @@ -11,7 +11,7 @@ onEditableInit () { return false }, - onEditableSave (field, row, oldValue, $el) { + onEditableSave (field, row, rowIndex, oldValue, $el) { return false }, onEditableShown (field, row, $el, editable) { @@ -114,21 +114,21 @@ $field.off('save').on('save', ({currentTarget}, {submitValue}) => { const $this = $(currentTarget) const data = this.getData() - const index = $this.parents('tr[data-index]').data('index') - const row = data[index] + const rowIndex = $this.parents('tr[data-index]').data('index') + const row = data[rowIndex] const oldValue = row[column.field] $this.data('value', submitValue) row[column.field] = submitValue - this.trigger('editable-save', column.field, row, oldValue, $this) - this.resetFooter() + this.trigger('editable-save', column.field, row, rowIndex, oldValue, $this) + this.initBody() }) $field.off('shown').on('shown', ({currentTarget}, editable) => { const $this = $(currentTarget) const data = this.getData() - const index = $this.parents('tr[data-index]').data('index') - const row = data[index] + const rowIndex = $this.parents('tr[data-index]').data('index') + const row = data[rowIndex] this.trigger('editable-shown', column.field, row, $this, editable) }) @@ -136,8 +136,8 @@ $field.off('hidden').on('hidden', ({currentTarget}, reason) => { const $this = $(currentTarget) const data = this.getData() - const index = $this.parents('tr[data-index]').data('index') - const row = data[index] + const rowIndex = $this.parents('tr[data-index]').data('index') + const row = data[rowIndex] this.trigger('editable-hidden', column.field, row, $this, reason) }) diff --git a/src/extensions/filter-control/bootstrap-table-filter-control.js b/src/extensions/filter-control/bootstrap-table-filter-control.js index 18db04da06..3507bc1fca 100644 --- a/src/extensions/filter-control/bootstrap-table-filter-control.js +++ b/src/extensions/filter-control/bootstrap-table-filter-control.js @@ -826,6 +826,10 @@ item.value = '' }) + $.each(that.options.filterControls, (i, item) => { + item.text = '' + }) + UtilsFilterControl.setValues(that) // clear cookies once the filters are clean diff --git a/src/extensions/multiple-sort/bootstrap-table-multiple-sort.js b/src/extensions/multiple-sort/bootstrap-table-multiple-sort.js index 13493f87e9..4a98cd2121 100644 --- a/src/extensions/multiple-sort/bootstrap-table-multiple-sort.js +++ b/src/extensions/multiple-sort/bootstrap-table-multiple-sort.js @@ -126,7 +126,7 @@ var t = that.options.queryParams; that.options.queryParams = function(params) { params.multiSort = that.options.sortPriority; - return t(params); + return $.fn.bootstrapTable.utils.calculateObjectValue(that.options, t, [params]); }; isSingleSort=false; that.initServer(that.options.silentSort);