mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* react-bootstrap-table-next: add initial typings * [name react-bootstrap-table2] add modules * [react-bootstrap-table-next] add filter example * [react-bootstrap-table2-filter] add filter example * [react-bootstrap-table-next] update types - loosen table typing after testing with real life projects - remove enums in favour of constant declarations and aggregation types * [react-bootstrap-table-next] fix cell align type * [react-bootstrap-table-next] update tests * [react-bootstrap-table2-toolkit] narrow types * [react-bootstrap-table-next] fix test column * [react-bootstrap-table2-filter] update comments * [react-bootstrap-table-next] fix documentation * [react-bootstrap-table2-filter] fix typo in header * [react-bootstrap-table-next] fix issues * [react-bootstrap-table-next] add definitions - expand toolkit definitions - add standalone pagination component types * [react-bootstrap-table-next] loosen column type * update typescript version * fix: typescript version mixup * fix: remove optional chaining, change TS version
105 lines
2.6 KiB
TypeScript
105 lines
2.6 KiB
TypeScript
import * as React from 'react';
|
|
import BootstrapTable, {
|
|
CellAlignment,
|
|
ColumnDescription,
|
|
HeaderFormatter,
|
|
ColumnFormatter,
|
|
} from 'react-bootstrap-table-next';
|
|
import paginationFactory from 'react-bootstrap-table2-paginator';
|
|
import { render } from 'react-dom';
|
|
import ToolkitProvider, { InjectedSearchProps } from 'react-bootstrap-table2-toolkit';
|
|
|
|
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<Product> = (column, colIndex, components) => {
|
|
return (
|
|
<div>
|
|
{column.text}
|
|
{components.sortElement}
|
|
{components.filterElement}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const priceFormatter: ColumnFormatter<Product, { indexSquare: number }> = (cell, row, rowIndex) => {
|
|
return (
|
|
<span>
|
|
{rowIndex} - {cell}
|
|
</span>
|
|
);
|
|
};
|
|
|
|
const productColumns: Array<ColumnDescription<Product>> = [
|
|
{ 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,
|
|
},
|
|
];
|
|
|
|
/**
|
|
* Toolkit with custom search test test
|
|
*/
|
|
|
|
const CustomSearch = (props: InjectedSearchProps) => {
|
|
return (
|
|
<span>
|
|
<input value={props.searchText} onChange={e => props.onSearch(e.currentTarget.value)} />
|
|
<button onClick={props.onClear}>Clear Search</button>
|
|
</span>
|
|
);
|
|
};
|
|
|
|
render(
|
|
<ToolkitProvider data={products} keyField="id" columns={productColumns}>
|
|
{({ baseProps, searchProps }) => (
|
|
<>
|
|
<CustomSearch {...searchProps} />
|
|
<BootstrapTable {...baseProps} pagination={paginationFactory({ sizePerPage: 10, page: 1 })} />
|
|
</>
|
|
)}
|
|
</ToolkitProvider>,
|
|
document.getElementById('app'),
|
|
);
|