Options
All
  • Public
  • Public/Protected
  • All
Menu

Customizable grid powered by CSS grid.

Example of usage

Grid with sticky header and server-side virtual scroll.

export const component: DraymanComponent = async ({ forceUpdate }) => {
    const data = [
        { name: 'Hydrogen', weight: 1.0079, symbol: 'H' },
        { name: 'Helium', weight: 4.0026, symbol: 'He' },
        { name: 'Lithium', weight: 6.941, symbol: 'Li' },
        { name: 'Beryllium', weight: 9.0122, symbol: 'Be' },
        { name: 'Boron', weight: 10.811, symbol: 'B' },
        { name: 'Carbon', weight: 12.0107, symbol: 'C' },
        { name: 'Nitrogen', weight: 14.0067, symbol: 'N' },
        { name: 'Oxygen', weight: 15.9994, symbol: 'O' },
        { name: 'Fluorine', weight: 18.9984, symbol: 'F' },
        { name: 'Neon', weight: 20.1797, symbol: 'Ne' },
    ];

    const columns = [{
        field: 'name',
        label: 'Name',
    }, {
        field: 'weight',
        label: 'Weight',
    }, {
        field: 'symbol',
        label: 'Symbol',
    }];

    let header = [
        {
            col: 0,
            row: 0,
            content: [{ type: 'text', value: 'name' }]
        },
        {
            col: 1,
            row: 0,
            content: [{ type: 'text', value: 'weight' }]
        },
        {
            col: 2,
            row: 0,
            content: [{ type: 'text', value: 'symbol' }]
        },
    ];
    header = header.map(x => ({ ...x, cellStyle: { position: 'sticky', backgroundColor: 'white', zIndex: 100, top: 0 } }));

    let grid = [];

    const onScroll = ({ currentRow, visibleRowCount }) => {
        const visibleData = data.slice(currentRow, currentRow + visibleRowCount);
        const visibleGridData = visibleData.map((x, i) => ([
            {
                col: 0,
                row: currentRow + i + 1,
                content: [{ type: 'text', value: x.name }],
            },
            {
                col: 1,
                row: currentRow + i + 1,
                content: [{ type: 'text', value: x.weight }],
            },
            {
                col: 2,
                row: currentRow + i + 1,
                content: [{ type: 'text', value: x.symbol }],
            },
        ])).flat();
        grid = [
            ...header,
            ...visibleGridData,
        ];
    };

    onScroll({ currentRow: 0, visibleRowCount: 5 });

    return () => <drayman-grid
        grid={grid}
        cellHeight={40}
        cellWidth={100}
        columnCount={3}
        rowCount={data.length + 1}
        onScroll={async ({ currentRow, visibleRowCount }) => {
            onScroll({ currentRow, visibleRowCount });
            await forceUpdate();
        }}
    />;
}

Hierarchy

Index

Properties

Optional cellHeight

cellHeight: number

Height of the cell. If not specified, cell height will automatically be calculated to fit a grid.

Optional cellWidth

cellWidth: number

Width of the cell. If not specified, cell width will automatically be calculated to fit a grid.

Optional changedWidthIndex

changedWidthIndex: ElementEvent<{ changedColumnWidthIndex: number; columnWidths: number[] }>

Index of the column that has been resized.

columnCount

columnCount: number

Optional columnWidths

columnWidths: number[]

Width of each column.

grid

grid: GridCell[]

Optional gridRef

gridRef: string

Optional onCellClick

onCellClick: ElementEvent<{ button: GridContentButton; cell: GridCell }>

Optional onContentButtonClick

onContentButtonClick: ElementEvent<{ cell: GridCell }>

Optional onContextMenuItemClick

onContextMenuItemClick: ElementEvent<{ cell: GridCell; label: string }>

Optional onLoad

onLoad: ElementEvent<{ currentCol: number; currentRow: number; visibleColCount: number; visibleRowCount: number }>

Optional onScroll

onScroll: ElementEvent<{ currentCol: number; currentRow: number; visibleColCount: number; visibleRowCount: number }>

Optional onSelectedCellsChange

onSelectedCellsChange: ElementEvent<{ clearPrevious: boolean; selectedCells: GridCell[] }>

Optional ref

ref: string

rowCount

rowCount: number

Optional rowHoverStyle

rowHoverStyle: any

Optional scrollDirection

scrollDirection: "vertical" | "horizontal"

Optional scrollbarWidth

scrollbarWidth: "narrow" | "medium" | "wide"

Width of the scrollbar. Default is narrow - 8px. Medium is 12px and wide is 16px.

Optional selectedCells

selectedCells: GridCell[]

Optional selectionMode

selectionMode: { cellStyle?: any; enabled: boolean }

Type declaration

  • Optional cellStyle?: any
  • enabled: boolean

Optional style

style: CSS