From 4f2e0d0f259731af9fe804fced871fc193d1ff86 Mon Sep 17 00:00:00 2001 From: EdwinBetanc0urt Date: Mon, 24 Jun 2024 15:23:48 -0400 Subject: [PATCH] fix: Sort table when is lookup and insensitive case. --- .../ADempiere/DataTable/Browser/index.vue | 1 + src/store/modules/ADempiere/browserManager.js | 18 +++++++++++++++++- src/utils/ADempiere/dictionaryUtils.js | 7 ++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/components/ADempiere/DataTable/Browser/index.vue b/src/components/ADempiere/DataTable/Browser/index.vue index ac3e616faf..52a22272c3 100644 --- a/src/components/ADempiere/DataTable/Browser/index.vue +++ b/src/components/ADempiere/DataTable/Browser/index.vue @@ -73,6 +73,7 @@ :column-key="fieldAttributes.columnName" :prop="fieldAttributes.columnName" sortable + :sort-by="fieldAttributes.sortByProperty" :min-width="widthColumn(fieldAttributes)" :fixed="fieldAttributes.isFixedTableColumn" > diff --git a/src/store/modules/ADempiere/browserManager.js b/src/store/modules/ADempiere/browserManager.js index 327df6c050..3612bc9a17 100644 --- a/src/store/modules/ADempiere/browserManager.js +++ b/src/store/modules/ADempiere/browserManager.js @@ -31,7 +31,9 @@ import { import { ROW_ATTRIBUTES, ROW_KEY_ATTRIBUTES, ROWS_OF_RECORDS_BY_PAGE } from '@/utils/ADempiere/tableUtils' -import { DISPLAY_COLUMN_PREFIX } from '@/utils/ADempiere/dictionaryUtils' +import { + DISPLAY_COLUMN_PREFIX, SORT_COLUMN_PREFIX +} from '@/utils/ADempiere/dictionaryUtils' // Utils and Helper Methods import { isEmptyValue } from '@/utils/ADempiere/valueUtils' @@ -277,6 +279,20 @@ const browserControl = { .then(browserSearchResponse => { const recordsList = browserSearchResponse.records.map((record, rowIndex) => { const { values } = record + + // TODO: Test peformance. + Object.keys(values).forEach(key => { + const currentValue = values[key] + if (key.startsWith(DISPLAY_COLUMN_PREFIX)) { + // Add column with sort values to correct sorting + let sortValue = '' + if (!isEmptyValue(currentValue)) { + sortValue = currentValue.toLowerCase() + } + values[SORT_COLUMN_PREFIX + key] = sortValue + } + }) + return { ...values, // datatables app attributes diff --git a/src/utils/ADempiere/dictionaryUtils.js b/src/utils/ADempiere/dictionaryUtils.js index 6f0eb9ff73..dd70f67db4 100644 --- a/src/utils/ADempiere/dictionaryUtils.js +++ b/src/utils/ADempiere/dictionaryUtils.js @@ -43,6 +43,11 @@ import { */ export const DISPLAY_COLUMN_PREFIX = `DisplayColumn_` +/** + * Sort Column Prefix on Column Name: "SortColumn_ColumnName" + */ +export const SORT_COLUMN_PREFIX = `SortColumn_` + /** * Identifier Column Suffix on Column Name: "_ID" */ @@ -243,7 +248,7 @@ export function generateField({ isSupported: componentReference.isSupported, size: componentReference.size || DEFAULT_SIZE, displayColumnName: DISPLAY_COLUMN_PREFIX + columnName, // key to display column - sortByProperty: !isSupportLookup(fieldToGenerate.display_type) ? columnName : DISPLAY_COLUMN_PREFIX + columnName, + sortByProperty: !isSupportLookup(fieldToGenerate.display_type) ? columnName : SORT_COLUMN_PREFIX + DISPLAY_COLUMN_PREFIX + columnName, // value attributes parsedDefaultValue, parsedDefaultValueTo,