import * as React from 'react'; import { render } from 'react-dom'; import BootstrapTable, { ColumnFormatter, CellAlignment, HeaderFormatter, ColumnDescription, RowSelectionType, ROW_SELECT_SINGLE, } from 'react-bootstrap-table-next'; interface Product { id: number; name: string; price?: number; quality?: number; inStockStatus?: number; sales?: number; } const products: Product[] = [ { id: 1, name: 'Item name 1', price: 100, }, { id: 2, name: 'Item name 2', price: 100, }, ]; const priceHeaderFormatter: HeaderFormatter = (column, colIndex, components) => { return (
{column.text} {components.sortElement} {components.filterElement}
); }; const priceFormatter: ColumnFormatter = (cell, row, rowIndex) => { return ( {rowIndex} - {cell} ); }; const productColumns: Array> = [ { dataField: 'id', align: 'center', sort: true, text: 'Product ID' }, { dataField: 'name', align: 'center', sort: true, text: 'Product Name' }, { isDummyField: true, dataField: '', sort: true, text: 'Product Name', }, { dataField: 'price', sort: true, formatter: priceFormatter, text: 'Product Price', headerFormatter: priceHeaderFormatter, }, /** * test optional dataField for dummyFields */ { isDummyField: true, dataField: '', sort: true, formatter: priceFormatter, text: 'Product Price', headerFormatter: priceHeaderFormatter, }, ]; /** * Basic table test with custom header and cell formatters */ render( , document.getElementById('app'), ); /** * Inline untyped columns test */ render( Dummy Field, text: 'Dummy Columns', }, { dataField: 'price', sort: true, formatter: priceFormatter, text: 'Product Price', headerFormatter: priceHeaderFormatter, }, /** * test optional dataField for dummyFields */ { isDummyField: true, dataField: '', sort: true, formatter: priceFormatter, text: 'Product Price', headerFormatter: priceHeaderFormatter, }, ]} />, document.getElementById('app'), ); /** * Basic table with custom data indicator and caption */ render(
No data available
} caption={Amazing table} columns={productColumns} />, document.getElementById('app'), ); /** * Basic table with custom data indicator and caption */ render( , document.getElementById('app'), ); /** * Event handling table test */ render( { typeof row.inStockStatus === 'number'; }, onDoubleClick: (e, row, rowIndex) => {}, onMouseEnter: (e, row, rowIndex) => {}, onMouseLeave: (e, row, rowIndex) => {}, }} keyField="id" columns={productColumns} />, document.getElementById('app'), );