PDA

View Full Version : [FIXED] Cannot edit grouped field in grid



cnelissen
28 Dec 2012, 10:06 AM
If you setup a grid with a grouped field, and then edit that grouped field, with a row editor for example, you will get an error. The same code runs fine with 4.1.1a.

To reproduce, try to change the "Group" column from "Group 1" to "Group 2".



<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ext4 Test File</title>
<link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
<script src="../../ext-all-debug.js"></script>
<script>
Ext.onReady(function() {
Ext.define('GroupItems', {
extend: 'Ext.data.Model',

fields: [
{name: 'group', type: 'string'},
{name: 'description', type: 'string'},
{name: 'notes', type: 'string'}
]
});

var viewport = Ext.create('Ext.Viewport', {
layout: 'fit',
items: [{
xtype: 'gridpanel',
store: Ext.create('Ext.data.Store', {
model: 'GroupItems',
data: [{
'group': 'Group 1',
'description': 'Test Description 1',
'notes': 'Test Notes 1'
},{
'group': 'Group 1',
'description': 'Test Description 2',
'notes': 'Test Notes 2'
}],
sorters: [{property: 'group', direction: 'ASC'}],
groupField: 'group'
}),

plugins: [{
ptype: 'rowediting',
clicksToEdit: 1
}],

features: [{
ftype: 'grouping',
id: 'groupingfeature'
}],

columns: [{
text: 'Group',
dataIndex: 'group',
editor: {
xtype: 'textfield',
allowBlank: false
},
width: 125
},{
text: 'Description',
dataIndex: 'description',
editor: {
xtype: 'textfield',
allowBlank: false
},
width: 125
},{
text: 'Notes',
dataIndex: 'notes',
editor: {
xtype: 'textfield',
allowBlank: false
},
flex: 1
}]
}]
});
});
</script>
</head>
<body>
</body>
</html>


I tracked down the error to the Ext.data.Store.updateGroupsOnUpdate function. If the grouped field is the first field in the set, or if it is the only field that was modified, then Ext.Array.indexOf returns '0', and the if statement is evaluated as false, which means the new group value is never added. Fix is below:



updateGroupsOnUpdate: function(record, modifiedFieldNames){
var me = this,
groupField = me.getGroupField(),
groupName = record.get(groupField),
groups = me.groups,
len, i, items, group;

if (modifiedFieldNames && Ext.Array.indexOf(modifiedFieldNames, groupField)!== -1) { // <-- Added !== -1 here

items = groups.items;
for (i = 0, len = items.length; i < len; ++i) {
group = items[i];
if (group.contains(record)) {
group.remove(record);
break;
}
}
groups.getByKey(groupName);
if (!group) {
group = groups.add(new Ext.data.Group({
key: groupName,
store: me
}));
}
group.add(record);
} else {

groups.getByKey(groupName).setDirty();
}
}

evant
28 Dec 2012, 2:36 PM
Thanks for the report! I have opened a bug in our bug tracker.