Had an interesting issue today

 

Question:

I'm been trying to get the reopen items feature to work  and I must have a basic misunderstanding. On the grid, I  have the following:


 

clearOpenItemsOnDataProviderChange = "false"
clearSelectionOnDataProviderChange = "false"
selectedKeyField="divisionUniqueKeyForSorts" 

As you can see from this first screenshot, the division root is the only item that has this unique key 
and, in fact, it does remember the open items when I refresh the dataprovider, just as I would like. However, whenever I try to select a single line which is needed in my app, it selects all the children.

-> Answer,
The fundamental issue here is that the requierment of a selectedKeyField - that it needs to be globally unique (across all children AND parents) is not being met. The selectedKeyField makes it easy for us to recognize "business equality" vs "object equality". From the docs:
"The selectedKeyField is a property on the object that identifies the object uniquely. Similar to a surrogate key, or a business key, as long as it uniquely identifies the object. When this property is set, the selected keys returns the ID values of the objects that were selected. When a row is selected in the grid, we store the selectedKeyField property of the selected object in this array collection. This allows for multiple pages of data that comes down from the server and not maintained in memory to still keep track of the ids that were selected on other pages."

This SAME concept is used to track which items stay open. In other words, if object with ID 1 is refreshed multiple times, even if it is a different object coming back from the server, it will stay open, because you have set selectedKeyField. 

But in this case, the requierment of a selectedKeyField - that it needs to be globally unique (across all children AND parents) is not being met. So the only option is to either introduce such a field that exists across all objects, (parents and children) and ensure iti is globally unique, or set
clearOpenItemsOnDataProviderChange = "true"
clearSelectionOnDataProviderChange = "true"
selectedKeyField="" 


And manually track openItems and selectedObjects across refreshes.