From a467d164a936c8098c04f8d45a36fa70eb07b962 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 21 Feb 2018 19:06:10 +0530 Subject: [PATCH] [InlineFilters] Don't bind if disabled --- dist/frappe-datatable.cjs.js | 51 +++++++++++------------------------- dist/frappe-datatable.js | 51 +++++++++++------------------------- index.html | 2 +- src/cellmanager.js | 14 +++++----- src/columnmanager.js | 12 ++++++--- 5 files changed, 49 insertions(+), 81 deletions(-) diff --git a/dist/frappe-datatable.cjs.js b/dist/frappe-datatable.cjs.js index 1751590..cc03883 100644 --- a/dist/frappe-datatable.cjs.js +++ b/dist/frappe-datatable.cjs.js @@ -211,12 +211,10 @@ var isObject_1 = isObject; var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; -/** Detect free variable `global` from Node.js. */ var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; var _freeGlobal = freeGlobal; -/** Detect free variable `self`. */ var freeSelf = typeof self == 'object' && self && self.Object === Object && self; /** Used as a reference to the global object. */ @@ -224,34 +222,16 @@ var root = _freeGlobal || freeSelf || Function('return this')(); var _root = root; -/** - * Gets the timestamp of the number of milliseconds that have elapsed since - * the Unix epoch (1 January 1970 00:00:00 UTC). - * - * @static - * @memberOf _ - * @since 2.4.0 - * @category Date - * @returns {number} Returns the timestamp. - * @example - * - * _.defer(function(stamp) { - * console.log(_.now() - stamp); - * }, _.now()); - * // => Logs the number of milliseconds it took for the deferred invocation. - */ var now = function() { return _root.Date.now(); }; var now_1 = now; -/** Built-in value references. */ var Symbol = _root.Symbol; var _Symbol = Symbol; -/** Used for built-in method references. */ var objectProto = Object.prototype; /** Used to check objects for own properties. */ @@ -319,7 +299,6 @@ function objectToString(value) { var _objectToString = objectToString; -/** `Object#toString` result references. */ var nullTag = '[object Null]'; var undefinedTag = '[object Undefined]'; @@ -374,7 +353,6 @@ function isObjectLike(value) { var isObjectLike_1 = isObjectLike; -/** `Object#toString` result references. */ var symbolTag = '[object Symbol]'; /** @@ -401,7 +379,6 @@ function isSymbol(value) { var isSymbol_1 = isSymbol; -/** Used as references for various `Number` constants. */ var NAN = 0 / 0; /** Used to match leading and trailing whitespace. */ @@ -465,7 +442,6 @@ function toNumber(value) { var toNumber_1 = toNumber; -/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /* Built-in method references for those with the same name as other `lodash` methods. */ @@ -652,7 +628,6 @@ function debounce(func, wait, options) { var debounce_1 = debounce; -/** Error message constants. */ var FUNC_ERROR_TEXT$1 = 'Expected a function'; /** @@ -1379,10 +1354,13 @@ class ColumnManager { $('thead', this.header).innerHTML = html; this.$filterRow = $('.data-table-row[data-is-filter]', this.header); - // hide filter row immediately, so it doesn't disturb layout - $.style(this.$filterRow, { - display: 'none' - }); + + if (this.$filterRow) { + // hide filter row immediately, so it doesn't disturb layout + $.style(this.$filterRow, { + display: 'none' + }); + } } else { // refresh dom state const $cols = $.each('.data-table-col', this.header); @@ -1642,6 +1620,7 @@ class ColumnManager { } bindFilter() { + if (!this.options.enableInlineFilters) return; const handler = e => { const $filterCell = $.closest('.data-table-col', e.target); const { colIndex } = $.data($filterCell); @@ -1851,13 +1830,15 @@ class CellManager { this.deactivateEditing(); }); - this.keyboard.on('ctrl+f', (e) => { - const $cell = $.closest('.data-table-col', e.target); - let { colIndex } = $.data($cell); + if (this.options.enableInlineFilters) { + this.keyboard.on('ctrl+f', (e) => { + const $cell = $.closest('.data-table-col', e.target); + let { colIndex } = $.data($cell); - this.activateFilter(colIndex); - return true; - }); + this.activateFilter(colIndex); + return true; + }); + } } bindKeyboardSelection() { diff --git a/dist/frappe-datatable.js b/dist/frappe-datatable.js index d059008..4d920eb 100644 --- a/dist/frappe-datatable.js +++ b/dist/frappe-datatable.js @@ -210,12 +210,10 @@ var isObject_1 = isObject; var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; -/** Detect free variable `global` from Node.js. */ var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; var _freeGlobal = freeGlobal; -/** Detect free variable `self`. */ var freeSelf = typeof self == 'object' && self && self.Object === Object && self; /** Used as a reference to the global object. */ @@ -223,34 +221,16 @@ var root = _freeGlobal || freeSelf || Function('return this')(); var _root = root; -/** - * Gets the timestamp of the number of milliseconds that have elapsed since - * the Unix epoch (1 January 1970 00:00:00 UTC). - * - * @static - * @memberOf _ - * @since 2.4.0 - * @category Date - * @returns {number} Returns the timestamp. - * @example - * - * _.defer(function(stamp) { - * console.log(_.now() - stamp); - * }, _.now()); - * // => Logs the number of milliseconds it took for the deferred invocation. - */ var now = function() { return _root.Date.now(); }; var now_1 = now; -/** Built-in value references. */ var Symbol = _root.Symbol; var _Symbol = Symbol; -/** Used for built-in method references. */ var objectProto = Object.prototype; /** Used to check objects for own properties. */ @@ -318,7 +298,6 @@ function objectToString(value) { var _objectToString = objectToString; -/** `Object#toString` result references. */ var nullTag = '[object Null]'; var undefinedTag = '[object Undefined]'; @@ -373,7 +352,6 @@ function isObjectLike(value) { var isObjectLike_1 = isObjectLike; -/** `Object#toString` result references. */ var symbolTag = '[object Symbol]'; /** @@ -400,7 +378,6 @@ function isSymbol(value) { var isSymbol_1 = isSymbol; -/** Used as references for various `Number` constants. */ var NAN = 0 / 0; /** Used to match leading and trailing whitespace. */ @@ -464,7 +441,6 @@ function toNumber(value) { var toNumber_1 = toNumber; -/** Error message constants. */ var FUNC_ERROR_TEXT = 'Expected a function'; /* Built-in method references for those with the same name as other `lodash` methods. */ @@ -651,7 +627,6 @@ function debounce(func, wait, options) { var debounce_1 = debounce; -/** Error message constants. */ var FUNC_ERROR_TEXT$1 = 'Expected a function'; /** @@ -1378,10 +1353,13 @@ class ColumnManager { $('thead', this.header).innerHTML = html; this.$filterRow = $('.data-table-row[data-is-filter]', this.header); - // hide filter row immediately, so it doesn't disturb layout - $.style(this.$filterRow, { - display: 'none' - }); + + if (this.$filterRow) { + // hide filter row immediately, so it doesn't disturb layout + $.style(this.$filterRow, { + display: 'none' + }); + } } else { // refresh dom state const $cols = $.each('.data-table-col', this.header); @@ -1641,6 +1619,7 @@ class ColumnManager { } bindFilter() { + if (!this.options.enableInlineFilters) return; const handler = e => { const $filterCell = $.closest('.data-table-col', e.target); const { colIndex } = $.data($filterCell); @@ -1850,13 +1829,15 @@ class CellManager { this.deactivateEditing(); }); - this.keyboard.on('ctrl+f', (e) => { - const $cell = $.closest('.data-table-col', e.target); - let { colIndex } = $.data($cell); + if (this.options.enableInlineFilters) { + this.keyboard.on('ctrl+f', (e) => { + const $cell = $.closest('.data-table-col', e.target); + let { colIndex } = $.data($cell); - this.activateFilter(colIndex); - return true; - }); + this.activateFilter(colIndex); + return true; + }); + } } bindKeyboardSelection() { diff --git a/index.html b/index.html index a4c587b..333f7af 100644 --- a/index.html +++ b/index.html @@ -70,7 +70,7 @@ layout: 'fluid', columns, data, - enableInlineFilters: true, + // enableInlineFilters: true, getEditor(colIndex, rowIndex, value, parent) { // editing obj only for date field if (colIndex != 6) return; diff --git a/src/cellmanager.js b/src/cellmanager.js index eeff133..e9c2a6a 100644 --- a/src/cellmanager.js +++ b/src/cellmanager.js @@ -108,13 +108,15 @@ export default class CellManager { this.deactivateEditing(); }); - this.keyboard.on('ctrl+f', (e) => { - const $cell = $.closest('.data-table-col', e.target); - let { colIndex } = $.data($cell); + if (this.options.enableInlineFilters) { + this.keyboard.on('ctrl+f', (e) => { + const $cell = $.closest('.data-table-col', e.target); + let { colIndex } = $.data($cell); - this.activateFilter(colIndex); - return true; - }); + this.activateFilter(colIndex); + return true; + }); + } } bindKeyboardSelection() { diff --git a/src/columnmanager.js b/src/columnmanager.js index c5286b6..e67951d 100644 --- a/src/columnmanager.js +++ b/src/columnmanager.js @@ -40,10 +40,13 @@ export default class ColumnManager { $('thead', this.header).innerHTML = html; this.$filterRow = $('.data-table-row[data-is-filter]', this.header); - // hide filter row immediately, so it doesn't disturb layout - $.style(this.$filterRow, { - display: 'none' - }); + + if (this.$filterRow) { + // hide filter row immediately, so it doesn't disturb layout + $.style(this.$filterRow, { + display: 'none' + }); + } } else { // refresh dom state const $cols = $.each('.data-table-col', this.header); @@ -303,6 +306,7 @@ export default class ColumnManager { } bindFilter() { + if (!this.options.enableInlineFilters) return; const handler = e => { const $filterCell = $.closest('.data-table-col', e.target); const { colIndex } = $.data($filterCell);