From 3651f23157c677cfc146d4848fb9b4dc0052dc15 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 7 Mar 2018 15:56:07 +0530 Subject: [PATCH] disable editing if getEditor returns false --- dist/frappe-datatable.cjs.js | 24 +++++++++++++++++++----- dist/frappe-datatable.js | 24 +++++++++++++++++++----- docs/assets/frappe-datatable.js | 24 +++++++++++++++++++----- src/cellmanager.js | 22 ++++++++++++++++++---- src/defaults.js | 2 +- 5 files changed, 76 insertions(+), 20 deletions(-) diff --git a/dist/frappe-datatable.cjs.js b/dist/frappe-datatable.cjs.js index d10f8ad..2c47179 100644 --- a/dist/frappe-datatable.cjs.js +++ b/dist/frappe-datatable.cjs.js @@ -2298,11 +2298,25 @@ class CellManager { } getEditor(colIndex, rowIndex, value, parent) { - // debugger; - const obj = this.options.getEditor(colIndex, rowIndex, value, parent); - if (obj && obj.setValue) return obj; + const column = this.datamanager.getColumn(colIndex); + const row = this.datamanager.getRow(rowIndex); + let editor = this.options.getEditor ? + this.options.getEditor(colIndex, rowIndex, value, parent, column, row) : + this.getDefaultEditor(parent); - // editing fallback + if (editor === false) { + // explicitly returned false + return false; + } + if (editor === undefined) { + // didn't return editor, fallback to default + editor = this.getDefaultEditor(parent); + } + + return editor; + } + + getDefaultEditor(parent) { const $input = $.create('input', { class: 'input-style', type: 'text', @@ -3347,7 +3361,7 @@ var DEFAULT_OPTIONS = { none: '' }, freezeMessage: '', - getEditor: () => {}, + getEditor: null, addSerialNoColumn: true, addCheckboxColumn: false, enableClusterize: true, diff --git a/dist/frappe-datatable.js b/dist/frappe-datatable.js index 351a037..fb7ea56 100644 --- a/dist/frappe-datatable.js +++ b/dist/frappe-datatable.js @@ -2297,11 +2297,25 @@ class CellManager { } getEditor(colIndex, rowIndex, value, parent) { - // debugger; - const obj = this.options.getEditor(colIndex, rowIndex, value, parent); - if (obj && obj.setValue) return obj; + const column = this.datamanager.getColumn(colIndex); + const row = this.datamanager.getRow(rowIndex); + let editor = this.options.getEditor ? + this.options.getEditor(colIndex, rowIndex, value, parent, column, row) : + this.getDefaultEditor(parent); - // editing fallback + if (editor === false) { + // explicitly returned false + return false; + } + if (editor === undefined) { + // didn't return editor, fallback to default + editor = this.getDefaultEditor(parent); + } + + return editor; + } + + getDefaultEditor(parent) { const $input = $.create('input', { class: 'input-style', type: 'text', @@ -3346,7 +3360,7 @@ var DEFAULT_OPTIONS = { none: '' }, freezeMessage: '', - getEditor: () => {}, + getEditor: null, addSerialNoColumn: true, addCheckboxColumn: false, enableClusterize: true, diff --git a/docs/assets/frappe-datatable.js b/docs/assets/frappe-datatable.js index 351a037..fb7ea56 100644 --- a/docs/assets/frappe-datatable.js +++ b/docs/assets/frappe-datatable.js @@ -2297,11 +2297,25 @@ class CellManager { } getEditor(colIndex, rowIndex, value, parent) { - // debugger; - const obj = this.options.getEditor(colIndex, rowIndex, value, parent); - if (obj && obj.setValue) return obj; + const column = this.datamanager.getColumn(colIndex); + const row = this.datamanager.getRow(rowIndex); + let editor = this.options.getEditor ? + this.options.getEditor(colIndex, rowIndex, value, parent, column, row) : + this.getDefaultEditor(parent); - // editing fallback + if (editor === false) { + // explicitly returned false + return false; + } + if (editor === undefined) { + // didn't return editor, fallback to default + editor = this.getDefaultEditor(parent); + } + + return editor; + } + + getDefaultEditor(parent) { const $input = $.create('input', { class: 'input-style', type: 'text', @@ -3346,7 +3360,7 @@ var DEFAULT_OPTIONS = { none: '' }, freezeMessage: '', - getEditor: () => {}, + getEditor: null, addSerialNoColumn: true, addCheckboxColumn: false, enableClusterize: true, diff --git a/src/cellmanager.js b/src/cellmanager.js index 39f601c..38a6f25 100644 --- a/src/cellmanager.js +++ b/src/cellmanager.js @@ -430,11 +430,25 @@ export default class CellManager { } getEditor(colIndex, rowIndex, value, parent) { - // debugger; - const obj = this.options.getEditor(colIndex, rowIndex, value, parent); - if (obj && obj.setValue) return obj; + const column = this.datamanager.getColumn(colIndex); + const row = this.datamanager.getRow(rowIndex); + let editor = this.options.getEditor ? + this.options.getEditor(colIndex, rowIndex, value, parent, column, row) : + this.getDefaultEditor(parent); - // editing fallback + if (editor === false) { + // explicitly returned false + return false; + } + if (editor === undefined) { + // didn't return editor, fallback to default + editor = this.getDefaultEditor(parent); + } + + return editor; + } + + getDefaultEditor(parent) { const $input = $.create('input', { class: 'input-style', type: 'text', diff --git a/src/defaults.js b/src/defaults.js index f958cd4..0217f17 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -39,7 +39,7 @@ export default { none: '' }, freezeMessage: '', - getEditor: () => {}, + getEditor: null, addSerialNoColumn: true, addCheckboxColumn: false, enableClusterize: true,