open-row
Description
Fires when opening (expanding) a rowThe action can be triggered if the treetoggle parameter of the columns property is enabled.
Usage
"open-row": ({
    id: string | number,
    nested?: boolean,
    eventSource?: string
}) => boolean|void;
Parameters
The callback of the action takes an object with the following parameters:
id- (required) the id of a row that have nested rowsnested- (optional) if set to true, all nested items will be expandedeventSource- (optional) the name of the Grid action that triggeredopen-row
note
If id is set to 0 and nested to true, all rows in the table will be expanded
Example
In the example below we make all rows expand on a button click. To do this, we get access to the Grid api via the bind:this construct and use the api.exec() method to trigger the open-rowaction on a button click.
Example:
<script>
    import { Button } from "@svar-ui/svelte-core"; // import the Button component
    import { Grid } from "@svar-ui/svelte-grid";
    const treeData = [
        {
            id: 1,
            city: "Amieshire",
            firstName: "Ernest",
            lastName: "Schuppe",
            open: false,
            data: [
                {
                    id: "1.1",
                    city: "Gust",
                    firstName: "Janis",
                    lastName: "Vandervort",
                },
                {
                    id: "1.2",
                    city: "Amieshire",
                    firstName: "Makenzie",
                    lastName: "Bode",
                },
            ],
        },
        {
            id: 2,
            city: "Amieshire",
            firstName: "Ciara",
            lastName: "Towne",
            data: [
                {
                    id: "2.1",
                    city: "Amieshire",
                    firstName: "Suzanne",
                    lastName: "Wolff",
                },
                {
                    id: "2.2",
                    city: "Amieshire",
                    firstName: "Alessandra",
                    lastName: "Feeney",
                },
            ],
        },
    ];
    const treeColumns = [
        { id: "id", width: 80 },
        {
            id: "lastName",
            header: "Last Name",
            flexgrow: 1,
            treetoggle: true, // make rows collapsible
        },
        {
            id: "firstName",
            header: "First Name",
            treetoggle: true, // make rows collapsible
            width: 150,
        },
        {
            id: "city",
            width: 100,
            header: "City",
            footer: "City",
        },
    ];
    let api = $state();
    function openAll() {
        api.exec("open-row", { id: 0, nested: true });
    }
</script>
<Button type="primary" onclick={() => openAll()}>Open all</Button>
    
<Grid
    bind:this={api}
    tree={true}
    data={treeData}
    columns={treeColumns} />
Related articles: