-
Notifications
You must be signed in to change notification settings - Fork 665
T1306840 - DataGrid - TagBox in the filter row doesn't show selected tags if values are numbers #33080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 26_1
Are you sure you want to change the base?
T1306840 - DataGrid - TagBox in the filter row doesn't show selected tags if values are numbers #33080
Changes from all commits
6760514
e7eb53c
256c4e0
3b8bc20
7bedcc6
3832c65
8562a1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| const SELECTORS = { | ||
| editorCell: 'dx-editor-cell', | ||
| editorContainer: 'dx-editor-container', | ||
| widget: 'dx-widget', | ||
| }; | ||
|
|
||
| export class FilterCellModel { | ||
| constructor(protected readonly root: HTMLElement | null) {} | ||
|
|
||
| public getElement(): HTMLElement | null { | ||
| return this.root; | ||
| } | ||
|
|
||
| public getEditor<T>(EditorModel: new (element: HTMLElement) => T): T { | ||
| const editorElement = this.root?.querySelector(`.${SELECTORS.editorContainer} .${SELECTORS.widget}`) as HTMLElement; | ||
| return new EditorModel(editorElement); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export class BaseRowModel { | ||
| constructor(protected readonly root: HTMLElement | null) {} | ||
|
|
||
| public getElement(): HTMLElement | null { | ||
| return this.root; | ||
| } | ||
|
|
||
| public getCells(): NodeListOf<HTMLElement> { | ||
| return this.root?.querySelectorAll('td') as NodeListOf<HTMLElement>; | ||
Raushen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public getCell(columnIndex: number): HTMLElement | null { | ||
| return this.getCells()?.[columnIndex] ?? null; | ||
Raushen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { FilterCellModel } from '../cell/filter_cell'; | ||
| import { BaseRowModel } from './base_row'; | ||
|
|
||
| export class FilterRowModel extends BaseRowModel { | ||
| public getFilterCell(columnIndex: number): FilterCellModel { | ||
| return new FilterCellModel(this.getCell(columnIndex)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import '@js/ui/tag_box'; | ||
|
|
||
| import { | ||
| afterEach, beforeEach, describe, expect, it, | ||
| } from '@jest/globals'; | ||
| import type { EditorPreparingEvent } from '@js/ui/data_grid'; | ||
| import { TagBoxModel } from '@ts/ui/__tests__/__mock__/model/tag_box'; | ||
|
|
||
| import { | ||
| afterTest, | ||
| beforeTest, | ||
| createDataGrid, | ||
| flushAsync, | ||
| } from '../../__tests__/__mock__/helpers/utils'; | ||
|
|
||
| describe('FilterRow', () => { | ||
| beforeEach(beforeTest); | ||
| afterEach(afterTest); | ||
|
|
||
| describe('TagBox in filterRow with lookup column (T1306840)', () => { | ||
| it('should display tags in TagBox after selecting filter values', async () => { | ||
| // arrange | ||
| const lookupDataSource = [ | ||
| { Value: 0, Text: 'A' }, | ||
| { Value: 1, Text: 'B' }, | ||
| { Value: 2, Text: 'C' }, | ||
| ]; | ||
|
|
||
| const { component } = await createDataGrid({ | ||
| dataSource: [ | ||
| { ID: 1, test: 0 }, | ||
| { ID: 2, test: 2 }, | ||
| { ID: 3, test: 1 }, | ||
| ], | ||
| keyExpr: 'ID', | ||
| columns: [{ | ||
| dataField: 'test', | ||
| lookup: { | ||
| dataSource: lookupDataSource, | ||
| displayExpr: 'Text', | ||
| valueExpr: 'Value', | ||
| }, | ||
| }], | ||
| filterRow: { visible: true }, | ||
| onEditorPreparing(e: EditorPreparingEvent) { | ||
| if (e.parentType === 'filterRow' && e.dataField === 'test') { | ||
| e.editorName = 'dxTagBox'; | ||
| e.editorOptions.dataSource = lookupDataSource; | ||
| e.editorOptions.displayExpr = 'Text'; | ||
| e.editorOptions.valueExpr = 'Value'; | ||
| e.editorOptions.showSelectionControls = true; | ||
| e.editorOptions.applyValueMode = 'useButtons'; | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| await flushAsync(); | ||
|
|
||
| // act | ||
| const filterCell = component.getFilterRow().getFilterCell(0); | ||
| const tagBox = filterCell.getEditor(TagBoxModel); | ||
| tagBox.setValue([0, 2]); | ||
|
|
||
| await flushAsync(); | ||
|
|
||
| // assert | ||
| expect(tagBox.getValue()).toEqual([0, 2]); | ||
| expect(tagBox.getTags()).toHaveLength(2); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,7 @@ const FILTER_MODIFIED_CLASS = 'dx-filter-modified'; | |
| const EDITORS_INPUT_SELECTOR = 'input:not([type=\'hidden\'])'; | ||
|
|
||
| const BETWEEN_OPERATION_DATA_TYPES = ['date', 'datetime', 'number']; | ||
| const MULTISELECT_EDITOR_NAMES = ['dxTagBox', 'dxDateRangeBox', 'dxCalendar', 'dxRangeSlider']; | ||
|
|
||
| function isOnClickApplyFilterMode(that) { | ||
| return that.option('filterRow.applyFilter') === 'onClick'; | ||
|
|
@@ -124,9 +125,20 @@ const getColumnSelectedFilterOperation = function (that, column) { | |
| } | ||
| }; | ||
|
|
||
| const isValidFilterValue = function (filterValue, column) { | ||
| if (column && BETWEEN_OPERATION_DATA_TYPES.includes(column.dataType) && Array.isArray(filterValue)) { | ||
| return false; | ||
| const hasMultiselectEditor = function ($editorContainer): boolean { | ||
| const editor = getEditorInstance($editorContainer); | ||
| // @ts-expect-error | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change import Editor to |
||
| return !editor || MULTISELECT_EDITOR_NAMES.includes(editor.NAME); | ||
| }; | ||
|
|
||
| const isValidFilterValue = function (filterValue, column, $editorContainer): boolean { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add types to arguments, please |
||
| if (Array.isArray(filterValue)) { | ||
| if (hasMultiselectEditor($editorContainer)) { | ||
| return true; | ||
| } | ||
| if (BETWEEN_OPERATION_DATA_TYPES.includes(column?.dataType)) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return filterValue !== undefined; | ||
|
|
@@ -137,15 +149,20 @@ const getFilterValue = function (that, columnIndex, $editorContainer) { | |
| const filterValue = getColumnFilterValue(that, column); | ||
| const isFilterRange = $editorContainer.closest(`.${that.addWidgetPrefix(FILTER_RANGE_OVERLAY_CLASS)}`).length; | ||
| const isRangeStart = $editorContainer.hasClass(that.addWidgetPrefix(FILTER_RANGE_START_CLASS)); | ||
| const isBetween = getColumnSelectedFilterOperation(that, column) === 'between'; | ||
|
|
||
| if (filterValue && Array.isArray(filterValue) && getColumnSelectedFilterOperation(that, column) === 'between') { | ||
| if (filterValue && Array.isArray(filterValue) && isBetween) { | ||
| if (isRangeStart) { | ||
| return filterValue[0]; | ||
| } | ||
| return filterValue[1]; | ||
| } | ||
|
|
||
| return !isFilterRange && isValidFilterValue(filterValue, column) ? filterValue : null; | ||
| if (isFilterRange || !isValidFilterValue(filterValue, column, $editorContainer)) { | ||
| return null; | ||
| } | ||
|
|
||
| return filterValue; | ||
| }; | ||
|
|
||
| const normalizeFilterValue = function (that, filterValue, column, $editorContainer) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import type dxTagBox from '@js/ui/tag_box'; | ||
| import TagBox from '@js/ui/tag_box'; | ||
|
|
||
| const TAG_CLASS = 'dx-tag'; | ||
|
|
||
| export class TagBoxModel { | ||
| constructor(protected readonly root: HTMLElement) {} | ||
|
|
||
| public getInstance(): dxTagBox { | ||
| return TagBox.getInstance(this.root) as dxTagBox; | ||
| } | ||
|
|
||
| public getValue(): (string | number)[] { | ||
| return this.getInstance().option('value') as (string | number)[]; | ||
| } | ||
|
|
||
| public setValue(value: (string | number)[]): void { | ||
| this.getInstance().option('value', value); | ||
| } | ||
|
|
||
| public getInput(): HTMLInputElement { | ||
| return this.root.querySelector('input') as HTMLInputElement; | ||
| } | ||
|
|
||
| public getTags(): NodeListOf<HTMLElement> { | ||
| return this.root.querySelectorAll(`.${TAG_CLASS}`); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.