solutionforest / filament-tree

Filament Tree is a plugin for Filament Admin that creates a model management page with a heritage tree structure view. This plugin can be used to create menus and more.
MIT License
136 stars 45 forks source link

Tree node collapsed state #10

Closed skoro closed 1 year ago

skoro commented 1 year ago

This PR lets you control the node collapsed state as well as the default tree collapsed state. For example, for long trees it's better to have them initially collapsed to overview all the root nodes and manually expand some nodes.

By default, collapsed is false but overriding resource's getNodeCollapsedState() method, user can set a whole tree as collapsed or selectively collapse nodes:

    public function getNodeCollapsedState(?Model $record = null): bool
    {
        // All the tree nodes will be collapsed.
        // return true;

        // Collapsed will be a node with id 3.
        // return $record->id == 3;

       // The tree nodes will be expanded.
       return false;
    }