jeudi 16 octobre 2014

[4.2.2+] Grouping field update can lead group header to disappear

[4.2.2+] Grouping field update can lead group header to disappear

Ext Version tested:


  • Ext 4.2.2 rev 1144

  • Ext 4.2.3 rev 1477


Browser versions tested against: Description:
Set up a groupingsummary feature and update some of the records (the group by field). Depending on the order of appearance of the records the grouping header might disappear.

Code:



Code:



Ext.onReady(function () {
var store = Ext.create('Ext.data.Store', {
storeId: 'simpsonsStore',
fields: ['name', 'surname'],
groupField: 'surname',
data: {
'items': [
{ name: 'Homer', surname: 'Not Simpson' },
{ name: 'Lisa', surname: 'Simpson'},
{ name: 'Bart', surname: 'Not Simpson' },
{ name: 'Marge', surname: 'Simpson'}
]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}, sorters: {
property: 'name',
direction: 'DESC'
}
});




grid = Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: store,
features: [{
ftype: 'groupingsummary',
hideGroupedHeader: true,
startCollapsed: false,
showSummaryRow: false,
groupHeaderTpl: '{name}'
}],
columns: [
{ text: 'Name', dataIndex: 'name' , width: 300},
{ text: 'Surname', dataIndex: 'surname', width: 300 },
]
});




var groupstore = Ext.create('Ext.data.Store', {
fields: ['column'],
data: [
{ "column": "name" },
{ "column": "surname" }
]
});




var combo = Ext.create('Ext.button.Button', {
text: 'Update',
listeners: {
click: function () {
grid.getStore().data.each(function (record) {
record.set('surname', 'Not Simpson');
});
grid.getView().refresh();
}
}
});




Ext.create('Ext.container.Viewport', {
layout: 'border',
items: [{
items: combo,
region: 'north',
height: '50px'
}, {
region: 'center',
items: grid
}]
});
});



Just press the button 'Update' and it should happen.

The issue cannot be reproduced with versions available on fiddle. If you help me post a fiddle using 4.2.2 or 4.2.3 I can set it up.


The issue won't occur (in the above example):



  • if you change the sorter of the grid

  • if you change all records to 'Simpson'


Basically it depends on the index of the records being changed.

Possible fix (based on my investigation):


In class 'Ext.grid.feature.GroupStore', the onUpdate method adds the group as an attribute of the record, with this line:



Code:



groupInfo = record.group = me.groupingFeature.getRecordGroup(record);

but then might end up calling


Code:



return me.onRefresh(me.store);

which recreates the groups.

In this case the function setupRowData won't see the first record as a first because the group's children are not the updated ones.

If I move the line after, like this, the issue doesn't happen.



Code:



if (modifiedFieldNames && Ext.Array.contains(modifiedFieldNames, me.groupingFeature.getGroupField())) {
return me.onRefresh(me.store);
}


groupInfo = record.group = me.groupingFeature.getRecordGroup(record);

I'm not sure it doesn't break anything else though.



[4.2.2+] Grouping field update can lead group header to disappear

Aucun commentaire:

Enregistrer un commentaire