Skip to content

Commit

Permalink
ROU-4691: Column Filter does not reflect the correct value when using…
Browse files Browse the repository at this point in the history
… FilterByCondition API (#392)

* Convert text to number when setting filter to Number and Currency columns

* Fix eslint error

* Fix Filter api setting the filter to the wrong column with duplicated binding

* Fix sonarcloud issue
  • Loading branch information
OS-giulianasilva authored Jan 18, 2024
1 parent 6f484f7 commit 1974f49
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/OSFramework/DataGrid/Enum/ErrorMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace OSFramework.DataGrid.Enum {
AutoGenerateGridWrite = 'The auto generation of columns based on Data is not available when the Grid is editable. Please use ArrangeData action for this scenario.',
Column_NotFound = 'Column not found',
CustomizeExportingMessageEmptyString = 'It seems you are passing an empty message. Please pass a valid message.',
Filter_InvalidDataType = 'It seems you are trying to filter a Number/Currency column with a value that is not a number.',
FreezeColumnPositiveNumberExpected = 'Unable to freeze column. Please use a positive number.',
Grid_NotFound = 'Grid not found.',
InvalidColumnIdentifier = 'It seems you are not passing a valid column.',
Expand Down
31 changes: 27 additions & 4 deletions src/Providers/DataGrid/Wijmo/Features/ColumnFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,38 @@ namespace Providers.DataGrid.Wijmo.Feature {
const column = this._grid.getColumn(columnId);
if (column) {
const columnFilter = this._filter.getColumnFilter(
column.config.binding
column.provider
).conditionFilter;
const isNumericalColumn =
column.columnType ===
OSFramework.DataGrid.Enum.ColumnType.Calculated ||
column.columnType ===
OSFramework.DataGrid.Enum.ColumnType.Currency ||
column.columnType ===
OSFramework.DataGrid.Enum.ColumnType.Number;

if (values.length > 0) {
const condition1 = values[0];
const condition2 = values[1];

// If it is a numerical column and one of the conditions' value is not a number
// Then throw an error
if (
isNumericalColumn &&
(isNaN(parseFloat(condition1.value)) ||
(condition2 && isNaN(parseFloat(condition2.value))))
) {
throw new Error(
OSFramework.DataGrid.Enum.ErrorMessages.Filter_InvalidDataType
);
}

columnFilter.condition1.value =
this._getFilterConditionValue(
column.columnType,
condition1.value
isNumericalColumn
? parseFloat(condition1.value)
: condition1.value
);
columnFilter.condition1.operator =
wijmo.grid.filter.Operator[condition1.operatorTypeId];
Expand All @@ -210,7 +231,9 @@ namespace Providers.DataGrid.Wijmo.Feature {
columnFilter.condition2.value =
this._getFilterConditionValue(
column.columnType,
condition2.value
isNumericalColumn
? parseFloat(condition2.value)
: condition2.value
);
columnFilter.condition2.operator =
wijmo.grid.filter.Operator[
Expand Down Expand Up @@ -249,7 +272,7 @@ namespace Providers.DataGrid.Wijmo.Feature {
OSFramework.DataGrid.Enum.ColumnType.DateTime;

const columnFilter = this._filter.getColumnFilter(
column.config.binding
column.provider
).valueFilter;

// we receive values as an array ["Brazil", "Portugal"], but wijmo expects an object
Expand Down

0 comments on commit 1974f49

Please sign in to comment.