Skip to content

Commit af7d42e

Browse files
List: custom properties should be accessible in groupTemplate arguments(T1319741) (#32268)
1 parent fd3f7a1 commit af7d42e

File tree

2 files changed

+66
-1
lines changed
  • packages/devextreme

2 files changed

+66
-1
lines changed

packages/devextreme/js/__internal/data/data_converter/grouped.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const groupKey = 'key';
88
export function getDataSourceOptions<TItem>(
99
dataSource: DataSourceLike<TItem>,
1010
): DataSourceLike<TItem> | DataSourceOptions<GroupItem<TItem>> {
11-
if (!isGroupItemsArray<TItem>(dataSource)) {
11+
if (
12+
!isGroupItemsArray<TItem>(dataSource)
13+
|| (dataSource as GroupItem<TItem>[]).some((item) => Object.keys(item).length !== 2)
14+
) {
1215
return dataSource;
1316
}
1417

packages/devextreme/testing/tests/DevExpress.ui.widgets/listParts/commonTests.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3791,6 +3791,68 @@ QUnit.module('regressions', moduleSetup, () => {
37913791
done();
37923792
});
37933793
});
3794+
3795+
QUnit.test('custom properties should be preserved in grouped items (T1319741)', function(assert) {
3796+
const data = [
3797+
{ key: 'Group 1', items: [{ text: 'Item 1' }], customProp: 'customValue' }
3798+
];
3799+
3800+
const list = this.element.dxList({
3801+
dataSource: data,
3802+
grouped: true
3803+
}).dxList('instance');
3804+
3805+
const dataSourceItems = list.getDataSource().items();
3806+
3807+
assert.strictEqual(dataSourceItems.length, 1, 'One group loaded');
3808+
assert.strictEqual(dataSourceItems[0].key, 'Group 1', 'Key preserved');
3809+
assert.strictEqual(dataSourceItems[0].customProp, 'customValue', 'Custom property preserved');
3810+
});
3811+
3812+
QUnit.test('custom properties should be preserved in mixed grouped items (T1319741)', function(assert) {
3813+
const data = [
3814+
{ key: 'Group 1', items: [{ text: 'Item 1' }] },
3815+
{ key: 'Group 2', items: [{ text: 'Item 2' }], customProp: 'customValue' }
3816+
];
3817+
3818+
const list = this.element.dxList({
3819+
dataSource: data,
3820+
grouped: true
3821+
}).dxList('instance');
3822+
3823+
const dataSourceItems = list.getDataSource().items();
3824+
3825+
assert.strictEqual(dataSourceItems.length, 2, 'Two groups loaded');
3826+
3827+
assert.strictEqual(dataSourceItems[0].key, 'Group 1');
3828+
assert.strictEqual(dataSourceItems[1].key, 'Group 2');
3829+
assert.strictEqual(dataSourceItems[1].customProp, 'customValue', 'Custom property preserved in second group');
3830+
3831+
const $groups = $(list.element()).find(`.${LIST_GROUP_CLASS}`);
3832+
assert.strictEqual($groups.length, 2, 'Two groups rendered');
3833+
assert.strictEqual($groups.eq(1).find(`.${LIST_ITEM_CLASS}`).text(), 'Item 2', 'Item in second group rendered');
3834+
});
3835+
3836+
QUnit.test('custom properties should be available in groupTemplate (T1319741)', function(assert) {
3837+
const data = [
3838+
{ key: 'Group 1', customProp: 'customValue', items: [{ text: 'Item 1' }] }
3839+
];
3840+
3841+
const groupTemplateStub = sinon.stub().returns($('<div>'));
3842+
3843+
this.element.dxList({
3844+
dataSource: data,
3845+
grouped: true,
3846+
groupTemplate: groupTemplateStub
3847+
});
3848+
3849+
assert.strictEqual(groupTemplateStub.callCount, 1, 'Template was called once');
3850+
const groupItem = groupTemplateStub.getCall(0).args[0];
3851+
3852+
assert.strictEqual(groupItem.key, 'Group 1', 'Key is correct in template');
3853+
assert.ok(Object.prototype.hasOwnProperty.call(groupItem, 'customProp'), 'Custom property is present in group item');
3854+
assert.strictEqual(groupItem.customProp, 'customValue', 'Custom property value is correct');
3855+
});
37943856
});
37953857

37963858
QUnit.module('widget sizing render', {}, () => {

0 commit comments

Comments
 (0)