mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 05:30:05 +00:00
Compare commits
40 Commits
react-boot
...
react-boot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae4f503b30 | ||
|
|
0e7c145f96 | ||
|
|
a07b2da00a | ||
|
|
2068f518f6 | ||
|
|
47d6eb097a | ||
|
|
76f4795400 | ||
|
|
ee829eb924 | ||
|
|
ae34c44547 | ||
|
|
b99a277595 | ||
|
|
1d13565824 | ||
|
|
3d37a31103 | ||
|
|
f4f6649b91 | ||
|
|
8ecdbf611b | ||
|
|
4a340c714b | ||
|
|
4daa5ef4d7 | ||
|
|
acb9c9f61e | ||
|
|
6d13a86512 | ||
|
|
b5d536b8f4 | ||
|
|
e667317fbe | ||
|
|
d4ffc11f7e | ||
|
|
3c6aaacbce | ||
|
|
defcd04b52 | ||
|
|
5a44384e3c | ||
|
|
ec742a43f6 | ||
|
|
7138b68559 | ||
|
|
e6e7d6f9d2 | ||
|
|
909a6e211e | ||
|
|
83c9d69e27 | ||
|
|
aad2ad3823 | ||
|
|
9190cfc6d9 | ||
|
|
45b133579b | ||
|
|
970f7c0d15 | ||
|
|
def898f636 | ||
|
|
be916d81a3 | ||
|
|
49d1ce8812 | ||
|
|
18caf0ac8d | ||
|
|
1b9bd63370 | ||
|
|
b2121fdf24 | ||
|
|
4aaf140de5 | ||
|
|
569aa0195e |
@@ -28,10 +28,12 @@
|
||||
* [rowClasses](#rowClasses)
|
||||
* [rowEvents](#rowEvents)
|
||||
* [hiddenRows](#hiddenRows)
|
||||
* [sort](#sort)
|
||||
* [defaultSorted](#defaultSorted)
|
||||
* [defaultSortDirection](#defaultSortDirection)
|
||||
* [pagination](#pagination)
|
||||
* [filter](#filter)
|
||||
* [filterPosition](filterPosition)
|
||||
* [onTableChange](#onTableChange)
|
||||
* [onDataSizeChange](#onDataSizeChange)
|
||||
|
||||
@@ -198,6 +200,27 @@ const hiddenRows = [1, 4];
|
||||
<BootstrapTable data={ data } columns={ columns } hiddenRows={ hiddenRows } />
|
||||
```
|
||||
|
||||
### <a name='sort'>sort - [Object]</a>
|
||||
Two cases you probably need to configure `sort` prop:
|
||||
|
||||
#### Manage sorting state
|
||||
You can give `dataField` and `order` to specify the sorting state in table, For example
|
||||
|
||||
```js
|
||||
<BootstrapTable sort={ { dataField: 'price', order: 'asc' } }>
|
||||
```
|
||||
|
||||
#### One-time sorting configuration
|
||||
In earily version, we only can configure [`sortCaret`](./columns.md#sortCaret) and [`sortFunc` ](./columns.md#sortFunc) per column. But they are same in most of cases.
|
||||
So here we give you a chance to just setup these prop in one time.
|
||||
|
||||
```js
|
||||
<BootstrapTable sort={ {
|
||||
sortCaret: ...
|
||||
sortFunc: ...
|
||||
} }>
|
||||
```
|
||||
|
||||
### <a name='defaultSorted'>defaultSorted - [Array]</a>
|
||||
`defaultSorted` accept an object array which allow you to define the default sort columns when first render.
|
||||
|
||||
@@ -208,6 +231,8 @@ const defaultSorted = [{
|
||||
}];
|
||||
```
|
||||
|
||||
**Note**: Only the first column is sorted currently, see #1083.
|
||||
|
||||
### <a name='defaultSortDirection'>defaultSortDirection - [String]</a>
|
||||
Default sort direction when user click on header column at first time, available value is `asc` and `desc`. Default is `desc`.
|
||||
|
||||
@@ -327,6 +352,9 @@ Following is a shape of `newState`
|
||||
}
|
||||
```
|
||||
|
||||
### <a name='filterPosition'>filterPosition - [String]</a>
|
||||
Available value is `inline`, `top` and `bottom`, default is `inline`. This prop decide where `react-bootstrap-table` render column filter.
|
||||
|
||||
### <a name='onDataSizeChange'>onDataSizeChange - [Function]</a>
|
||||
This callback function will be called only when data size change by search/filter etc. This function have one argument which is an object contains below props:
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
# Row selection
|
||||
`react-bootstrap-table2` supports the row selection feature. By passing prop `selectRow` to enable row selection. When you enable this feature, `react-bootstrap-table2` will prepend a new selection column.
|
||||
`react-bootstrap-table2` supports the row selection feature. By passing prop `selectRow` to enable row selection. When you enable this feature, `react-bootstrap-table2` will prepend a new selection column.
|
||||
|
||||
## Required
|
||||
* [mode (**required**)](#mode)
|
||||
@@ -11,6 +11,8 @@
|
||||
* [classes)](#classes)
|
||||
* [bgColor](#bgColor)
|
||||
* [nonSelectable)](#nonSelectable)
|
||||
* [nonSelectableStyle](#nonSelectableStyle)
|
||||
* [nonSelectableClasses](#nonSelectableClasses)
|
||||
* [clickToSelect)](#clickToSelect)
|
||||
* [clickToExpand)](#clickToExpand)
|
||||
* [clickToEdit](#clickToEdit)
|
||||
@@ -139,6 +141,54 @@ const selectRow = {
|
||||
};
|
||||
```
|
||||
|
||||
### <a name='nonSelectableStyle'>selectRow.nonSelectableStyle - [Object | Function]</a>
|
||||
This prop allow you to customize the non selectable rows. `selectRow.nonSelectableStyle` accepts an style object
|
||||
and a callback function for more flexible customization.
|
||||
|
||||
### Style Object
|
||||
|
||||
```js
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
nonSelectable: [1, 3 ,5],
|
||||
nonSelectableStyle: { backgroundColor: 'gray' }
|
||||
};
|
||||
```
|
||||
|
||||
### Callback Function
|
||||
|
||||
```js
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
nonSelectable: [1, 3 ,5],
|
||||
nonSelectableStyle: (row, rowIndex) => { return ...; }
|
||||
};
|
||||
```
|
||||
|
||||
### <a name='nonSelectableClasses'>selectRow.nonSelectableClasses - [String | Function]</a>
|
||||
This prop allow you to set a custom class for the non selectable rows, or use a callback function for more
|
||||
flexible customization
|
||||
|
||||
### String
|
||||
|
||||
```js
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
nonSelectable: [1, 3 ,5],
|
||||
nonSelectableClasses: 'my-class'
|
||||
};
|
||||
```
|
||||
|
||||
### Callback Function
|
||||
|
||||
```js
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
nonSelectable: [1, 3 ,5],
|
||||
nonSelectableClasses: (row, rowIndex) => { return ...; }
|
||||
};
|
||||
```
|
||||
|
||||
### <a name='clickToSelect'>selectRow.clickToSelect - [Bool]</a>
|
||||
Allow user to select row by clicking on the row.
|
||||
|
||||
@@ -149,7 +199,7 @@ const selectRow = {
|
||||
};
|
||||
```
|
||||
|
||||
> Note: When you also enable [cellEdit](./cell-edit.md), the `selectRow.clickToSelect` will deactivate the functionality of cell editing
|
||||
> Note: When you also enable [cellEdit](./cell-edit.md), the `selectRow.clickToSelect` will deactivate the functionality of cell editing
|
||||
> If you want to click on row to select row and edit cell simultaneously, you are suppose to enable [`selectRow.clickToEdit`](#clickToEdit)
|
||||
|
||||
### <a name='clickToExpand'>selectRow.clickToExpand - [Bool]</a>
|
||||
@@ -307,7 +357,7 @@ const selectRow = {
|
||||
mode: 'checkbox',
|
||||
onSelectAll: (isSelect, rows, e) => {
|
||||
if (isSelect && SOME_CONDITION) {
|
||||
return [1, 3, 4]; // finally, key 1, 3, 4 will being selected
|
||||
return [1, 3, 4]; // finally, key 1, 3, 4 will being selected
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -80,7 +80,7 @@
|
||||
"webpack-dev-server": "2.7.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"classnames": "2.2.5",
|
||||
"classnames": "^2.2.5",
|
||||
"prop-types": "15.5.10",
|
||||
"react": "16.4.0",
|
||||
"react-dom": "16.4.0",
|
||||
|
||||
49
packages/react-bootstrap-table2-example/examples/bootstrap4/caption-table.js
vendored
Normal file
49
packages/react-bootstrap-table2-example/examples/bootstrap4/caption-table.js
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const products = productsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const CaptionElement = () => <h3 style={{ borderRadius: '0.25em', textAlign: 'center', color: 'purple', border: '1px solid purple', padding: '0.5em' }}>Component as Header</h3>;
|
||||
|
||||
<BootstrapTable bootstrap4 keyField="id" data={ products } caption="Plain text header" columns={ columns } />
|
||||
|
||||
<BootstrapTable bootstrap4 keyField="id" data={ products } caption={<CaptionElement />} columns={ columns } />
|
||||
`;
|
||||
|
||||
const Caption = () => <h3 style={ { borderRadius: '0.25em', textAlign: 'center', color: 'purple', border: '1px solid purple', padding: '0.5em' } }>Component as Header</h3>;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<BootstrapTable bootstrap4 keyField="id" data={ products } caption="Plain text header" columns={ columns } />
|
||||
<BootstrapTable bootstrap4 keyField="id" data={ products } caption={ <Caption /> } columns={ columns } />
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
114
packages/react-bootstrap-table2-example/examples/column-filter/filter-position.js
vendored
Normal file
114
packages/react-bootstrap-table2-example/examples/column-filter/filter-position.js
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
import React from 'react';
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const products = productsGenerator(8);
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
filter: textFilter()
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
filter: textFilter()
|
||||
}];
|
||||
|
||||
const sourceCode1 = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID',
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
filter: textFilter()
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
filter: textFilter()
|
||||
}];
|
||||
|
||||
<BootstrapTable
|
||||
keyField='id'
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
filterPosition="top"
|
||||
/>
|
||||
`;
|
||||
|
||||
const sourceCode2 = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID',
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
filter: textFilter()
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
filter: textFilter()
|
||||
}];
|
||||
|
||||
<BootstrapTable
|
||||
keyField='id'
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
filterPosition="bottom"
|
||||
/>
|
||||
`;
|
||||
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true
|
||||
};
|
||||
|
||||
const expandRow = {
|
||||
renderer: row => (
|
||||
<div>
|
||||
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
|
||||
<p>You can render anything here, also you can add additional data on every row object</p>
|
||||
<p>expandRow.renderer callback will pass the origin row object to you</p>
|
||||
</div>
|
||||
),
|
||||
showExpandColumn: true,
|
||||
expandColumnPosition: 'right'
|
||||
};
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
filterPosition="top"
|
||||
expandRow={ expandRow }
|
||||
selectRow={ selectRow }
|
||||
/>
|
||||
<Code>{ sourceCode1 }</Code>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
filterPosition="bottom"
|
||||
expandRow={ expandRow }
|
||||
selectRow={ selectRow }
|
||||
/>
|
||||
<Code>{ sourceCode2 }</Code>
|
||||
</div>
|
||||
);
|
||||
@@ -8,14 +8,17 @@ const products = productsGenerator(8);
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
text: 'Product ID',
|
||||
footer: 'hello'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
footer: 'hello',
|
||||
filter: textFilter()
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
footer: 'hello',
|
||||
filter: textFilter()
|
||||
}];
|
||||
|
||||
@@ -39,6 +42,11 @@ const columns = [{
|
||||
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
||||
`;
|
||||
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true
|
||||
};
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<BootstrapTable
|
||||
@@ -46,6 +54,8 @@ export default () => (
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
filterPosition="bottom"
|
||||
selectRow={ selectRow }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
|
||||
@@ -40,7 +40,13 @@ const columns = [{
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
exportCSV
|
||||
exportCSV={ {
|
||||
fileName: 'custom.csv',
|
||||
separator: '|',
|
||||
ignoreHeader: true,
|
||||
noAutoBOM: false,
|
||||
blobType: 'text/csv;charset=ansi'
|
||||
} }
|
||||
>
|
||||
{
|
||||
props => (
|
||||
@@ -64,7 +70,8 @@ export default () => (
|
||||
fileName: 'custom.csv',
|
||||
separator: '|',
|
||||
ignoreHeader: true,
|
||||
noAutoBOM: false
|
||||
noAutoBOM: false,
|
||||
blobType: 'text/csv;charset=ansi'
|
||||
} }
|
||||
>
|
||||
{
|
||||
|
||||
@@ -36,11 +36,12 @@ const columns = [{
|
||||
|
||||
const MyExportCSV = (props) => {
|
||||
const handleClick = () => {
|
||||
props.onExport();
|
||||
// passing my custom data
|
||||
props.onExport(products.filter(r => r.id > 2));
|
||||
};
|
||||
return (
|
||||
<div>
|
||||
<button className="btn btn-success" onClick={ handleClick }>Export to CSV</button>
|
||||
<button className="btn btn-success" onClick={ handleClick }>Only export Product ID bigger than 2</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
92
packages/react-bootstrap-table2-example/examples/csv/export-footer.js
vendored
Normal file
92
packages/react-bootstrap-table2-example/examples/csv/export-footer.js
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/* eslint react/prop-types: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import ToolkitProvider, { CSVExport } from 'react-bootstrap-table2-toolkit';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const { ExportCSVButton } = CSVExport;
|
||||
const products = productsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID',
|
||||
footer: 'Footer 1'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
footer: '',
|
||||
footerFormatter: column => column.text
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
footer: columnData => columnData.reduce((acc, item) => acc + item, 0)
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import ToolkitProvider, { CSVExport } from 'react-bootstrap-table2-toolkit';
|
||||
|
||||
const { ExportCSVButton } = CSVExport;
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID',
|
||||
footer: 'Footer 1'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
footer: 'Footer 2'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price',
|
||||
footer: 'Footer 3'
|
||||
}];
|
||||
|
||||
<ToolkitProvider
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
exportCSV={ {
|
||||
fileName: 'custom.csv',
|
||||
separator: '|',
|
||||
ignoreHeader: true,
|
||||
noAutoBOM: false,
|
||||
blobType: 'text/csv;charset=ansi'
|
||||
} }
|
||||
>
|
||||
{
|
||||
props => (
|
||||
<div>
|
||||
<ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
|
||||
<hr />
|
||||
<BootstrapTable { ...props.baseProps } />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</ToolkitProvider>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<ToolkitProvider
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
exportCSV={ {
|
||||
ignoreFooter: false
|
||||
} }
|
||||
>
|
||||
{
|
||||
props => (
|
||||
<div>
|
||||
<ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
|
||||
<hr />
|
||||
<BootstrapTable { ...props.baseProps } />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</ToolkitProvider>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-class.js
vendored
Normal file
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-class.js
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const products = productsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true,
|
||||
nonSelectable: [0, 2, 4],
|
||||
nonSelectableClasses: 'row-index-bigger-than-2101'
|
||||
};
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true,
|
||||
nonSelectable: [0, 2, 4],
|
||||
nonSelectableClasses: 'row-index-bigger-than-2101'
|
||||
};
|
||||
|
||||
<BootstrapTable
|
||||
keyField='id'
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
selectRow={ selectRow }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-style.js
vendored
Normal file
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-style.js
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const products = productsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true,
|
||||
nonSelectable: [0, 2, 4],
|
||||
nonSelectableStyle: { backgroundColor: 'gray' }
|
||||
};
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true,
|
||||
nonSelectable: [0, 2, 4],
|
||||
nonSelectableStyle: { backgroundColor: 'gray' }
|
||||
};
|
||||
|
||||
<BootstrapTable
|
||||
keyField='id'
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
selectRow={ selectRow }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
98
packages/react-bootstrap-table2-example/examples/sort/one-time-sort-configuration.js
vendored
Normal file
98
packages/react-bootstrap-table2-example/examples/sort/one-time-sort-configuration.js
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
/* eslint no-unused-vars: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const products = productsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID',
|
||||
sort: true
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
sort: true
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID',
|
||||
sort: true
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
sort: true
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
class OnetimeSortConfiguration extends React.Component {
|
||||
sortFunc = (a, b, order, dataField) => {
|
||||
if (order === 'asc') {
|
||||
return b - a;
|
||||
}
|
||||
return a - b; // desc
|
||||
}
|
||||
|
||||
render() {
|
||||
const sortOption = {
|
||||
// No need to configure sortFunc per column
|
||||
sortFunc: this.sortFunc,
|
||||
// No need to configure sortCaret per column
|
||||
sortCaret: (order, column) => {
|
||||
if (!order) return (<span> Desc/Asc</span>);
|
||||
else if (order === 'asc') return (<span> Desc/<font color="red">Asc</font></span>);
|
||||
else if (order === 'desc') return (<span> <font color="red">Desc</font>/Asc</span>);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button className="btn btn-default" onClick={ this.handleClick }>Change Data</button>
|
||||
<BootstrapTable keyField="id" data={ products } columns={ columns } sort={ sortOption } />
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default class OnetimeSortConfiguration extends React.Component {
|
||||
sortFunc = (a, b, order, dataField) => {
|
||||
if (order === 'asc') {
|
||||
return b - a;
|
||||
}
|
||||
return a - b; // desc
|
||||
}
|
||||
|
||||
render() {
|
||||
const sortOption = {
|
||||
sortFunc: this.sortFunc,
|
||||
sortCaret: (order, column) => {
|
||||
if (!order) return (<span> Desc/Asc</span>);
|
||||
else if (order === 'asc') return (<span> Desc/<font color="red">Asc</font></span>);
|
||||
else if (order === 'desc') return (<span> <font color="red">Desc</font>/Asc</span>);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h3>Reverse Sorting Table</h3>
|
||||
<BootstrapTable keyField="id" data={ products } columns={ columns } sort={ sortOption } />
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
118
packages/react-bootstrap-table2-example/examples/sort/sort-management.js
vendored
Normal file
118
packages/react-bootstrap-table2-example/examples/sort/sort-management.js
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
/* eslint no-console: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const products = productsGenerator();
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
|
||||
class SortManagement extends React.Component {
|
||||
state = {
|
||||
field: null,
|
||||
order: null
|
||||
}
|
||||
|
||||
handleSort = (field, order) => {
|
||||
this.setState({
|
||||
field,
|
||||
order
|
||||
});
|
||||
}
|
||||
|
||||
handleSortById = () => {
|
||||
this.setState({
|
||||
field: 'id',
|
||||
order: 'desc'
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID',
|
||||
sort: true,
|
||||
onSort: this.handleSort
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
sort: true,
|
||||
onSort: this.handleSort
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
return (
|
||||
<div>
|
||||
<button className="btn btn-danger" onClick={ this.handleSortById }>Sort By ID</button>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
sort={ {
|
||||
dataField: this.state.field,
|
||||
order: this.state.order
|
||||
} }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default class SortManagement extends React.Component {
|
||||
state = {
|
||||
field: null,
|
||||
order: null
|
||||
}
|
||||
|
||||
handleSort = (field, order) => {
|
||||
this.setState({
|
||||
field,
|
||||
order
|
||||
});
|
||||
}
|
||||
|
||||
handleSortById = () => {
|
||||
this.setState({
|
||||
field: 'id',
|
||||
order: 'desc'
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID',
|
||||
sort: true,
|
||||
onSort: this.handleSort
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name',
|
||||
sort: true,
|
||||
onSort: this.handleSort
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
return (
|
||||
<div>
|
||||
<button className="btn btn-danger" onClick={ this.handleSortById }>Sort By ID</button>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
sort={ {
|
||||
dataField: this.state.field,
|
||||
order: this.state.order
|
||||
} }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-example",
|
||||
"version": "1.0.31",
|
||||
"version": "1.0.36",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
|
||||
@@ -18,6 +18,7 @@ import TabIndexCellTable from 'examples/basic/tabindex-column';
|
||||
|
||||
// bootstrap 4
|
||||
import Bootstrap4DefaultSortTable from 'examples/bootstrap4/sort';
|
||||
import Bootstrap4CaptionTable from 'examples/bootstrap4/caption-table';
|
||||
import Bootstrap4RowSelectionTable from 'examples/bootstrap4/row-selection';
|
||||
import Bootstrap4PaginationTable from 'examples/bootstrap4/pagination';
|
||||
import Bootstrap4ColumnToggleTable from 'examples/bootstrap4/column-toggle';
|
||||
@@ -92,6 +93,7 @@ import AdvanceCustomFilter from 'examples/column-filter/advance-custom-filter';
|
||||
import ClearAllFilters from 'examples/column-filter/clear-all-filters';
|
||||
import FilterHooks from 'examples/column-filter/filter-hooks';
|
||||
import CustomFilterLogic from 'examples/column-filter/custom-filter-logic';
|
||||
import FilterPosition from 'examples/column-filter/filter-position';
|
||||
|
||||
// work on rows
|
||||
import RowStyleTable from 'examples/rows/row-style';
|
||||
@@ -104,6 +106,8 @@ import EnableSortTable from 'examples/sort/enable-sort-table';
|
||||
import DefaultSortTable from 'examples/sort/default-sort-table';
|
||||
import DefaultSortDirectionTable from 'examples/sort/default-sort-direction';
|
||||
import SortEvents from 'examples/sort/sort-events';
|
||||
import SortManagement from 'examples/sort/sort-management';
|
||||
import OneTimeSortConfiguration from 'examples/sort/one-time-sort-configuration';
|
||||
import CustomSortValue from 'examples/sort/custom-sort-value';
|
||||
import CustomSortTable from 'examples/sort/custom-sort-table';
|
||||
import CustomSortCaretTable from 'examples/sort/custom-sort-caret';
|
||||
@@ -151,6 +155,8 @@ import HeaderStyleTable from 'examples/row-selection/header-style';
|
||||
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
|
||||
import CustomSelectionTable from 'examples/row-selection/custom-selection';
|
||||
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
|
||||
import NonSelectableRowsStyleTable from 'examples/row-selection/non-selectable-rows-style';
|
||||
import NonSelectableRowsClassTable from 'examples/row-selection/non-selectable-rows-class';
|
||||
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
|
||||
import SelectionHooks from 'examples/row-selection/selection-hooks';
|
||||
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
|
||||
@@ -209,6 +215,7 @@ import CSVColumnType from 'examples/csv/csv-column-type';
|
||||
import CustomCSVButton from 'examples/csv/custom-csv-button';
|
||||
import ExportCustomData from 'examples/csv/export-custom-data';
|
||||
import CustomCSV from 'examples/csv/custom-csv';
|
||||
import ExportTableFooter from 'examples/csv/export-footer';
|
||||
|
||||
// Column toggle
|
||||
import BasicColumnToggle from 'examples/column-toggle';
|
||||
@@ -265,6 +272,7 @@ storiesOf('Basic Table', module)
|
||||
storiesOf('Bootstrap 4', module)
|
||||
.addDecorator(bootstrapStyle(BOOTSTRAP_VERSION.FOUR))
|
||||
.add('Sort table with bootstrap 4', () => <Bootstrap4DefaultSortTable />)
|
||||
.add('Table Caption bootstrap 4', () => <Bootstrap4CaptionTable />)
|
||||
.add('Row selection table with bootstrap 4', () => <Bootstrap4RowSelectionTable />)
|
||||
.add('Pagination table with bootstrap 4', () => <Bootstrap4PaginationTable />)
|
||||
.add('Column Toggle with bootstrap 4', () => <Bootstrap4ColumnToggleTable />)
|
||||
@@ -314,6 +322,7 @@ storiesOf('Column Filter', module)
|
||||
.add('Number Filter with Default Value', () => <NumberFilterWithDefaultValue />)
|
||||
.add('Date Filter', () => <DateFilter />)
|
||||
.add('Date Filter with Default Value', () => <DateFilterWithDefaultValue />)
|
||||
.add('Filter Position', () => <FilterPosition />)
|
||||
.add('Custom Text Filter', () => <CustomTextFilter />)
|
||||
.add('Custom Select Filter', () => <CustomSelectFilter />)
|
||||
.add('Custom Number Filter', () => <CustomNumberFilter />)
|
||||
@@ -358,6 +367,8 @@ storiesOf('Sort Table', module)
|
||||
.add('Default Sort Table', () => <DefaultSortTable />)
|
||||
.add('Default Sort Direction Table', () => <DefaultSortDirectionTable />)
|
||||
.add('Sort Events', () => <SortEvents />)
|
||||
.add('Sort Management', () => <SortManagement />)
|
||||
.add('One-time Sort Configuation', () => <OneTimeSortConfiguration />)
|
||||
.add('Custom Sort Value', () => <CustomSortValue />)
|
||||
.add('Custom Sort Fuction', () => <CustomSortTable />)
|
||||
.add('Custom Sort Caret', () => <CustomSortCaretTable />)
|
||||
@@ -408,6 +419,8 @@ storiesOf('Row Selection', module)
|
||||
.add('Custom Selection', () => <CustomSelectionTable />)
|
||||
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
||||
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
|
||||
.add('Not Selectabled Rows Style', () => <NonSelectableRowsStyleTable />)
|
||||
.add('Not Selectabled Rows Class', () => <NonSelectableRowsClassTable />)
|
||||
.add('Selection Hooks', () => <SelectionHooks />)
|
||||
.add('Hide Selection Column', () => <HideSelectionColumnTable />)
|
||||
.add('Custom Selection Column Style', () => <SelectionColumnStyleTable />)
|
||||
@@ -476,7 +489,8 @@ storiesOf('Export CSV', module)
|
||||
.add('CSV Column Type', () => <CSVColumnType />)
|
||||
.add('Custom CSV Button', () => <CustomCSVButton />)
|
||||
.add('Export Custom Data', () => <ExportCustomData />)
|
||||
.add('Custom CSV', () => <CustomCSV />);
|
||||
.add('Custom CSV', () => <CustomCSV />)
|
||||
.add('Export Table Footer', () => <ExportTableFooter />);
|
||||
|
||||
storiesOf('EmptyTableOverlay', module)
|
||||
.addDecorator(bootstrapStyle())
|
||||
|
||||
@@ -330,3 +330,29 @@ Following properties is valid in `FILTER_TYPES`:
|
||||
* NUMBER
|
||||
* DATE
|
||||
* MULTISELECT
|
||||
|
||||
### Position
|
||||
Default filter is rendered inside the table column header, but you can choose to render them as a row by `filterPosition`:
|
||||
|
||||
#### Render in the top of table body
|
||||
|
||||
```js
|
||||
<BootstrapTable
|
||||
keyField='id'
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
filterPosition="top"
|
||||
/>
|
||||
```
|
||||
|
||||
#### Render in the bottom of table body
|
||||
```js
|
||||
<BootstrapTable
|
||||
keyField='id'
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
filter={ filterFactory() }
|
||||
filterPosition="bottom"
|
||||
/>
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-filter",
|
||||
"version": "1.2.0",
|
||||
"version": "1.3.0",
|
||||
"description": "it's a column filter addon for react-bootstrap-table2",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -209,6 +209,9 @@ Custom the csv file separator.
|
||||
#### ignoreHeader - [bool]
|
||||
Default is `false`. Give true to avoid to attach the csv header.
|
||||
|
||||
#### ignoreFooter - [bool]
|
||||
Default is `true`. Give `false` to attach the table footer if enabled.
|
||||
|
||||
#### noAutoBOM - [bool]
|
||||
Default is `true`.
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ class ToolkitProvider extends statelessDecorator(React.Component) {
|
||||
fileName: PropTypes.string,
|
||||
separator: PropTypes.string,
|
||||
ignoreHeader: PropTypes.bool,
|
||||
ignoreFooter: PropTypes.bool,
|
||||
noAutoBOM: PropTypes.bool,
|
||||
blobType: PropTypes.string,
|
||||
exportAll: PropTypes.bool,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table2-toolkit",
|
||||
"version": "2.1.0",
|
||||
"version": "2.1.1",
|
||||
"description": "The toolkit for react-bootstrap-table2",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -12,17 +12,21 @@ export const getMetaInfo = columns =>
|
||||
export: column.csvExport === false ? false : true,
|
||||
row: Number(column.row) || 0,
|
||||
rowSpan: Number(column.rowSpan) || 1,
|
||||
colSpan: Number(column.colSpan) || 1
|
||||
colSpan: Number(column.colSpan) || 1,
|
||||
footer: column.footer,
|
||||
footerFormatter: column.footerFormatter
|
||||
}))
|
||||
.filter(_ => _.export);
|
||||
|
||||
export const transform = (
|
||||
data,
|
||||
meta,
|
||||
getValue,
|
||||
columns,
|
||||
_,
|
||||
{
|
||||
separator,
|
||||
ignoreHeader
|
||||
ignoreHeader,
|
||||
ignoreFooter
|
||||
}
|
||||
) => {
|
||||
const visibleColumns = meta.filter(m => m.export);
|
||||
@@ -37,7 +41,7 @@ export const transform = (
|
||||
content += data
|
||||
.map((row, rowIndex) =>
|
||||
visibleColumns.map((m) => {
|
||||
let cellContent = getValue(row, m.field);
|
||||
let cellContent = _.get(row, m.field);
|
||||
if (m.formatter) {
|
||||
cellContent = m.formatter(cellContent, row, rowIndex, m.formatExtraData);
|
||||
}
|
||||
@@ -47,6 +51,18 @@ export const transform = (
|
||||
return cellContent;
|
||||
}).join(separator)).join('\n');
|
||||
|
||||
if (!ignoreFooter) {
|
||||
content += '\n';
|
||||
content += visibleColumns.map((m, i) => {
|
||||
if (typeof m.footer === 'function') {
|
||||
const columnData = _.pluck(data, columns[i].dataField);
|
||||
return `"${m.footer(columnData, columns[i], i)}"`;
|
||||
} else if (m.footerFormatter) {
|
||||
return `"${m.footerFormatter(columns[i], i)}"`;
|
||||
}
|
||||
return `"${m.footer}"`;
|
||||
}).join(separator);
|
||||
}
|
||||
return content;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ const csvDefaultOptions = {
|
||||
fileName: 'spreadsheet.csv',
|
||||
separator: ',',
|
||||
ignoreHeader: false,
|
||||
ignoreFooter: true,
|
||||
noAutoBOM: true,
|
||||
blobType: 'text/plain;charset=utf-8',
|
||||
exportAll: true,
|
||||
@@ -46,7 +47,7 @@ export default Base =>
|
||||
data = data.filter(row => !!selections.find(sel => row[keyField] === sel));
|
||||
}
|
||||
|
||||
const content = transform(data, meta, this._.get, options);
|
||||
const content = transform(data, meta, columns, this._, options);
|
||||
save(content, options);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-bootstrap-table-next",
|
||||
"version": "3.2.0",
|
||||
"version": "3.3.3",
|
||||
"description": "Next generation of react-bootstrap-table",
|
||||
"main": "./lib/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -6,6 +6,7 @@ import PropTypes from 'prop-types';
|
||||
import cs from 'classnames';
|
||||
|
||||
import Header from './header';
|
||||
import Filters from './filters';
|
||||
import Caption from './caption';
|
||||
import Body from './body';
|
||||
import Footer from './footer';
|
||||
@@ -65,7 +66,8 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
||||
rowEvents,
|
||||
selectRow,
|
||||
expandRow,
|
||||
cellEdit
|
||||
cellEdit,
|
||||
filterPosition
|
||||
} = this.props;
|
||||
|
||||
const tableWrapperClass = cs('react-bootstrap-table', wrapperClasses);
|
||||
@@ -77,9 +79,13 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
||||
[bootstrap4 ? 'table-sm' : 'table-condensed']: condensed
|
||||
}, classes);
|
||||
|
||||
const hasFilters = columns.some(col => col.filter || col.filterRenderer);
|
||||
|
||||
const hasFooter = _.filter(columns, col => _.has(col, 'footer')).length > 0;
|
||||
|
||||
const tableCaption = (caption && <Caption>{ caption }</Caption>);
|
||||
const tableCaption = (
|
||||
caption && <Caption bootstrap4={ bootstrap4 }>{ caption }</Caption>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={ tableWrapperClass }>
|
||||
@@ -91,12 +97,27 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
||||
sortField={ this.props.sortField }
|
||||
sortOrder={ this.props.sortOrder }
|
||||
onSort={ this.props.onSort }
|
||||
globalSortCaret={ this.props.sort && this.props.sort.sortCaret }
|
||||
onFilter={ this.props.onFilter }
|
||||
currFilters={ this.props.currFilters }
|
||||
onExternalFilter={ this.props.onExternalFilter }
|
||||
selectRow={ selectRow }
|
||||
expandRow={ expandRow }
|
||||
filterPosition={ filterPosition }
|
||||
/>
|
||||
{hasFilters && filterPosition !== Const.FILTERS_POSITION_INLINE && (
|
||||
<Filters
|
||||
columns={ columns }
|
||||
className={ this.props.filtersClasses }
|
||||
onSort={ this.props.onSort }
|
||||
onFilter={ this.props.onFilter }
|
||||
currFilters={ this.props.currFilters }
|
||||
filterPosition={ this.props.filterPosition }
|
||||
onExternalFilter={ this.props.onExternalFilter }
|
||||
selectRow={ selectRow }
|
||||
expandRow={ expandRow }
|
||||
/>
|
||||
)}
|
||||
<Body
|
||||
data={ this.getData() }
|
||||
keyField={ keyField }
|
||||
@@ -135,7 +156,7 @@ BootstrapTable.propTypes = {
|
||||
remote: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
|
||||
pagination: PropTypes.bool
|
||||
})]),
|
||||
noDataIndication: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
noDataIndication: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
||||
striped: PropTypes.bool,
|
||||
bordered: PropTypes.bool,
|
||||
hover: PropTypes.bool,
|
||||
@@ -166,6 +187,8 @@ BootstrapTable.propTypes = {
|
||||
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
nonSelectable: PropTypes.array,
|
||||
nonSelectableStyle: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
nonSelectableClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
hideSelectColumn: PropTypes.bool,
|
||||
selectionRenderer: PropTypes.func,
|
||||
@@ -199,11 +222,23 @@ BootstrapTable.propTypes = {
|
||||
rowEvents: PropTypes.object,
|
||||
rowClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
headerClasses: PropTypes.string,
|
||||
filtersClasses: PropTypes.string,
|
||||
filterPosition: PropTypes.oneOf([
|
||||
Const.FILTERS_POSITION_TOP,
|
||||
Const.FILTERS_POSITION_INLINE,
|
||||
Const.FILTERS_POSITION_BOTTOM
|
||||
]),
|
||||
footerClasses: PropTypes.string,
|
||||
defaultSorted: PropTypes.arrayOf(PropTypes.shape({
|
||||
dataField: PropTypes.string.isRequired,
|
||||
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]).isRequired
|
||||
})),
|
||||
sort: PropTypes.shape({
|
||||
dataField: PropTypes.string,
|
||||
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
||||
sortFunc: PropTypes.func,
|
||||
sortCaret: PropTypes.func
|
||||
}),
|
||||
defaultSortDirection: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
||||
overlay: PropTypes.func,
|
||||
onTableChange: PropTypes.func,
|
||||
@@ -240,7 +275,8 @@ BootstrapTable.defaultProps = {
|
||||
cellEdit: {
|
||||
mode: null,
|
||||
nonEditableRows: []
|
||||
}
|
||||
},
|
||||
filterPosition: Const.FILTERS_POSITION_INLINE
|
||||
};
|
||||
|
||||
export default BootstrapTable;
|
||||
|
||||
12
packages/react-bootstrap-table2/src/caption.js
vendored
12
packages/react-bootstrap-table2/src/caption.js
vendored
@@ -4,16 +4,22 @@ import PropTypes from 'prop-types';
|
||||
|
||||
const Caption = (props) => {
|
||||
if (!props.children) return null;
|
||||
return (
|
||||
<caption>{ props.children }</caption>
|
||||
|
||||
const caption = props.bootstrap4 ? (
|
||||
<caption style={ { captionSide: 'top' } }>{props.children}</caption>
|
||||
) : (
|
||||
<caption>{props.children}</caption>
|
||||
);
|
||||
|
||||
return caption;
|
||||
};
|
||||
|
||||
Caption.propTypes = {
|
||||
children: PropTypes.oneOfType([
|
||||
PropTypes.node,
|
||||
PropTypes.string
|
||||
])
|
||||
]),
|
||||
bootstrap4: PropTypes.bool
|
||||
};
|
||||
|
||||
export default Caption;
|
||||
|
||||
5
packages/react-bootstrap-table2/src/const.js
vendored
5
packages/react-bootstrap-table2/src/const.js
vendored
@@ -12,5 +12,8 @@ export default {
|
||||
TYPE_STRING: 'string',
|
||||
TYPE_NUMBER: 'number',
|
||||
TYPE_BOOLEAN: 'bool',
|
||||
TYPE_DATE: 'date'
|
||||
TYPE_DATE: 'date',
|
||||
FILTERS_POSITION_INLINE: 'inline',
|
||||
FILTERS_POSITION_TOP: 'top',
|
||||
FILTERS_POSITION_BOTTOM: 'bottom'
|
||||
};
|
||||
|
||||
@@ -247,6 +247,7 @@ const withContext = Base =>
|
||||
ref={ n => this.sortContext = n }
|
||||
defaultSorted={ this.props.defaultSorted }
|
||||
defaultSortDirection={ this.props.defaultSortDirection }
|
||||
sort={ this.props.sort }
|
||||
data={ rootProps.getData(filterProps, searchProps) }
|
||||
>
|
||||
<this.SortContext.Consumer>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Const from '../const';
|
||||
import _ from '../utils';
|
||||
|
||||
import dataOperator from '../store/operators';
|
||||
import { getSelectionSummary } from '../store/selection';
|
||||
@@ -72,7 +73,7 @@ class SelectionProvider extends React.Component {
|
||||
if (!isUnSelect) {
|
||||
currSelected = selected.concat(dataOperator.selectableKeys(data, keyField, nonSelectable));
|
||||
} else {
|
||||
currSelected = selected.filter(s => typeof data.find(d => d[keyField] === s) === 'undefined');
|
||||
currSelected = selected.filter(s => typeof data.find(d => _.get(d, keyField) === s) === 'undefined');
|
||||
}
|
||||
|
||||
let result;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint camelcase: 0 */
|
||||
/* eslint react/require-default-props: 0 */
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
@@ -19,6 +20,11 @@ export default (
|
||||
dataField: PropTypes.string.isRequired,
|
||||
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]).isRequired
|
||||
})),
|
||||
sort: PropTypes.shape({
|
||||
dataField: PropTypes.string,
|
||||
order: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC]),
|
||||
sortFunc: PropTypes.func
|
||||
}),
|
||||
defaultSortDirection: PropTypes.oneOf([Const.SORT_DESC, Const.SORT_ASC])
|
||||
}
|
||||
|
||||
@@ -26,19 +32,14 @@ export default (
|
||||
super(props);
|
||||
let sortOrder;
|
||||
let sortColumn;
|
||||
const { columns, defaultSorted, defaultSortDirection } = props;
|
||||
const { defaultSorted, defaultSortDirection, sort } = props;
|
||||
|
||||
if (defaultSorted && defaultSorted.length > 0) {
|
||||
const sortField = defaultSorted[0].dataField;
|
||||
sortOrder = defaultSorted[0].order || defaultSortDirection;
|
||||
const sortColumns = columns.filter(col => col.dataField === sortField);
|
||||
if (sortColumns.length > 0) {
|
||||
sortColumn = sortColumns[0];
|
||||
|
||||
if (sortColumn.onSort) {
|
||||
sortColumn.onSort(sortField, sortOrder);
|
||||
}
|
||||
}
|
||||
sortColumn = this.initSort(defaultSorted[0].dataField, sortOrder);
|
||||
} else if (sort && sort.dataField && sort.order) {
|
||||
sortOrder = sort.order;
|
||||
sortColumn = this.initSort(sort.dataField, sortOrder);
|
||||
}
|
||||
this.state = { sortOrder, sortColumn };
|
||||
}
|
||||
@@ -50,6 +51,30 @@ export default (
|
||||
}
|
||||
}
|
||||
|
||||
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||
const { sort, columns } = nextProps;
|
||||
if (sort && sort.dataField && sort.order) {
|
||||
this.setState({
|
||||
sortOrder: sort.order,
|
||||
sortColumn: columns.find(col => col.dataField === sort.dataField)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
initSort(sortField, sortOrder) {
|
||||
let sortColumn;
|
||||
const { columns } = this.props;
|
||||
const sortColumns = columns.filter(col => col.dataField === sortField);
|
||||
if (sortColumns.length > 0) {
|
||||
sortColumn = sortColumns[0];
|
||||
|
||||
if (sortColumn.onSort) {
|
||||
sortColumn.onSort(sortField, sortOrder);
|
||||
}
|
||||
}
|
||||
return sortColumn;
|
||||
}
|
||||
|
||||
handleSort = (column) => {
|
||||
const sortOrder = dataOperator.nextOrder(column, this.state, this.props.defaultSortDirection);
|
||||
|
||||
@@ -68,9 +93,11 @@ export default (
|
||||
|
||||
render() {
|
||||
let { data } = this.props;
|
||||
const { sort } = this.props;
|
||||
const { sortOrder, sortColumn } = this.state;
|
||||
if (!isRemoteSort() && sortColumn) {
|
||||
data = dataOperator.sort(data, sortOrder, sortColumn);
|
||||
const sortFunc = sortColumn.sortFunc ? sortColumn.sortFunc : (sort && sort.sortFunc);
|
||||
data = dataOperator.sort(data, sortOrder, { ...sortColumn, sortFunc });
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
49
packages/react-bootstrap-table2/src/filters-cell.js
vendored
Normal file
49
packages/react-bootstrap-table2/src/filters-cell.js
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import _ from './utils';
|
||||
|
||||
const FiltersCell = (props) => {
|
||||
const {
|
||||
index, column, onExternalFilter,
|
||||
currFilters, onFilter
|
||||
} = props;
|
||||
const { filterRenderer, filter } = column;
|
||||
let filterElm;
|
||||
const cellAttrs = {};
|
||||
const cellStyle = {};
|
||||
cellAttrs.style = cellStyle;
|
||||
if (column.headerAlign) {
|
||||
cellStyle.textAlign = _.isFunction(column.headerAlign)
|
||||
? column.headerAlign(column, index)
|
||||
: column.headerAlign;
|
||||
}
|
||||
if (column.filterRenderer) {
|
||||
const onCustomFilter = onExternalFilter(column, filter.props.type);
|
||||
filterElm = filterRenderer(onCustomFilter, column);
|
||||
} else if (filter) {
|
||||
filterElm = (
|
||||
<filter.Filter
|
||||
{ ...filter.props }
|
||||
filterState={ currFilters[column.dataField] }
|
||||
onFilter={ onFilter }
|
||||
column={ column }
|
||||
/>
|
||||
);
|
||||
}
|
||||
return React.createElement('th', cellAttrs, filterElm);
|
||||
};
|
||||
|
||||
FiltersCell.propTypes = {
|
||||
index: PropTypes.number.isRequired,
|
||||
column: PropTypes.object.isRequired,
|
||||
currFilters: PropTypes.object.isRequired,
|
||||
onFilter: PropTypes.func,
|
||||
onExternalFilter: PropTypes.func
|
||||
};
|
||||
|
||||
FiltersCell.defaultProps = {
|
||||
onFilter: () => { },
|
||||
onExternalFilter: () => { }
|
||||
};
|
||||
|
||||
export default FiltersCell;
|
||||
83
packages/react-bootstrap-table2/src/filters.js
vendored
Normal file
83
packages/react-bootstrap-table2/src/filters.js
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
/* eslint react/require-default-props: 0 */
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import FiltersCell from './filters-cell';
|
||||
import Const from './const';
|
||||
import RowTemplate from './row/row-template';
|
||||
|
||||
const Filters = (props) => {
|
||||
const {
|
||||
columns,
|
||||
onFilter,
|
||||
currFilters,
|
||||
filterPosition,
|
||||
onExternalFilter,
|
||||
className,
|
||||
selectRow,
|
||||
expandRow
|
||||
} = props;
|
||||
|
||||
function renderContent() {
|
||||
const filterColumns = [];
|
||||
let showFiltersRow = false;
|
||||
|
||||
columns.forEach((column, i) => {
|
||||
filterColumns.push(<FiltersCell
|
||||
index={ i }
|
||||
key={ column.dataField }
|
||||
column={ column }
|
||||
currFilters={ currFilters }
|
||||
onExternalFilter={ onExternalFilter }
|
||||
onFilter={ onFilter }
|
||||
/>);
|
||||
|
||||
if (column.filterRenderer || column.filter) {
|
||||
if (!showFiltersRow) {
|
||||
showFiltersRow = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
return filterColumns;
|
||||
}
|
||||
|
||||
return (
|
||||
<tbody
|
||||
className={ className }
|
||||
style={ {
|
||||
display:
|
||||
filterPosition === Const.FILTERS_POSITION_TOP
|
||||
? 'table-header-group'
|
||||
: 'table-footer-group'
|
||||
} }
|
||||
>
|
||||
<RowTemplate
|
||||
renderContent={ renderContent }
|
||||
selectRow={ selectRow }
|
||||
expandRow={ expandRow }
|
||||
cellEl="td"
|
||||
/>
|
||||
</tbody>
|
||||
);
|
||||
};
|
||||
|
||||
Filters.propTypes = {
|
||||
columns: PropTypes.array.isRequired,
|
||||
onFilter: PropTypes.func,
|
||||
filterPosition: PropTypes.oneOf([
|
||||
Const.FILTERS_POSITION_TOP,
|
||||
Const.FILTERS_POSITION_INLINE,
|
||||
Const.FILTERS_POSITION_BOTTOM
|
||||
]),
|
||||
currFilters: PropTypes.object,
|
||||
onExternalFilter: PropTypes.func,
|
||||
className: PropTypes.string,
|
||||
selectRow: PropTypes.object,
|
||||
expandRow: PropTypes.object
|
||||
};
|
||||
|
||||
Filters.defaultProps = {
|
||||
position: Const.FILTERS_POSITION_TOP
|
||||
};
|
||||
|
||||
export default Filters;
|
||||
62
packages/react-bootstrap-table2/src/footer.js
vendored
62
packages/react-bootstrap-table2/src/footer.js
vendored
@@ -2,57 +2,41 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import Const from './const';
|
||||
import RowTemplate from './row/row-template';
|
||||
import FooterCell from './footer-cell';
|
||||
import _ from './utils';
|
||||
|
||||
const Footer = (props) => {
|
||||
const { data, className, columns, selectRow, expandRow } = props;
|
||||
const SelectionFooterCellComp = () => <th />;
|
||||
const ExpansionFooterCellComp = () => <th />;
|
||||
|
||||
const isRenderFunctionColumnInLeft = (
|
||||
position = Const.INDICATOR_POSITION_LEFT
|
||||
) => position === Const.INDICATOR_POSITION_LEFT;
|
||||
function renderContent() {
|
||||
return columns.map((column, i) => {
|
||||
if (column.footer === undefined || column.footer === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const childrens = columns.map((column, i) => {
|
||||
if (column.footer === undefined || column.footer === null) {
|
||||
return false;
|
||||
}
|
||||
const columnData = _.pluck(data, column.dataField);
|
||||
|
||||
const columnData = _.pluck(data, column.dataField);
|
||||
|
||||
return (
|
||||
<FooterCell
|
||||
index={ i }
|
||||
key={ column.dataField }
|
||||
column={ column }
|
||||
columnData={ columnData }
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
if (selectRow && selectRow.hideSelectColumn !== true) {
|
||||
if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
|
||||
childrens.unshift(<SelectionFooterCellComp key="selection" />);
|
||||
} else {
|
||||
childrens.push(<SelectionFooterCellComp key="selection" />);
|
||||
}
|
||||
}
|
||||
|
||||
if (expandRow.showExpandColumn) {
|
||||
if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
|
||||
childrens.unshift(<ExpansionFooterCellComp key="expansion" />);
|
||||
} else {
|
||||
childrens.push(<ExpansionFooterCellComp key="expansion" />);
|
||||
}
|
||||
return (
|
||||
<FooterCell
|
||||
index={ i }
|
||||
key={ column.dataField }
|
||||
column={ column }
|
||||
columnData={ columnData }
|
||||
/>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<tfoot>
|
||||
<tr className={ className }>
|
||||
{ childrens }
|
||||
</tr>
|
||||
<RowTemplate
|
||||
renderContent={ renderContent }
|
||||
selectRow={ selectRow }
|
||||
expandRow={ expandRow }
|
||||
className={ className }
|
||||
cellEl="th"
|
||||
/>
|
||||
</tfoot>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -21,7 +21,9 @@ class HeaderCell extends eventDelegater(React.Component) {
|
||||
isLastSorting,
|
||||
onFilter,
|
||||
currFilters,
|
||||
onExternalFilter
|
||||
filterPosition,
|
||||
onExternalFilter,
|
||||
globalSortCaret
|
||||
} = this.props;
|
||||
|
||||
const {
|
||||
@@ -41,12 +43,18 @@ class HeaderCell extends eventDelegater(React.Component) {
|
||||
headerSortingStyle
|
||||
} = column;
|
||||
|
||||
const sortCaretfunc = sortCaret || globalSortCaret;
|
||||
|
||||
const delegateEvents = this.delegate(headerEvents);
|
||||
|
||||
const customAttrs = _.isFunction(headerAttrs)
|
||||
? headerAttrs(column, index)
|
||||
: (headerAttrs || {});
|
||||
|
||||
const cellAttrs = {
|
||||
..._.isFunction(headerAttrs) ? headerAttrs(column, index) : headerAttrs,
|
||||
...customAttrs,
|
||||
...delegateEvents,
|
||||
tabIndex: 0
|
||||
tabIndex: _.isDefined(customAttrs.tabIndex) ? customAttrs.tabIndex : 0
|
||||
};
|
||||
|
||||
let sortSymbol;
|
||||
@@ -76,7 +84,9 @@ class HeaderCell extends eventDelegater(React.Component) {
|
||||
cellAttrs.className = cs(cellAttrs.className, 'sortable');
|
||||
|
||||
if (sorting) {
|
||||
sortSymbol = sortCaret ? sortCaret(sortOrder, column) : <SortCaret order={ sortOrder } />;
|
||||
sortSymbol = sortCaretfunc ?
|
||||
sortCaretfunc(sortOrder, column) :
|
||||
<SortCaret order={ sortOrder } />;
|
||||
|
||||
// append customized classes or style if table was sorting based on the current column.
|
||||
cellClasses = cs(
|
||||
@@ -93,25 +103,27 @@ class HeaderCell extends eventDelegater(React.Component) {
|
||||
: headerSortingStyle
|
||||
};
|
||||
} else {
|
||||
sortSymbol = sortCaret ? sortCaret(undefined, column) : <SortSymbol />;
|
||||
sortSymbol = sortCaretfunc ? sortCaretfunc(undefined, column) : <SortSymbol />;
|
||||
}
|
||||
}
|
||||
|
||||
if (cellClasses) cellAttrs.className = cs(cellAttrs.className, cellClasses);
|
||||
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
|
||||
|
||||
if (filterRenderer) {
|
||||
const onCustomFilter = onExternalFilter(column, filter.props.type);
|
||||
filterElm = filterRenderer(onCustomFilter, column);
|
||||
} else if (filter) {
|
||||
filterElm = (
|
||||
<filter.Filter
|
||||
{ ...filter.props }
|
||||
filterState={ currFilters[column.dataField] }
|
||||
onFilter={ onFilter }
|
||||
column={ column }
|
||||
/>
|
||||
);
|
||||
if (filterPosition === Const.FILTERS_POSITION_INLINE) {
|
||||
if (filterRenderer) {
|
||||
const onCustomFilter = onExternalFilter(column, filter.props.type);
|
||||
filterElm = filterRenderer(onCustomFilter, column);
|
||||
} else if (filter) {
|
||||
filterElm = (
|
||||
<filter.Filter
|
||||
{ ...filter.props }
|
||||
filterState={ currFilters[column.dataField] }
|
||||
onFilter={ onFilter }
|
||||
column={ column }
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const children = headerFormatter ?
|
||||
@@ -176,6 +188,8 @@ HeaderCell.propTypes = {
|
||||
sortCaret: PropTypes.func,
|
||||
isLastSorting: PropTypes.bool,
|
||||
onFilter: PropTypes.func,
|
||||
filterPosition: PropTypes.oneOf([Const.FILTERS_POSITION_INLINE,
|
||||
Const.FILTERS_POSITION_BOTTOM, Const.FILTERS_POSITION_TOP]),
|
||||
currFilters: PropTypes.object,
|
||||
onExternalFilter: PropTypes.func
|
||||
};
|
||||
|
||||
18
packages/react-bootstrap-table2/src/header.js
vendored
18
packages/react-bootstrap-table2/src/header.js
vendored
@@ -18,9 +18,11 @@ const Header = (props) => {
|
||||
sortField,
|
||||
sortOrder,
|
||||
selectRow,
|
||||
expandRow,
|
||||
currFilters,
|
||||
onExternalFilter,
|
||||
expandRow
|
||||
filterPosition,
|
||||
globalSortCaret
|
||||
} = props;
|
||||
|
||||
let SelectionHeaderCellComp = () => null;
|
||||
@@ -50,11 +52,13 @@ const Header = (props) => {
|
||||
column={ column }
|
||||
onSort={ onSort }
|
||||
sorting={ currSort }
|
||||
sortOrder={ sortOrder }
|
||||
globalSortCaret={ globalSortCaret }
|
||||
isLastSorting={ isLastSorting }
|
||||
onFilter={ onFilter }
|
||||
currFilters={ currFilters }
|
||||
onExternalFilter={ onExternalFilter }
|
||||
sortOrder={ sortOrder }
|
||||
isLastSorting={ isLastSorting }
|
||||
filterPosition={ filterPosition }
|
||||
/>);
|
||||
})
|
||||
];
|
||||
@@ -93,8 +97,14 @@ Header.propTypes = {
|
||||
selectRow: PropTypes.object,
|
||||
currFilters: PropTypes.object,
|
||||
onExternalFilter: PropTypes.func,
|
||||
globalSortCaret: PropTypes.func,
|
||||
className: PropTypes.string,
|
||||
expandRow: PropTypes.object
|
||||
expandRow: PropTypes.object,
|
||||
filterPosition: PropTypes.oneOf([
|
||||
Const.FILTERS_POSITION_TOP,
|
||||
Const.FILTERS_POSITION_INLINE,
|
||||
Const.FILTERS_POSITION_BOTTOM
|
||||
])
|
||||
};
|
||||
|
||||
export default Header;
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
export default ExtendBase =>
|
||||
class ColumnResolver extends ExtendBase {
|
||||
visibleColumnSize(includeSelectColumn = true) {
|
||||
let columnLen = this.props.columns.filter(c => !c.hidden).length;
|
||||
let columnLen;
|
||||
if (this.props.columnToggle && this.props.columnToggle.toggles) {
|
||||
const columns = this.props.columnToggle.toggles;
|
||||
columnLen = Object.keys(columns).filter(name => columns[name]).length;
|
||||
} else {
|
||||
columnLen = this.props.columns.filter(c => !c.hidden).length;
|
||||
}
|
||||
if (!includeSelectColumn) return columnLen;
|
||||
if (this.props.selectRow && !this.props.selectRow.hideSelectColumn) {
|
||||
columnLen += 1;
|
||||
|
||||
@@ -44,7 +44,7 @@ export default class ExpandCell extends Component {
|
||||
if (tabIndex !== -1) attrs.tabIndex = tabIndex;
|
||||
|
||||
return (
|
||||
<td onClick={ this.handleClick } { ...attrs }>
|
||||
<td className="expand-cell" onClick={ this.handleClick } { ...attrs }>
|
||||
{
|
||||
expandColumnRenderer ? expandColumnRenderer({
|
||||
expandable,
|
||||
|
||||
@@ -28,7 +28,7 @@ export default class ExpansionHeaderCell extends Component {
|
||||
};
|
||||
|
||||
return (
|
||||
<th data-row-selection { ...attrs }>
|
||||
<th className="expand-cell-header" data-row-selection { ...attrs }>
|
||||
{
|
||||
expandHeaderColumnRenderer ?
|
||||
expandHeaderColumnRenderer({ isAnyExpands }) :
|
||||
|
||||
@@ -9,6 +9,7 @@ export default (Component) => {
|
||||
const key = props.value;
|
||||
const selected = _.contains(selectRow.selected, key);
|
||||
const selectable = !selectRow.nonSelectable || !_.contains(selectRow.nonSelectable, key);
|
||||
const notSelectable = _.contains(selectRow.nonSelectable, key);
|
||||
|
||||
let {
|
||||
style,
|
||||
@@ -38,6 +39,22 @@ export default (Component) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (notSelectable) {
|
||||
const notSelectableStyle = _.isFunction(selectRow.nonSelectableStyle)
|
||||
? selectRow.nonSelectableStyle(props.row, props.rowIndex)
|
||||
: selectRow.nonSelectableStyle;
|
||||
|
||||
const notSelectableClasses = _.isFunction(selectRow.nonSelectableClasses)
|
||||
? selectRow.nonSelectableClasses(props.row, props.rowIndex)
|
||||
: selectRow.nonSelectableClasses;
|
||||
|
||||
style = {
|
||||
...style,
|
||||
...notSelectableStyle
|
||||
};
|
||||
className = cs(className, notSelectableClasses) || undefined;
|
||||
}
|
||||
|
||||
return (
|
||||
<Component
|
||||
{ ...props }
|
||||
|
||||
@@ -86,7 +86,7 @@ export default class SelectionCell extends Component {
|
||||
<BootstrapContext.Consumer>
|
||||
{
|
||||
({ bootstrap4 }) => (
|
||||
<td onClick={ this.handleClick } { ...attrs }>
|
||||
<td className="selection-cell" onClick={ this.handleClick } { ...attrs }>
|
||||
{
|
||||
selectionRenderer ? selectionRenderer({
|
||||
mode: inputType,
|
||||
|
||||
@@ -112,7 +112,7 @@ export default class SelectionHeaderCell extends Component {
|
||||
);
|
||||
}
|
||||
return (
|
||||
<th data-row-selection { ...attrs }>{ content }</th>
|
||||
<th className="selection-cell-header" data-row-selection { ...attrs }>{ content }</th>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
48
packages/react-bootstrap-table2/src/row/row-template.js
vendored
Normal file
48
packages/react-bootstrap-table2/src/row/row-template.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
/* eslint react/require-default-props: 0 */
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import Const from '../const';
|
||||
|
||||
const RowTemplate = (props) => {
|
||||
const {
|
||||
renderContent,
|
||||
selectRow,
|
||||
expandRow,
|
||||
cellEl,
|
||||
...rest
|
||||
} = props;
|
||||
|
||||
const isRenderFunctionColumnInLeft = (
|
||||
position = Const.INDICATOR_POSITION_LEFT
|
||||
) => position === Const.INDICATOR_POSITION_LEFT;
|
||||
|
||||
const childrens = renderContent() || [];
|
||||
|
||||
if (selectRow && selectRow.hideSelectColumn !== true) {
|
||||
if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
|
||||
childrens.unshift(React.createElement(cellEl, { key: 'selection' }));
|
||||
} else {
|
||||
childrens.push(React.createElement(cellEl, { key: 'selection' }));
|
||||
}
|
||||
}
|
||||
|
||||
if (expandRow.showExpandColumn) {
|
||||
if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
|
||||
childrens.unshift(React.createElement(cellEl, { key: 'expansion' }));
|
||||
} else {
|
||||
childrens.push(React.createElement(cellEl, { key: 'expansion' }));
|
||||
}
|
||||
}
|
||||
|
||||
return <tr { ...rest }>{ childrens }</tr>;
|
||||
};
|
||||
|
||||
RowTemplate.propTypes = {
|
||||
renderContent: PropTypes.func.isRequired,
|
||||
cellEl: PropTypes.string.isRequired,
|
||||
selectRow: PropTypes.object,
|
||||
expandRow: PropTypes.object
|
||||
};
|
||||
|
||||
export default RowTemplate;
|
||||
@@ -2,14 +2,14 @@ import _ from '../utils';
|
||||
import { getRowByRowId } from './rows';
|
||||
|
||||
export const getSelectionSummary = (
|
||||
data,
|
||||
data = [],
|
||||
keyField,
|
||||
selected = []
|
||||
) => {
|
||||
let allRowsSelected = data.length > 0;
|
||||
let allRowsNotSelected = true;
|
||||
|
||||
const rowKeys = data.map(d => d[keyField]);
|
||||
const rowKeys = data.map(d => _.get(d, keyField));
|
||||
for (let i = 0; i < rowKeys.length; i += 1) {
|
||||
const curr = rowKeys[i];
|
||||
if (typeof selected.find(x => x === curr) === 'undefined') {
|
||||
@@ -24,7 +24,7 @@ export const getSelectionSummary = (
|
||||
};
|
||||
};
|
||||
|
||||
export const selectableKeys = (data, keyField, skips = []) => {
|
||||
export const selectableKeys = (data = [], keyField, skips = []) => {
|
||||
if (skips.length === 0) {
|
||||
return data.map(row => _.get(row, keyField));
|
||||
}
|
||||
@@ -40,6 +40,6 @@ export const unSelectableKeys = (selected, skips = []) => {
|
||||
return selected.filter(x => _.contains(skips, x));
|
||||
};
|
||||
|
||||
export const getSelectedRows = (data, keyField, selected) =>
|
||||
export const getSelectedRows = (data = [], keyField, selected) =>
|
||||
selected.map(k => getRowByRowId(data, keyField, k)).filter(x => !!x);
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ describe('Footer', () => {
|
||||
|
||||
describe('simplest footer', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(
|
||||
wrapper = render(
|
||||
<Footer
|
||||
data={ data }
|
||||
columns={ columns }
|
||||
@@ -61,7 +61,7 @@ describe('Footer', () => {
|
||||
it('should render successfully', () => {
|
||||
expect(wrapper.length).toBe(1);
|
||||
expect(wrapper.find('tr').length).toBe(1);
|
||||
expect(wrapper.find(FooterCell).length).toBe(columns.length);
|
||||
expect(wrapper.find('th').length).toBe(columns.length);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,7 +86,7 @@ describe('Footer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('when selecrRow prop is enable', () => {
|
||||
describe('when selectRow prop is enable', () => {
|
||||
beforeEach(() => {
|
||||
wrapper = render(
|
||||
<Footer
|
||||
|
||||
@@ -729,7 +729,13 @@ describe('HeaderCell', () => {
|
||||
}
|
||||
};
|
||||
wrapper = shallow(
|
||||
<HeaderCell column={ column } index={ index } onFilter={ onFilter } currFilters={ {} } />
|
||||
<HeaderCell
|
||||
column={ column }
|
||||
index={ index }
|
||||
onFilter={ onFilter }
|
||||
currFilters={ {} }
|
||||
filterPosition="inline"
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -767,7 +773,12 @@ describe('HeaderCell', () => {
|
||||
filterRenderer
|
||||
};
|
||||
wrapper = shallow(
|
||||
<HeaderCell column={ column } index={ index } onExternalFilter={ onExternalFilter } />);
|
||||
<HeaderCell
|
||||
column={ column }
|
||||
index={ index }
|
||||
filterPosition="inline"
|
||||
onExternalFilter={ onExternalFilter }
|
||||
/>);
|
||||
});
|
||||
|
||||
it('should render successfully', () => {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
exports[`<SelectionCell /> render should render component correctly 1`] = `
|
||||
<td
|
||||
className="selection-cell"
|
||||
onClick={[Function]}
|
||||
>
|
||||
<input
|
||||
|
||||
@@ -1686,9 +1686,10 @@ class-utils@^0.3.5:
|
||||
isobject "^3.0.0"
|
||||
static-extend "^0.1.1"
|
||||
|
||||
classnames@2.2.5:
|
||||
version "2.2.5"
|
||||
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.5.tgz#fb3801d453467649ef3603c7d61a02bd129bde6d"
|
||||
classnames@^2.2.5:
|
||||
version "2.2.6"
|
||||
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce"
|
||||
integrity sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==
|
||||
|
||||
clean-css@4.1.9, clean-css@4.1.x:
|
||||
version "4.1.9"
|
||||
|
||||
Reference in New Issue
Block a user