From b36cfcde7da699706f4776a80a8d95753bc54682 Mon Sep 17 00:00:00 2001 From: BingoRUS Date: Thu, 25 Jan 2018 17:30:53 +0300 Subject: [PATCH] Release 17.1.8 Cherry-picked changesets: 0a52758 Dmitry Levkovskiy - Fix unexpected selection clearing on a dataSource changing (#1840) 234790c Alyar - dxList: Fix "Select All" incorrectly works with a filtered data source when selectAllMode is "allPages" (T567757) (#1819) --- drone-pr-workaround.sh | 0 js/ui/collection/ui.collection_widget.edit.js | 13 +++++-- js/ui/list/ui.list.edit.js | 14 +++++++ .../listParts/editingTests.js | 36 ++++++++++++++++++ .../collectionWidgetParts/editingTests.js | 38 ++++++++++++++++++- 5 files changed, 96 insertions(+), 5 deletions(-) mode change 100755 => 100644 drone-pr-workaround.sh diff --git a/drone-pr-workaround.sh b/drone-pr-workaround.sh old mode 100755 new mode 100644 diff --git a/js/ui/collection/ui.collection_widget.edit.js b/js/ui/collection/ui.collection_widget.edit.js index 5784b1d7b48a..e704a570f942 100644 --- a/js/ui/collection/ui.collection_widget.edit.js +++ b/js/ui/collection/ui.collection_widget.edit.js @@ -198,6 +198,10 @@ var CollectionWidget = BaseCollectionWidget.inherit({ return !!(this._dataSource && this._dataSource.key()); }, + _getCombinedFilter: function() { + return this._dataSource && this._dataSource.filter(); + }, + keyOf: function(item) { var key = item, store = this._dataSource && this._dataSource.store(); @@ -225,9 +229,7 @@ var CollectionWidget = BaseCollectionWidget.inherit({ that._updateSelectedItems(args.addedItems, args.removedItems); } }, - filter: function() { - return that._dataSource && that._dataSource.filter(); - }, + filter: that._getCombinedFilter.bind(that), totalCount: function() { var items = that.option("items"); var dataSource = that._dataSource; @@ -572,7 +574,10 @@ var CollectionWidget = BaseCollectionWidget.inherit({ } break; case "dataSource": - this.option("selectedItemKeys", []); + if(!args.value || !args.value.length) { + this.option("selectedItemKeys", []); + } + this.callBase(args); break; case "selectedIndex": diff --git a/js/ui/list/ui.list.edit.js b/js/ui/list/ui.list.edit.js index 7d7dcc4969ce..ea466c3051d7 100644 --- a/js/ui/list/ui.list.edit.js +++ b/js/ui/list/ui.list.edit.js @@ -281,6 +281,20 @@ var ListEdit = ListBase.inherit({ } }, + _getCombinedFilter: function() { + var filter, + storeLoadOptions, + dataSource = this._dataSource; + + if(dataSource) { + storeLoadOptions = { filter: dataSource.filter() }; + dataSource._addSearchFilter(storeLoadOptions); + filter = storeLoadOptions.filter; + } + + return filter; + }, + _isPageSelectAll: function() { return this.option("selectAllMode") === "page"; }, diff --git a/testing/tests/DevExpress.ui.widgets/listParts/editingTests.js b/testing/tests/DevExpress.ui.widgets/listParts/editingTests.js index d50fcd496eaa..7cad70651e42 100644 --- a/testing/tests/DevExpress.ui.widgets/listParts/editingTests.js +++ b/testing/tests/DevExpress.ui.widgets/listParts/editingTests.js @@ -505,6 +505,42 @@ QUnit.test("selection works well after clean all selected items and selectAllMod assert.equal(selectionChangedSpy.callCount, 3, "'selectionChanged' event has been fired 3 times"); }); +//T567757 +QUnit.test("Selecting all filtered items when selectAllMode is 'allPages'", function(assert) { + //arrange + var items = [1, 2, 3, 4, 5], + $selectAll, + ds = new DataSource({ + store: items, + pageSize: 2, + paginate: true, + searchValue: "1" + }); + + var instance = $("#list").dxList({ + dataSource: ds, + showSelectionControls: true, + selectionMode: "all", + selectAllMode: "allPages" + }).dxList("instance"); + + //act + instance.selectItem(0); + + //assert + $selectAll = $("#list").find(".dx-list-select-all-checkbox"); + assert.ok($selectAll.hasClass("dx-checkbox-checked"), "selectAll checkbox is checked"); + assert.deepEqual(instance.option("selectedItems"), [1], "selected items"); + + //act + ds.searchValue(""); + ds.load(); + + //assert + $selectAll = $("#list").find(".dx-list-select-all-checkbox"); + assert.ok($selectAll.hasClass("dx-checkbox-indeterminate"), "selectAll checkbox is indeterminate"); +}); + var LIST_ITEM_SELECTED_CLASS = "dx-list-item-selected"; QUnit.module("selecting in grouped list", { diff --git a/testing/tests/DevExpress.ui/collectionWidgetParts/editingTests.js b/testing/tests/DevExpress.ui/collectionWidgetParts/editingTests.js index f4c2c8c53225..e3b390137c01 100644 --- a/testing/tests/DevExpress.ui/collectionWidgetParts/editingTests.js +++ b/testing/tests/DevExpress.ui/collectionWidgetParts/editingTests.js @@ -551,7 +551,7 @@ var runTests = function() { } }); - QUnit.test("selectedItems should be cleared if datasource instance has been changed", function(assert) { + QUnit.test("selectedItems should be cleared if datasource instance has been changed to null", function(assert) { var instance = new TestComponent($("
"), { selectionMode: "multiple", dataSource: [1, 2, 3], @@ -569,6 +569,42 @@ var runTests = function() { assert.deepEqual(instance.option("selectedItemKeys"), [], "selectedItemKeys was cleared"); }); + QUnit.test("selectedItems should be cleared if datasource instance has been changed to empty array", function(assert) { + var instance = new TestComponent($("
"), { + selectionMode: "multiple", + dataSource: [1, 2, 3], + selectedItemKeys: [1, 2] + }); + + assert.deepEqual(instance.option("selectedItems"), [1, 2], "selectedItems is correct"); + assert.deepEqual(instance.option("selectedItem"), 1, "selectedItem is correct"); + assert.deepEqual(instance.option("selectedItemKeys"), [1, 2], "selectedItem is correct"); + + instance.option("dataSource", []); + + assert.deepEqual(instance.option("selectedItems"), [], "selectedItems was cleared"); + assert.strictEqual(instance.option("selectedItem"), undefined, "selectedItem was cleared"); + assert.deepEqual(instance.option("selectedItemKeys"), [], "selectedItemKeys was cleared"); + }); + + QUnit.test("selectedItems should not be cleared if datasource instance has been changed", function(assert) { + var instance = new TestComponent($("
"), { + selectionMode: "multiple", + dataSource: [1, 2, 3], + selectedItemKeys: [1, 2] + }); + + assert.deepEqual(instance.option("selectedItems"), [1, 2], "selectedItems is correct"); + assert.deepEqual(instance.option("selectedItem"), 1, "selectedItem is correct"); + assert.deepEqual(instance.option("selectedItemKeys"), [1, 2], "selectedItem is correct"); + + instance.option("dataSource", [1, 2, 3, 4]); + + assert.deepEqual(instance.option("selectedItems"), [1, 2], "selectedItems wasn't cleared"); + assert.strictEqual(instance.option("selectedItem"), 1, "selectedItem wasn't cleared"); + assert.deepEqual(instance.option("selectedItemKeys"), [1, 2], "selectedItemKeys wasn't cleared"); + }); + QUnit.module("selecting of item keys", { beforeEach: function() {