Documentation

Report Edit

Column Resizing

Grid supports column resizing.

Name
Continent
Browser
OS
Visits
Lue BrakusNorth AmericaSafariUbuntu57
Nat SchneiderSouth AmericaOperaiOS7
Llewellyn GulgowskiAsiaInternet ExplorerAndroid60
Nyah SchmidtAfricaOperaUbuntu34
Martin SchowalterAustraliaChromeAndroid10
Enola BotsfordSouth AmericaSafariAndroid38
Abbigail TremblayAsiaSafariAndroid56
Estel StoltenbergAsiaInternet ExploreriOS33
Clyde GrantSouth AmericaOperaUbuntu25
Anabel WeberAsiaFirefoxMac OS61
Name
Continent
Browser
OS
Visits

To enable resizing on a column, set the resizable flag to true.

If columns widths need to be persisted, add the width binding or use grid's onColumnResize event to process new measures. Use defaultWidth to set the initial width. These properties should be defined in the header object, but they can also be set on the column itself if there is only one header.

Double clicking on a resizer will calculate minimum width required to fit the content of the column.

Default column widths can be restored by clearing both column widths store and grid instance colWidth state. You can reset the default column widths by clearing both the column widths store and the Grid instance's colWidth state. To clear the colWidth state, maintain the grid instance using the onRef callback and apply the setState method.

ControllerGrid
<Grid
    records-bind="$page.records"
    columns={[
        {
            header: {
                text: "Name",
                width: bind('$page.colWidth.fullName'),
                resizable: true,
                defaultWidth: 200
            },
            field: "fullName",
            sortable: true
        },
        {
            header: "Continent",
            width: bind('$page.colWidth.continent'),
            resizable: true,
            field: "continent",
            sortable: true
        },
        {
            header: "Browser",
            width: bind('$page.colWidth.browser'),
            resizable: true,
            field: "browser",
            sortable: true
        },
        {
            header: "OS",
            width: bind('$page.colWidth.os'),
            resizable: true,
            field: "os",
            sortable: true
        },
        {
            header: "Visits",
            width: bind('$page.colWidth.visits'),
            resizable: false,
            field: "visits",
            sortable: true,
            align: "right"
        }
    ]}
    scrollable
    style="max-height: 400px; margin-bottom: 10px"
    onRef={(el, instance) => {
        instance.controller.gridInstance = instance;
    }}
/>

<Button
    text="Reset column widths"
    onClick={(e, {store, controller}) => {
        controller.gridInstance.setState({ colWidth: {} });
        store.delete('$page.colWidth');
    }}
/>
Copied!Cx Fiddle