import * as React from 'react'; import styles from './VirtualTableExample.scss'; import IReactComponentProps from '../../../../common/structures/IReactComponentProps'; import Checkbox from '../../../inputs/Checkbox/Checkbox'; import FlySelect from '../../../inputs/FlySelect/FlySelect'; import Divider from '../../../layout/Divider/Divider'; import { IVirtualTableCellRendererDataArgs, VirtualTable, IVirtualTableRowRendererDataArgs } from '../VirtualTable'; interface IDataObject { index: number; name: string; selected: boolean; } type FormDataTypeValueType = 'objects' | 'arrays'; type FormRowHeightSizeType = 's' | 'm' | 'l'; type FormRowHeaderHeightSizeType = 'auto' | 's' | 'm' | 'l'; interface IVirtualTableExampleState { data: IVirtualTableExampleState['dataArrays'] | IVirtualTableExampleState['dataObjects'] | null; dataArrays: any[][]; dataObjects: IDataObject[]; formDataTypeValue: FormDataTypeValueType; formRowHeightSize: FormRowHeightSizeType; formRowHeaderHeightSize: FormRowHeaderHeightSizeType; headers: any[] | null; } export class VirtualTableExample extends React.Component { protected _idGenCountArrays: number; protected _idGenCountObjects: number; constructor (props: IReactComponentProps) { super(props); const createRowsCount: number = 100; this._idGenCountArrays = 0; this._idGenCountObjects = 0; this.state = { data: null, dataArrays: Array.from(Array(createRowsCount).keys()).map(() => ([++this._idGenCountArrays, 'array row ' + this._idGenCountArrays, this._idGenCountArrays % 2 === 0])), dataObjects: Array.from(Array(createRowsCount).keys()).map(() => ({index: ++this._idGenCountObjects, name: 'object row ' + this._idGenCountObjects, selected: this._idGenCountObjects % 2 === 1})), formDataTypeValue: 'objects', formRowHeightSize: 'l', formRowHeaderHeightSize: 'auto', headers: null, }; setTimeout (() => { this._onUpdateConfig(); }); }; protected _onUpdateConfig () { this.setState((state) => ({ data: state.formDataTypeValue === 'objects' ? this.state.dataObjects.concat([{selected: false, index: 999999999} as any]) // add incomplete object with keys in a different order : this.state.dataArrays.concat([[999999999, false]]) // add incomplete object , headers: state.formDataTypeValue === 'objects' ? [{key: 'index', value: 'Index', flex: '0 0 100px'}, {key: 'name', value: 'Object Name', flex: '1 1 400px'}, {key: 'selected', value: 'Is Selected', flex: '0 0 100px'}] : ['Index', 'Name', 'Selected'] , })); } protected _onChangeDataTypeValue = (value: FormDataTypeValueType) => { this.setState( () => ({ formDataTypeValue: value, }), this._onUpdateConfig, ); }; protected _onChangeRowHeightSize = (event: any) => { const value = event.currentTarget.value; this.setState(() => ({ formRowHeightSize: value, })); }; protected _onChangeRowHeaderHeightSize = (event: any) => { const value = event.currentTarget.value; this.setState(() => ({ formRowHeaderHeightSize: value, })); }; protected _cellRenderer = (dataArgs: IVirtualTableCellRendererDataArgs) => { if ((dataArgs.colKey !== 'selected' && dataArgs.colKey !== 2) || dataArgs.isHeader) { return null; } return ( ); }; render () { return (
Data source type:
Row height:
Row header height:
); }; }