From ffd495501bd029fde4fca6e96ca202b7338ef3fb Mon Sep 17 00:00:00 2001 From: Elsio Sanchez <45974454+elsiosanchez@users.noreply.github.com> Date: Fri, 28 May 2021 17:55:38 -0400 Subject: [PATCH] Fast filtering in the tables (#885) * Filter on tables by columns marked as isSelectionColumn * remove unnecessary code * Search Table Children * minimal chages Co-authored-by: elsiosanchez --- .../ADempiere/DataTable/dataTables-Script.js | 57 ++++++++++++++----- src/components/ADempiere/DataTable/index.vue | 4 +- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/components/ADempiere/DataTable/dataTables-Script.js b/src/components/ADempiere/DataTable/dataTables-Script.js index d993c346..7603c253 100644 --- a/src/components/ADempiere/DataTable/dataTables-Script.js +++ b/src/components/ADempiere/DataTable/dataTables-Script.js @@ -73,13 +73,17 @@ export default { currentTable: 0, visible: this.getShowContextMenuTable, searchTable: '', // text from search + searchTableChildren: '', // text from search defaultMaxPagination: 50, activeName, rowStyle: { height: '52px' }, uuidCurrentRecordSelected: '', - showTableSearch: false + showTableSearch: false, + searchColumnName: [], + recordsSearchTable: [], + recordsSearchTableChildren: [] } }, computed: { @@ -257,6 +261,15 @@ export default { return this.currentTable } return this.currentTable + 1 + }, + + allRecordsData() { + if (this.isParent && !this.isEmptyValue(this.searchTable)) { + return this.recordsSearchTable + } else if (!this.isParent && !this.isEmptyValue(this.searchTableChildren)) { + return this.recordsSearchTableChildren + } + return this.recordsData } }, watch: { @@ -631,21 +644,37 @@ export default { selection: rowsSelection }) }, - filterResult() { - const data = this.recordsData.filter(rowItem => { - if (this.searchTable.trim().length) { - let find = false - Object.keys(rowItem).forEach(key => { - if (String(rowItem[key]).toLowerCase().includes(String(this.searchTable).toLowerCase())) { - find = true - return find - } - }) - return find + filterResult(value) { + const selectionColumn = this.fieldsList.filter(element => element.isSelectionColumn) + this.searchColumnName = selectionColumn.map(element => { + if (element.isSelectionColumn) { + return element.columnName } - return true }) - return data + if (this.isParent) { + this.searchTable = value + } else { + this.searchTableChildren = value + } + const result = this.getterDataRecordsAndSelection.record.filter(record => { + let list + this.searchColumnName.forEach(validate => { + if (typeof record[validate] !== 'boolean' && !this.isEmptyValue(record[validate]) || !this.isEmptyValue(record['DisplayColumn_' + validate])) { + const SearchColumns = typeof record[validate] === 'number' ? record['DisplayColumn_' + validate] : record[validate] + if (SearchColumns.includes(value)) { + list = record + } + } + }) + return list + }) + if (this.isParent) { + this.searchTable = value + this.recordsSearchTable = result + } else { + this.searchTableChildren = value + this.recordsSearchTableChildren = result + } }, /** * Verify is displayed field in column table diff --git a/src/components/ADempiere/DataTable/index.vue b/src/components/ADempiere/DataTable/index.vue index 51bb9bb4..f2bbd94d 100644 --- a/src/components/ADempiere/DataTable/index.vue +++ b/src/components/ADempiere/DataTable/index.vue @@ -84,6 +84,7 @@ size="mini" :placeholder="$t('table.dataTable.search')" class="header-search-input" + @input="filterResult" /> @@ -138,7 +139,6 @@ :is-mobile="isMobile" :panel-metadata="panelMetadata" /> -