Premium support for our pure JavaScript UI components


Post by Josh Argent »

Hi,

We would like to initialise our tree grid with all the rows expanded. I see there is an expanded property on Grid.data.GridRowModel however it is just a getter.

In the Tree Grid example in the documentation, the data is set with rows that have expanded set to true. I can't find this property documented anywhere besides that example.

Please can you advise on the best option?


Post by mats »

It's a field https://bryntum.com/docs/grid/api/Grid/data/GridRowModel#field-expanded so you can put this in your data. Or call https://bryntum.com/docs/grid/api/Grid/feature/Tree#function-expandAll after you've loaded your initial data.


Post by Josh Argent »

Okay, so using myRecord.expanded = true; fails because we're trying to set a getter. But myRecord.data.expanded = true; seems to work so long as we do that before inserting the record into the store. Does that seem reasonable?


Post by mats »

Yes, the expanded field lets you set the expanded value in the data you load. I recommend against writing any code using record.data since it's a private member.

It sounds more fitting in your case to simply call expandAll after loading IMHO.


Post by Josh Argent »

I was afraid that would be the case. I guess we will use the expandAll instead.

It would be great if there was a way of setting the default expand/collapse state on the model itself, perhaps a static property called initiallyExpanded?


Post by Josh Argent »

Actually it looks like I can set a default using defaults!

static get defaults() {
    return {
        expanded: true
    };
}

Post by mats »

Yep that works too!


Post Reply