-
Notifications
You must be signed in to change notification settings - Fork 665
FilterBuilder: fix invalid date formatting (T1319193, T1311486) #32286
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
Merged
Raushen
merged 4 commits into
DevExpress:26_1
from
anna-shakhova:26_1__T1319193-filter-builder-date-format
Jan 27, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes
File renamed without changes
File renamed without changes
158 changes: 158 additions & 0 deletions
158
e2e/testcafe-devextreme/tests/dataGrid/common/filterPanel/functional.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import DataGrid from 'devextreme-testcafe-models/dataGrid'; | ||
| import Popup from 'devextreme-testcafe-models/popup'; | ||
| import FilterBuilder from 'devextreme-testcafe-models/filterBuilder'; | ||
| import FilterTextBox from 'devextreme-testcafe-models/dataGrid/editors/filterTextBox'; | ||
|
|
||
| import url from '../../../../helpers/getPageUrl'; | ||
| import { createWidget } from '../../../../helpers/createWidget'; | ||
|
|
||
| fixture.disablePageReloads`Filtering` | ||
| .page(url(__dirname, '../../../container.html')); | ||
|
|
||
| const GRID_CONTAINER = '#container'; | ||
|
|
||
| // T1319193, T1311486 | ||
| test('Proper handle custom filter operations for dates with non-date values', async (t) => { | ||
| const dataGrid = new DataGrid(GRID_CONTAINER); | ||
| const filterPanel = dataGrid.getFilterPanel(); | ||
|
|
||
| let filterBuilderPopup = await filterPanel.openFilterBuilderPopup(t); | ||
| let filterBuilder = filterBuilderPopup.getFilterBuilder(); | ||
|
|
||
| await t | ||
| .click(filterBuilder.getAddButton()) | ||
| .expect(FilterBuilder.getPopupTreeView().visible).ok() | ||
| .click(FilterBuilder.getPopupTreeViewNodeByText('Add Condition')) | ||
| .click(filterBuilder.getField(0, 'item').element) | ||
| .click(FilterBuilder.getPopupTreeViewNodeByText('Order Date')) | ||
| .click(filterBuilder.getField(0, 'itemOperation').element) | ||
| .click(FilterBuilder.getPopupTreeViewNodeByText('Is any of')) | ||
| .click(filterBuilder.getField(0, 'itemValue').element) | ||
| .click(FilterBuilder.getPopupTreeViewNodeCheckboxByText('Weekends')) | ||
| .click(new Popup(FilterBuilder.getPopupTreeView()).getOkButton().element) | ||
| .click(filterBuilderPopup.asPopup().getOkButton().element); | ||
|
|
||
| await t | ||
| .expect(dataGrid.getRows().count) | ||
| .eql(3) | ||
| .expect(filterPanel.getFilterText().element.innerText) | ||
| .eql('[Order Date] Is any of(\'Weekends\')'); | ||
|
|
||
| filterBuilderPopup = await filterPanel.openFilterBuilderPopup(t); | ||
| filterBuilder = filterBuilderPopup.getFilterBuilder(); | ||
|
|
||
| await t | ||
| .click(filterBuilder.getField(0, 'itemOperation').element) | ||
| .click(FilterBuilder.getPopupTreeViewNodeByText('Weekends')) | ||
| .click(filterBuilderPopup.asPopup().getOkButton().element); | ||
|
|
||
| await t | ||
| .expect(dataGrid.getRows().count) | ||
| .eql(3) | ||
| .expect(filterPanel.getFilterText().element.innerText) | ||
| .eql('[Order Date] Weekends'); | ||
|
|
||
| const dateFilterCell = dataGrid.getFilterEditor(1, FilterTextBox); | ||
|
|
||
| await t | ||
| .click(dateFilterCell.menuButton) | ||
| .click(dateFilterCell.menu.getItemByText('Between')) | ||
| .expect(dataGrid.getFilterRangeOverlay().exists).ok() | ||
| .typeText(dataGrid.getFilterRangeStartEditor().input, '2/1/2017') | ||
| .typeText(dataGrid.getFilterRangeEndEditor().input, '2/28/2017') | ||
| .pressKey('enter'); | ||
|
|
||
| await t | ||
| .expect(dataGrid.getRows().count) | ||
| .eql(4) | ||
| .expect(filterPanel.getFilterText().element.innerText) | ||
| .eql('[Order Date] Is between(\'2/1/2017\', \'2/28/2017\')'); | ||
| }).before(async () => { | ||
| const dataSource = [{ | ||
| ID: 1, | ||
| OrderNumber: 35711, | ||
| OrderDate: '2017/01/12', | ||
| Employee: 'Jim Packard', | ||
| }, { | ||
| ID: 5, | ||
| OrderNumber: 35714, | ||
| OrderDate: '2017/01/22', | ||
| Employee: 'Harv Mudd', | ||
| }, { | ||
| ID: 7, | ||
| OrderNumber: 35983, | ||
| OrderDate: '2017/02/07', | ||
| Employee: 'Todd Hoffman', | ||
| }, { | ||
| ID: 14, | ||
| OrderNumber: 39420, | ||
| OrderDate: '2017/02/15', | ||
| Employee: 'Jim Packard', | ||
| }, { | ||
| ID: 15, | ||
| OrderNumber: 39874, | ||
| OrderDate: '2017/02/04', | ||
| Employee: 'Harv Mudd', | ||
| }]; | ||
|
|
||
| return createWidget('dxDataGrid', { | ||
| dataSource, | ||
| keyExpr: 'ID', | ||
| filterRow: { visible: true }, | ||
| filterPanel: { visible: true }, | ||
| headerFilter: { visible: true }, | ||
| filterBuilder: { | ||
| customOperations: [ | ||
| { | ||
| name: 'weekends', | ||
| caption: 'Weekends', | ||
| dataTypes: ['date'], | ||
| icon: 'check', | ||
| hasValue: false, | ||
| calculateFilterExpression() { | ||
| function getOrderDay(rowData: { OrderDate: string }) { | ||
| return (new Date(rowData.OrderDate)).getDay(); | ||
| } | ||
|
|
||
| return [[getOrderDay, '=', 0], 'or', [getOrderDay, '=', 6]]; | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| columns: [ | ||
| 'OrderNumber', | ||
| { | ||
| dataField: 'OrderDate', | ||
| dataType: 'date', | ||
| calculateFilterExpression(value, selectedFilterOperations, target) { | ||
| if (target === 'headerFilter' && value === 'weekends') { | ||
| function getOrderDay(rowData: { OrderDate: string }) { | ||
| return (new Date(rowData.OrderDate)).getDay(); | ||
| } | ||
|
|
||
| return [[getOrderDay, '=', 0], 'or', [getOrderDay, '=', 6]]; | ||
| } | ||
| return this.defaultCalculateFilterExpression?.( | ||
| value, | ||
| selectedFilterOperations, | ||
| target, | ||
| ) ?? []; | ||
| }, | ||
| headerFilter: { | ||
| dataSource(data) { | ||
| if (data.dataSource) { | ||
| data.dataSource.postProcess = (results) => { | ||
| results.push({ | ||
| text: 'Weekends', | ||
| value: 'weekends', | ||
| }); | ||
| return results; | ||
| }; | ||
| } | ||
| }, | ||
| }, | ||
| }, | ||
| 'Employee', | ||
| ], | ||
| }); | ||
| }); | ||
8 changes: 4 additions & 4 deletions
8
...reme/tests/dataGrid/common/filterPanel.ts → ...sts/dataGrid/common/filterPanel/visual.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/devextreme/js/__internal/filter_builder/__tests__/utils.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import { describe, expect, it } from '@jest/globals'; | ||
| import type { CustomOperation, Field } from '@js/ui/filter_builder'; | ||
|
|
||
| import { getCurrentValueText } from '../m_utils'; | ||
|
|
||
| describe('Formatting', () => { | ||
| it('empty string', () => { | ||
| const field = {}; | ||
| const value = ''; | ||
|
|
||
| expect(getCurrentValueText(field, value, null)).toBe(''); | ||
| }); | ||
|
|
||
| it('string', () => { | ||
| const field = {}; | ||
| const value = 'Text'; | ||
|
|
||
| expect(getCurrentValueText(field, value, null)).toBe('Text'); | ||
| }); | ||
|
|
||
| it('shortDate', () => { | ||
| const field = { format: 'shortDate' }; | ||
| const value = new Date(2017, 8, 5); | ||
|
|
||
| expect(getCurrentValueText(field, value, null)).toBe('9/5/2017'); | ||
| }); | ||
|
|
||
| it('invalid date string (T1319193)', () => { | ||
| const field = { format: 'shortDate' }; | ||
| const dateString = 'Weekend'; | ||
|
|
||
| expect(getCurrentValueText(field, dateString, null)).toBe(dateString); | ||
| }); | ||
|
|
||
| it('boolean', () => { | ||
| const field: Field = { dataType: 'boolean' }; | ||
| let value = true; | ||
|
|
||
| expect(getCurrentValueText(field, value, null)).toBe('true'); | ||
|
|
||
| value = false; | ||
| expect(getCurrentValueText(field, value, null)).toBe('false'); | ||
|
|
||
| field.falseText = 'False Text'; | ||
| expect(getCurrentValueText(field, value, null)).toBe('False Text'); | ||
| }); | ||
|
|
||
| it('field.customizeText', () => { | ||
| const field: Field = { | ||
| customizeText(conditionInfo) { | ||
| return `${conditionInfo.valueText}Test`; | ||
| }, | ||
| }; | ||
| const value = 'MyValue'; | ||
|
|
||
| expect(getCurrentValueText(field, value, null)).toBe('MyValueTest'); | ||
| }); | ||
|
|
||
| it('customOperation.customizeText', () => { | ||
| const field: Field = { | ||
| customizeText(conditionInfo) { | ||
| return `${conditionInfo.valueText}Test`; | ||
| }, | ||
| }; | ||
| const value = 'MyValue'; | ||
| const customOperation: CustomOperation = { | ||
| customizeText(conditionInfo) { | ||
| return `${conditionInfo.valueText}CustomOperation`; | ||
| }, | ||
| }; | ||
|
|
||
| expect(getCurrentValueText(field, value, customOperation)).toBe('MyValueTestCustomOperation'); | ||
| }); | ||
|
|
||
| it('customOperation.customizeText for array', async () => { | ||
| const field: Field = { dataType: 'string' }; | ||
|
|
||
| const customOperation = { customizeText: (): string => '(Blanks)' }; | ||
| let text = await getCurrentValueText(field, '', customOperation); | ||
|
|
||
| expect(text).toBe(''); | ||
|
|
||
| text = await getCurrentValueText(field, [null], customOperation); | ||
| expect(text).toEqual(['(Blanks)']); | ||
|
|
||
| const field2: Field = { dataType: 'number' }; | ||
|
|
||
| text = await getCurrentValueText(field2, null, customOperation); | ||
|
|
||
| expect(text).toBe(''); | ||
|
|
||
| text = await getCurrentValueText(field, [null], customOperation); | ||
| expect(text).toEqual(['(Blanks)']); | ||
| }); | ||
|
|
||
| it('default format for date', () => { | ||
| const field: Field = { dataType: 'date' }; | ||
| const value = new Date(2017, 8, 5, 12, 30, 0); | ||
|
|
||
| expect(getCurrentValueText(field, value, null)).toBe('9/5/2017'); | ||
| }); | ||
|
|
||
| it('default format for datetime', () => { | ||
| const field: Field = { dataType: 'datetime' }; | ||
| const value = new Date(2017, 8, 5, 12, 30, 0); | ||
|
|
||
| expect(getCurrentValueText(field, value, null)).toBe('9/5/2017, 12:30 PM'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test name grammar: "Proper handle ..." → "Properly handle ...".