From 1dbbe2d718f09a4d5b1ab09f6e80d81777a17bb9 Mon Sep 17 00:00:00 2001 From: Konstantin Volnyagin Date: Thu, 30 Aug 2018 11:22:27 +0300 Subject: [PATCH] DataGrid: Fix dataType changing at runtime (T667936) (#5231) --- .../ui.grid_core.columns_controller.js | 2 +- .../columnsController.tests.js | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/js/ui/grid_core/ui.grid_core.columns_controller.js b/js/ui/grid_core/ui.grid_core.columns_controller.js index b5d8c0c04b2d..f029ece557c8 100644 --- a/js/ui/grid_core/ui.grid_core.columns_controller.js +++ b/js/ui/grid_core/ui.grid_core.columns_controller.js @@ -1123,7 +1123,7 @@ module.exports = { that._updateLockCount--; } that._columnChanges = undefined; - if(columnChanges.optionNames && (columnChanges.optionNames.dataField || columnChanges.optionNames.lookup)) { + if(columnChanges.optionNames && (columnChanges.optionNames.dataField || columnChanges.optionNames.lookup || columnChanges.optionNames.dataType)) { that.reinit(); } else { that.columnsChanged.fire(columnChanges); diff --git a/testing/tests/DevExpress.ui.widgets.dataGrid/columnsController.tests.js b/testing/tests/DevExpress.ui.widgets.dataGrid/columnsController.tests.js index b784a9f4104c..eff5f32897c4 100644 --- a/testing/tests/DevExpress.ui.widgets.dataGrid/columnsController.tests.js +++ b/testing/tests/DevExpress.ui.widgets.dataGrid/columnsController.tests.js @@ -4700,6 +4700,40 @@ QUnit.test("update column dataField", function(assert) { assert.strictEqual(columnsChangedArgs[0].optionNames.length, 1); }); +// T667936 +QUnit.test("change column dataType", function(assert) { + this.applyOptions({ columns: ["id", "orderDate"] }); + + var columnsChangedArgs = []; + + var items = [ + { id: 1, orderDate: "2018/08/30" }, + { id: 2, orderDate: "2018/08/31" } + ]; + + var dataSource = new DataSource(items); + + dataSource.load(); + + this.columnsController.applyDataSource(dataSource); + + this.columnsController.columnsChanged.add(function(e) { + columnsChangedArgs.push(e); + }); + + // act + this.columnsController.columnOption('orderDate', "dataType", "date"); + + // assert + assert.strictEqual(this.columnsController.getColumns()[1].dataField, "orderDate"); + assert.strictEqual(this.columnsController.getColumns()[1].dataType, "date"); + assert.deepEqual(this.columnsController.getColumns()[1].filterOperations, ["=", "<>", "<", ">", "<=", ">=", "between"]); + assert.deepEqual(this.columnsController.getColumns()[1].calculateCellValue(items[0]), new Date(2018, 7, 30), "calculateCellValue for field with changed dataType"); + assert.strictEqual(columnsChangedArgs.length, 1); + assert.strictEqual(columnsChangedArgs[0].optionNames.all, true); + assert.strictEqual(columnsChangedArgs[0].optionNames.length, 1); +}); + // T346972 QUnit.test("change column option validationRules at runtime", function(assert) { this.applyOptions({ columns: ["field1", "field2"] });