rallyappsdk2

Grouping WSAPI data store by Parent Name


I am creating a rallygrid component and would like to have the grid items grouped by their parent's Name attribute (bonus if I could also display the ID of the parent). I added the groupBy:'Parent' configuration to the storeConfig of the grid and was surprised that no results were returned. I also tried using groupBy:'Parent.Name' but still nothing.

I know this is possible with other fields such as Owner, but I'm at a loss as to why the Parent wouldn't be usable as well. Is this a bug, or am I setting the config up incorrectly?

Thanks


Solution

  • Change the storeConfig to keep the records from trying to update after being grouped:

    storeConfig : {
        remoteSort   : false,
        remoteGroup  : false,
        remoteFilter : false,
    }
    

    Add a listener to the load event which assigns a root level property to the record and groups by that record value. (For some reason store.group('Parent.Name'); doesn't work.)

    load: function(store) {
        store.each(function(record) {
            record.set('ParentName', record.get('Parent') && record.get('Parent').Name || '-- Unparented --');
        });
    
        store.group('ParentName');
    }