Issue with groupByField and refreshCell

Hi there,

I see a potential bug related to using groupByField. You can see it in action in your Feature Explorer.

First, I’m changing a record and then calling refreshCell with groupByField commented out here http://www.smartclient.com/docs/6.5/a/system/reference/SmartClient_Explorer.html#dynamicGrouping

isc.ListGrid.create({
    ID: "countryList",
    top:0,
    width:522, height:224,
    alternateRecordStyles:true, showAllRecords:true, cellHeight:22,
    dataSource: countryDS,
    // display a subset of fields from the datasource

    fields:[
        {name:"countryCode", title:"Flag", width:40, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png", canEdit:false},
        {name:"countryName"},
        {name:"government"},
        {name:"continent"}
    ],
    groupStartOpen:"all",
    //groupByField: 'continent',
 dataProperties: {dataArrived:function(startRow,endRow){var record = countryList.getRecord(0);record.countryName += "-test";var rowNum = countryList.getRecordIndex(record);countryList.refreshCell(rowNum,countryList.getColNum("countryName"));}},
    autoFetchData: true

})

The call to refreshCell, constructed using getRecordIndex and getColNum for the correct record works just fine. However, on this second try, we’ll re-enable the groupByField and the refreshCell does not work any more.

isc.ListGrid.create({
    ID: "countryList",
    top:0,
    width:522, height:224,
    alternateRecordStyles:true, showAllRecords:true, cellHeight:22,
    dataSource: countryDS,
    // display a subset of fields from the datasource

    fields:[
        {name:"countryCode", title:"Flag", width:40, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png", canEdit:false},
        {name:"countryName"},
        {name:"government"},
        {name:"continent"}
    ],
    groupStartOpen:"all",
    groupByField: 'continent',
 dataProperties: {dataArrived:function(startRow,endRow){var record = countryList.getRecord(0);record.countryName += "-test";var rowNum = countryList.getRecordIndex(record);countryList.refreshCell(rowNum,countryList.getColNum("countryName"));}},
    autoFetchData: true

})

Ok, I got a bit turned around on what my exact problem was here, I’ll admit it. It turns out the problem that tripped me up is that lengthIsKnown is not a recognized function when using groupByField. Is that by design?

The following on the same page returns a false when groupByField is enabled and a true when it is disabled:

isc.ListGrid.create({
    ID: "countryList",
    top:0,
    width:522, height:224,
    alternateRecordStyles:true, showAllRecords:true, cellHeight:22,
    dataSource: countryDS,
    // display a subset of fields from the datasource

    fields:[
        {name:"countryCode", title:"Flag", width:40, type:"image", imageURLPrefix:"flags/16/", imageURLSuffix:".png", canEdit:false},
        {name:"countryName"},
        {name:"government"},
        {name:"continent"}
    ],
    groupStartOpen:"all",
    groupByField: 'continent',
 dataProperties: {dataArrived:function(startRow,endRow){alert(isA.Function(countryList.data.lengthIsKnown));}},
    autoFetchData: true

})

Hi senordhuff,

When grouped, the groupTree becomes ListGrid.data, and the original dataset is available as listGrid.originalData. Trees/ResultTrees do not have a lengthIsKnown() function, this is expected but it might be a useful addition for uniformity anyway.

Does this help you fix your issue?

Hi, that is very useful information. I think this is a fairly dramatic change that could impact a lot of existing SmartClient code. It dramatically impacts our codebase. We are using lengthIsKnown, rowIsLoaded, and getRange in many places and always doing it against grid.data. So, I’ve had to go modify all that code to check the grid. This is the logic I’m using now prior to calling these functions:

	var dataSet=grid.data;
	if(grid.originalData!=null){
		dataSet=grid.originalData;
	}

This will ensure our logic is always using the resultSet and not using the resultTree. Do you anticipate any potential problems with that?

One question I have is whether calling invalidateCache() on grid.originalData will cause problems when a grid is grouped and thus grid.data is a ResultTree?

Also, can you confirm that any time you make changes to a grid when it is grouped and grid.data is a ResultTree, that those changes are captured in originalData as well? And, if you then ungroup, that grid.data will still persist those changes and not revert back to originalData that hasn’t been changed? I assume so but just want to avoid getting tripped up assuming that originalData will always reflect the current resultset even if data is changed when the grid has a grouping.

Sorry for all the questions but, like I said, I just had to change a lot of code to comply with these changes.

Hi senordhuff,

A better way to check for grouping is just listGrid.isGrouped.

We’d recommend calling ungroup() before invalidateCache().

Changes to either structure (groupTree or originalData) via databinding APIs (addData() et al) will be reflected in the other structure, and will persist.

A number of changes may be required to make existing code work with grouping if you have a lot of interactions with this.data. However remember that grouping is an optional feature that you can turn off globally (canGroupBy:false), and also consider that the way we approached it - replacing this.data with a Tree formed from the same records - allows lots of existing code for event handlers, hovers, editing, etc to work unchanged.

Thanks for the feedback, since it can potentially break existing this.data interactions, you might want to consider having the ListGrid default to canGroupBy:false and add some extra documentation regarding grouping and how it can cause problems with existing grid.data logic (especially here: http://www.smartclient.com/docs/6.5/a/b/c/go.html#attr..ListGrid.canGroupBy) .

That is your call though.

So, I am trying to create a “data” object that always points to the ResultSet and not to the ResultTree and thought it would make sense to check for the existence of originalData like I had in my code snippet. Should I perhaps use this snippet instead?

	var dataSet=grid.data;
	if(grid.isGrouped  && grid.originalData!=null){
		dataSet=grid.originalData;
	}

That doc has been expanded actually :slight_smile:

That code snippet is fine.