Skip to content

Commit

Permalink
Release 16.2.11
Browse files Browse the repository at this point in the history
Cherry-picked changesets:
  3299f80 Dmitry Levkovskiy - Fix unexpected selection clearing on a dataSource changing (#1839)
  38f75fa Alyar - dxList: Fix "Select All"  incorrectly works with a filtered data source when selectAllMode is "allPages" (T567757) (#1820)
  • Loading branch information
BingoRUS committed Jan 25, 2018
1 parent f62f5a7 commit 28a9f17
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
Empty file modified drone-pr-workaround.sh
100755 → 100644
Empty file.
13 changes: 9 additions & 4 deletions js/ui/collection/ui.collection_widget.edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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();
Expand Down Expand Up @@ -224,9 +228,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;
Expand Down Expand Up @@ -573,7 +575,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":
Expand Down
14 changes: 14 additions & 0 deletions js/ui/list/ui.list.edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,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";
},
Expand Down
36 changes: 36 additions & 0 deletions testing/tests/DevExpress.ui.widgets/listParts/editingTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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($("<div>"), {
selectionMode: "multiple",
dataSource: [1, 2, 3],
Expand All @@ -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($("<div>"), {
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($("<div>"), {
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() {
Expand Down

0 comments on commit 28a9f17

Please sign in to comment.