import * as React from 'react'; import { Grid, GridToolbar, GridColumn as Column, GridColumnProps, GridToolbarColumnsChooser, GridToolbarGroup } from '@progress/kendo-react-grid'; import products from './products'; import { GroupDescriptor } from '@progress/kendo-data-query'; import { ToolbarSpacer } from '@progress/kendo-react-buttons'; interface GridColumnExtendedProps extends GridColumnProps { minWidth: number; } const columns: Array = [ { field: 'ProductID', title: 'ID', minWidth: 50 }, { field: 'ProductName', title: 'Product Name', minWidth: 200 }, { field: 'Category.CategoryName', title: 'Category Name', minWidth: 100 }, { field: 'Discontinued', title: 'Discontinued', filter: 'boolean', minWidth: 120 } ]; const ADJUST_PADDING: number = 4; const COLUMN_MIN: number = 4; const initialGroup: GroupDescriptor[] = [{ field: 'Category.CategoryName' }]; const App = () => { const minGridWidth = React.useRef(0); const grid = React.useRef(null); const [applyMinWidth, setApplyMinWidth] = React.useState(false); const [gridCurrent, setGridCurrent] = React.useState(0); React.useEffect(() => { grid.current = document.querySelector('.k-grid'); window.addEventListener('resize', handleResize); columns.map((item: any) => item.minWidth !== undefined ? (minGridWidth.current += item.minWidth) : minGridWidth.current ); setGridCurrent(grid.current.offsetWidth); setApplyMinWidth(grid.current.offsetWidth < minGridWidth.current); }, []); const handleResize = () => { if (grid.current.offsetWidth < minGridWidth.current && !applyMinWidth) { setApplyMinWidth(true); } else if (grid.current.offsetWidth > minGridWidth.current) { setGridCurrent(grid.current.offsetWidth); setApplyMinWidth(false); } }; const setWidth = (minWidth: number | undefined) => { if (minWidth === undefined) { minWidth = 0; } let width = applyMinWidth ? minWidth : minWidth + (gridCurrent - minGridWidth.current) / columns.length; if (width >= COLUMN_MIN) { width -= ADJUST_PADDING; } return width; }; return ( {columns.map((column, index) => { return ( ); })} ); }; export default App;