You're viewing the legacy site. Visit cxjs.io/docs for the latest documentation. Legacy site. Visit cxjs.io/docs for new docs.

Documentation

Report Edit

Column Resizing

Grid supports column resizing.

Name
Continent
Browser
OS
Visits
Chester TurcotteAustraliaEdgeMac OS15
Jairo LockmanAfricaChromeUbuntu83
Victor ProhaskaNorth AmericaInternet ExplorerAndroid3
Brayan MayerAsiaSafariMac OS41
Kylee SwiftSouth AmericaOperaAndroid50
Robyn StromanAfricaSafariWindows16
Oswaldo CrooksEuropeSafariMac OS69
Dejon KingAfricaInternet ExplorerAndroid2
Collin HickleAsiaInternet ExplorerAndroid52
Ignatius RohanAfricaInternet ExplorerUbuntu98
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