PDA

View Full Version : [FIXED] When inserting data into a store the listview group headers do not update



Sandy.Place
11 Oct 2011, 11:50 AM
After inserting data into my store, the the headers are trying to rebuild, The doRefreshHeaders function, looks up the header using an index property which is not defined:



doRefreshHeaders: function() {
var headerIndicis = this.previousHeaderIndices,
ln = headerIndicis.length,
items = this.getViewItems(),
headerInfo = this.pinHeaderInfo = {offsets: []},
headerOffsets = headerInfo.offsets,
i, headerItem, header;

if (ln) {
for (i = 0; i < ln; i++) {
// THIS IS USING index which is not defined
headerItem = items[headerIndicis[i].index];
// END OF COMMENT
header = this.getItemHeader(headerItem);

headerOffsets.push({
header: header,
offset: headerItem.element.dom.offsetTop
});

header.element.setVisibilityMode(Ext.Element.VISIBILITY);
}

headerInfo.headerHeight = header.element.getHeight();
headerInfo.closest = this.getClosestGroups();
this.setActiveGroup(headerInfo.closest.current);
}
},


I was able to fix this, though probably incorrectly by the following change to findGroupHeaderIndices



findGroupHeaderIndices: function () {
if (!this.getGrouped()) {
return;
}
var me = this,
store = me.getStore(),
groups = store.getGroups(),
groupLn = groups.length,
items = me.getViewItems(),
i = 0,
previousHeaderIndices = me.previousHeaderIndices,
previousIndexLn = previousHeaderIndices.length,
newHeaderIndices = [],
firstGroupedRecord, index, oldItemWithHeader;

// Add header to an item if needed
for (; i < groupLn; i++) {
firstGroupedRecord = groups[i].children[0];
index = store.indexOf(firstGroupedRecord);
if (previousHeaderIndices.indexOf(firstGroupedRecord) == -1) {
// I ADDED THIS TO FIX!!
firstGroupedRecord.index = index;
// END OF FIX
me.doAddHeader(items[index], store.getGroupString(firstGroupedRecord));
}
newHeaderIndices.push(firstGroupedRecord);
}

// Remove header from an item if needed
for (i = 0; i < previousIndexLn; i++) {
oldItemWithHeader = previousHeaderIndices[i];
if (newHeaderIndices.indexOf(oldItemWithHeader) == -1) {
oldItemWithHeader = items[store.indexOf(oldItemWithHeader)];
if (oldItemWithHeader) {
me.doRemoveHeader(oldItemWithHeader);
}
}
}

me.previousHeaderIndices = newHeaderIndices;
},


Thanks,
Sandy

Jamie Avins
11 Oct 2011, 12:15 PM
Nice catch, looks like something was cut out during a refactor. Will have this fixed for the next release. I'll also have to help someone spell headerIndicis - makes me cringe.