mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 05:30:05 +00:00
Compare commits
30 Commits
react-boot
...
react-boot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
@@ -32,6 +32,7 @@
|
|||||||
* [defaultSortDirection](#defaultSortDirection)
|
* [defaultSortDirection](#defaultSortDirection)
|
||||||
* [pagination](#pagination)
|
* [pagination](#pagination)
|
||||||
* [filter](#filter)
|
* [filter](#filter)
|
||||||
|
* [filterPosition](filterPosition)
|
||||||
* [onTableChange](#onTableChange)
|
* [onTableChange](#onTableChange)
|
||||||
* [onDataSizeChange](#onDataSizeChange)
|
* [onDataSizeChange](#onDataSizeChange)
|
||||||
|
|
||||||
@@ -208,6 +209,8 @@ const defaultSorted = [{
|
|||||||
}];
|
}];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Note**: Only the first column is sorted currently, see #1083.
|
||||||
|
|
||||||
### <a name='defaultSortDirection'>defaultSortDirection - [String]</a>
|
### <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`.
|
Default sort direction when user click on header column at first time, available value is `asc` and `desc`. Default is `desc`.
|
||||||
|
|
||||||
@@ -327,6 +330,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>
|
### <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:
|
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:
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
* [classes)](#classes)
|
* [classes)](#classes)
|
||||||
* [bgColor](#bgColor)
|
* [bgColor](#bgColor)
|
||||||
* [nonSelectable)](#nonSelectable)
|
* [nonSelectable)](#nonSelectable)
|
||||||
|
* [nonSelectableStyle](#nonSelectableStyle)
|
||||||
|
* [nonSelectableClasses](#nonSelectableClasses)
|
||||||
* [clickToSelect)](#clickToSelect)
|
* [clickToSelect)](#clickToSelect)
|
||||||
* [clickToExpand)](#clickToExpand)
|
* [clickToExpand)](#clickToExpand)
|
||||||
* [clickToEdit](#clickToEdit)
|
* [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>
|
### <a name='clickToSelect'>selectRow.clickToSelect - [Bool]</a>
|
||||||
Allow user to select row by clicking on the row.
|
Allow user to select row by clicking on the row.
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
"webpack-dev-server": "2.7.1"
|
"webpack-dev-server": "2.7.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"classnames": "2.2.5",
|
"classnames": "^2.2.5",
|
||||||
"prop-types": "15.5.10",
|
"prop-types": "15.5.10",
|
||||||
"react": "16.4.0",
|
"react": "16.4.0",
|
||||||
"react-dom": "16.4.0",
|
"react-dom": "16.4.0",
|
||||||
|
|||||||
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 = [{
|
const columns = [{
|
||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
text: 'Product ID'
|
text: 'Product ID',
|
||||||
|
footer: 'hello'
|
||||||
}, {
|
}, {
|
||||||
dataField: 'name',
|
dataField: 'name',
|
||||||
text: 'Product Name',
|
text: 'Product Name',
|
||||||
|
footer: 'hello',
|
||||||
filter: textFilter()
|
filter: textFilter()
|
||||||
}, {
|
}, {
|
||||||
dataField: 'price',
|
dataField: 'price',
|
||||||
text: 'Product Price',
|
text: 'Product Price',
|
||||||
|
footer: 'hello',
|
||||||
filter: textFilter()
|
filter: textFilter()
|
||||||
}];
|
}];
|
||||||
|
|
||||||
@@ -39,6 +42,11 @@ const columns = [{
|
|||||||
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
<BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true
|
||||||
|
};
|
||||||
|
|
||||||
export default () => (
|
export default () => (
|
||||||
<div>
|
<div>
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
@@ -46,6 +54,8 @@ export default () => (
|
|||||||
data={ products }
|
data={ products }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
filter={ filterFactory() }
|
filter={ filterFactory() }
|
||||||
|
filterPosition="bottom"
|
||||||
|
selectRow={ selectRow }
|
||||||
/>
|
/>
|
||||||
<Code>{ sourceCode }</Code>
|
<Code>{ sourceCode }</Code>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -36,11 +36,12 @@ const columns = [{
|
|||||||
|
|
||||||
const MyExportCSV = (props) => {
|
const MyExportCSV = (props) => {
|
||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
props.onExport();
|
// passing my custom data
|
||||||
|
props.onExport(products.filter(r => r.id > 2));
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<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>
|
</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>
|
||||||
|
);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-example",
|
"name": "react-bootstrap-table2-example",
|
||||||
"version": "1.0.31",
|
"version": "1.0.35",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ import AdvanceCustomFilter from 'examples/column-filter/advance-custom-filter';
|
|||||||
import ClearAllFilters from 'examples/column-filter/clear-all-filters';
|
import ClearAllFilters from 'examples/column-filter/clear-all-filters';
|
||||||
import FilterHooks from 'examples/column-filter/filter-hooks';
|
import FilterHooks from 'examples/column-filter/filter-hooks';
|
||||||
import CustomFilterLogic from 'examples/column-filter/custom-filter-logic';
|
import CustomFilterLogic from 'examples/column-filter/custom-filter-logic';
|
||||||
|
import FilterPosition from 'examples/column-filter/filter-position';
|
||||||
|
|
||||||
// work on rows
|
// work on rows
|
||||||
import RowStyleTable from 'examples/rows/row-style';
|
import RowStyleTable from 'examples/rows/row-style';
|
||||||
@@ -151,6 +152,8 @@ import HeaderStyleTable from 'examples/row-selection/header-style';
|
|||||||
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
|
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
|
||||||
import CustomSelectionTable from 'examples/row-selection/custom-selection';
|
import CustomSelectionTable from 'examples/row-selection/custom-selection';
|
||||||
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
|
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 SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
|
||||||
import SelectionHooks from 'examples/row-selection/selection-hooks';
|
import SelectionHooks from 'examples/row-selection/selection-hooks';
|
||||||
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
|
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
|
||||||
@@ -314,6 +317,7 @@ storiesOf('Column Filter', module)
|
|||||||
.add('Number Filter with Default Value', () => <NumberFilterWithDefaultValue />)
|
.add('Number Filter with Default Value', () => <NumberFilterWithDefaultValue />)
|
||||||
.add('Date Filter', () => <DateFilter />)
|
.add('Date Filter', () => <DateFilter />)
|
||||||
.add('Date Filter with Default Value', () => <DateFilterWithDefaultValue />)
|
.add('Date Filter with Default Value', () => <DateFilterWithDefaultValue />)
|
||||||
|
.add('Filter Position', () => <FilterPosition />)
|
||||||
.add('Custom Text Filter', () => <CustomTextFilter />)
|
.add('Custom Text Filter', () => <CustomTextFilter />)
|
||||||
.add('Custom Select Filter', () => <CustomSelectFilter />)
|
.add('Custom Select Filter', () => <CustomSelectFilter />)
|
||||||
.add('Custom Number Filter', () => <CustomNumberFilter />)
|
.add('Custom Number Filter', () => <CustomNumberFilter />)
|
||||||
@@ -408,6 +412,8 @@ storiesOf('Row Selection', module)
|
|||||||
.add('Custom Selection', () => <CustomSelectionTable />)
|
.add('Custom Selection', () => <CustomSelectionTable />)
|
||||||
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
||||||
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
|
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
|
||||||
|
.add('Not Selectabled Rows Style', () => <NonSelectableRowsStyleTable />)
|
||||||
|
.add('Not Selectabled Rows Class', () => <NonSelectableRowsClassTable />)
|
||||||
.add('Selection Hooks', () => <SelectionHooks />)
|
.add('Selection Hooks', () => <SelectionHooks />)
|
||||||
.add('Hide Selection Column', () => <HideSelectionColumnTable />)
|
.add('Hide Selection Column', () => <HideSelectionColumnTable />)
|
||||||
.add('Custom Selection Column Style', () => <SelectionColumnStyleTable />)
|
.add('Custom Selection Column Style', () => <SelectionColumnStyleTable />)
|
||||||
|
|||||||
@@ -330,3 +330,29 @@ Following properties is valid in `FILTER_TYPES`:
|
|||||||
* NUMBER
|
* NUMBER
|
||||||
* DATE
|
* DATE
|
||||||
* MULTISELECT
|
* 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",
|
"name": "react-bootstrap-table2-filter",
|
||||||
"version": "1.2.0",
|
"version": "1.3.0",
|
||||||
"description": "it's a column filter addon for react-bootstrap-table2",
|
"description": "it's a column filter addon for react-bootstrap-table2",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table-next",
|
"name": "react-bootstrap-table-next",
|
||||||
"version": "3.2.0",
|
"version": "3.3.2",
|
||||||
"description": "Next generation of react-bootstrap-table",
|
"description": "Next generation of react-bootstrap-table",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import PropTypes from 'prop-types';
|
|||||||
import cs from 'classnames';
|
import cs from 'classnames';
|
||||||
|
|
||||||
import Header from './header';
|
import Header from './header';
|
||||||
|
import Filters from './filters';
|
||||||
import Caption from './caption';
|
import Caption from './caption';
|
||||||
import Body from './body';
|
import Body from './body';
|
||||||
import Footer from './footer';
|
import Footer from './footer';
|
||||||
@@ -65,7 +66,8 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
rowEvents,
|
rowEvents,
|
||||||
selectRow,
|
selectRow,
|
||||||
expandRow,
|
expandRow,
|
||||||
cellEdit
|
cellEdit,
|
||||||
|
filterPosition
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const tableWrapperClass = cs('react-bootstrap-table', wrapperClasses);
|
const tableWrapperClass = cs('react-bootstrap-table', wrapperClasses);
|
||||||
@@ -77,6 +79,8 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
[bootstrap4 ? 'table-sm' : 'table-condensed']: condensed
|
[bootstrap4 ? 'table-sm' : 'table-condensed']: condensed
|
||||||
}, classes);
|
}, classes);
|
||||||
|
|
||||||
|
const hasFilters = columns.some(col => col.filter || col.filterRenderer);
|
||||||
|
|
||||||
const hasFooter = _.filter(columns, col => _.has(col, 'footer')).length > 0;
|
const hasFooter = _.filter(columns, col => _.has(col, 'footer')).length > 0;
|
||||||
|
|
||||||
const tableCaption = (caption && <Caption>{ caption }</Caption>);
|
const tableCaption = (caption && <Caption>{ caption }</Caption>);
|
||||||
@@ -96,7 +100,21 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
onExternalFilter={ this.props.onExternalFilter }
|
onExternalFilter={ this.props.onExternalFilter }
|
||||||
selectRow={ selectRow }
|
selectRow={ selectRow }
|
||||||
expandRow={ expandRow }
|
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
|
<Body
|
||||||
data={ this.getData() }
|
data={ this.getData() }
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
@@ -135,7 +153,7 @@ BootstrapTable.propTypes = {
|
|||||||
remote: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
|
remote: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
|
||||||
pagination: PropTypes.bool
|
pagination: PropTypes.bool
|
||||||
})]),
|
})]),
|
||||||
noDataIndication: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
noDataIndication: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
||||||
striped: PropTypes.bool,
|
striped: PropTypes.bool,
|
||||||
bordered: PropTypes.bool,
|
bordered: PropTypes.bool,
|
||||||
hover: PropTypes.bool,
|
hover: PropTypes.bool,
|
||||||
@@ -166,6 +184,8 @@ BootstrapTable.propTypes = {
|
|||||||
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||||
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
nonSelectable: PropTypes.array,
|
nonSelectable: PropTypes.array,
|
||||||
|
nonSelectableStyle: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
|
nonSelectableClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
hideSelectColumn: PropTypes.bool,
|
hideSelectColumn: PropTypes.bool,
|
||||||
selectionRenderer: PropTypes.func,
|
selectionRenderer: PropTypes.func,
|
||||||
@@ -199,6 +219,12 @@ BootstrapTable.propTypes = {
|
|||||||
rowEvents: PropTypes.object,
|
rowEvents: PropTypes.object,
|
||||||
rowClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
rowClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
headerClasses: PropTypes.string,
|
headerClasses: PropTypes.string,
|
||||||
|
filtersClasses: PropTypes.string,
|
||||||
|
filterPosition: PropTypes.oneOf([
|
||||||
|
Const.FILTERS_POSITION_TOP,
|
||||||
|
Const.FILTERS_POSITION_INLINE,
|
||||||
|
Const.FILTERS_POSITION_BOTTOM
|
||||||
|
]),
|
||||||
footerClasses: PropTypes.string,
|
footerClasses: PropTypes.string,
|
||||||
defaultSorted: PropTypes.arrayOf(PropTypes.shape({
|
defaultSorted: PropTypes.arrayOf(PropTypes.shape({
|
||||||
dataField: PropTypes.string.isRequired,
|
dataField: PropTypes.string.isRequired,
|
||||||
@@ -240,7 +266,8 @@ BootstrapTable.defaultProps = {
|
|||||||
cellEdit: {
|
cellEdit: {
|
||||||
mode: null,
|
mode: null,
|
||||||
nonEditableRows: []
|
nonEditableRows: []
|
||||||
}
|
},
|
||||||
|
filterPosition: Const.FILTERS_POSITION_INLINE
|
||||||
};
|
};
|
||||||
|
|
||||||
export default BootstrapTable;
|
export default BootstrapTable;
|
||||||
|
|||||||
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_STRING: 'string',
|
||||||
TYPE_NUMBER: 'number',
|
TYPE_NUMBER: 'number',
|
||||||
TYPE_BOOLEAN: 'bool',
|
TYPE_BOOLEAN: 'bool',
|
||||||
TYPE_DATE: 'date'
|
TYPE_DATE: 'date',
|
||||||
|
FILTERS_POSITION_INLINE: 'inline',
|
||||||
|
FILTERS_POSITION_TOP: 'top',
|
||||||
|
FILTERS_POSITION_BOTTOM: 'bottom'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Const from '../const';
|
import Const from '../const';
|
||||||
|
import _ from '../utils';
|
||||||
|
|
||||||
import dataOperator from '../store/operators';
|
import dataOperator from '../store/operators';
|
||||||
import { getSelectionSummary } from '../store/selection';
|
import { getSelectionSummary } from '../store/selection';
|
||||||
@@ -72,7 +73,7 @@ class SelectionProvider extends React.Component {
|
|||||||
if (!isUnSelect) {
|
if (!isUnSelect) {
|
||||||
currSelected = selected.concat(dataOperator.selectableKeys(data, keyField, nonSelectable));
|
currSelected = selected.concat(dataOperator.selectableKeys(data, keyField, nonSelectable));
|
||||||
} else {
|
} 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;
|
let result;
|
||||||
|
|||||||
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;
|
||||||
36
packages/react-bootstrap-table2/src/footer.js
vendored
36
packages/react-bootstrap-table2/src/footer.js
vendored
@@ -2,20 +2,15 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import Const from './const';
|
import RowTemplate from './row/row-template';
|
||||||
import FooterCell from './footer-cell';
|
import FooterCell from './footer-cell';
|
||||||
import _ from './utils';
|
import _ from './utils';
|
||||||
|
|
||||||
const Footer = (props) => {
|
const Footer = (props) => {
|
||||||
const { data, className, columns, selectRow, expandRow } = props;
|
const { data, className, columns, selectRow, expandRow } = props;
|
||||||
const SelectionFooterCellComp = () => <th />;
|
|
||||||
const ExpansionFooterCellComp = () => <th />;
|
|
||||||
|
|
||||||
const isRenderFunctionColumnInLeft = (
|
function renderContent() {
|
||||||
position = Const.INDICATOR_POSITION_LEFT
|
return columns.map((column, i) => {
|
||||||
) => position === Const.INDICATOR_POSITION_LEFT;
|
|
||||||
|
|
||||||
const childrens = columns.map((column, i) => {
|
|
||||||
if (column.footer === undefined || column.footer === null) {
|
if (column.footer === undefined || column.footer === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -31,28 +26,17 @@ const Footer = (props) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
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 (
|
return (
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr className={ className }>
|
<RowTemplate
|
||||||
{ childrens }
|
renderContent={ renderContent }
|
||||||
</tr>
|
selectRow={ selectRow }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
className={ className }
|
||||||
|
cellEl="th"
|
||||||
|
/>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class HeaderCell extends eventDelegater(React.Component) {
|
|||||||
isLastSorting,
|
isLastSorting,
|
||||||
onFilter,
|
onFilter,
|
||||||
currFilters,
|
currFilters,
|
||||||
|
filterPosition,
|
||||||
onExternalFilter
|
onExternalFilter
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
@@ -43,10 +44,14 @@ class HeaderCell extends eventDelegater(React.Component) {
|
|||||||
|
|
||||||
const delegateEvents = this.delegate(headerEvents);
|
const delegateEvents = this.delegate(headerEvents);
|
||||||
|
|
||||||
|
const customAttrs = _.isFunction(headerAttrs)
|
||||||
|
? headerAttrs(column, index)
|
||||||
|
: (headerAttrs || {});
|
||||||
|
|
||||||
const cellAttrs = {
|
const cellAttrs = {
|
||||||
..._.isFunction(headerAttrs) ? headerAttrs(column, index) : headerAttrs,
|
...customAttrs,
|
||||||
...delegateEvents,
|
...delegateEvents,
|
||||||
tabIndex: 0
|
tabIndex: _.isDefined(customAttrs.tabIndex) ? customAttrs.tabIndex : 0
|
||||||
};
|
};
|
||||||
|
|
||||||
let sortSymbol;
|
let sortSymbol;
|
||||||
@@ -100,6 +105,7 @@ class HeaderCell extends eventDelegater(React.Component) {
|
|||||||
if (cellClasses) cellAttrs.className = cs(cellAttrs.className, cellClasses);
|
if (cellClasses) cellAttrs.className = cs(cellAttrs.className, cellClasses);
|
||||||
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
|
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
|
||||||
|
|
||||||
|
if (filterPosition === Const.FILTERS_POSITION_INLINE) {
|
||||||
if (filterRenderer) {
|
if (filterRenderer) {
|
||||||
const onCustomFilter = onExternalFilter(column, filter.props.type);
|
const onCustomFilter = onExternalFilter(column, filter.props.type);
|
||||||
filterElm = filterRenderer(onCustomFilter, column);
|
filterElm = filterRenderer(onCustomFilter, column);
|
||||||
@@ -113,6 +119,7 @@ class HeaderCell extends eventDelegater(React.Component) {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const children = headerFormatter ?
|
const children = headerFormatter ?
|
||||||
headerFormatter(column, index, { sortElement: sortSymbol, filterElement: filterElm }) :
|
headerFormatter(column, index, { sortElement: sortSymbol, filterElement: filterElm }) :
|
||||||
@@ -176,6 +183,8 @@ HeaderCell.propTypes = {
|
|||||||
sortCaret: PropTypes.func,
|
sortCaret: PropTypes.func,
|
||||||
isLastSorting: PropTypes.bool,
|
isLastSorting: PropTypes.bool,
|
||||||
onFilter: PropTypes.func,
|
onFilter: PropTypes.func,
|
||||||
|
filterPosition: PropTypes.oneOf([Const.FILTERS_POSITION_INLINE,
|
||||||
|
Const.FILTERS_POSITION_BOTTOM, Const.FILTERS_POSITION_TOP]),
|
||||||
currFilters: PropTypes.object,
|
currFilters: PropTypes.object,
|
||||||
onExternalFilter: PropTypes.func
|
onExternalFilter: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|||||||
15
packages/react-bootstrap-table2/src/header.js
vendored
15
packages/react-bootstrap-table2/src/header.js
vendored
@@ -18,9 +18,10 @@ const Header = (props) => {
|
|||||||
sortField,
|
sortField,
|
||||||
sortOrder,
|
sortOrder,
|
||||||
selectRow,
|
selectRow,
|
||||||
|
expandRow,
|
||||||
currFilters,
|
currFilters,
|
||||||
onExternalFilter,
|
onExternalFilter,
|
||||||
expandRow
|
filterPosition
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
let SelectionHeaderCellComp = () => null;
|
let SelectionHeaderCellComp = () => null;
|
||||||
@@ -50,11 +51,12 @@ const Header = (props) => {
|
|||||||
column={ column }
|
column={ column }
|
||||||
onSort={ onSort }
|
onSort={ onSort }
|
||||||
sorting={ currSort }
|
sorting={ currSort }
|
||||||
|
sortOrder={ sortOrder }
|
||||||
|
isLastSorting={ isLastSorting }
|
||||||
onFilter={ onFilter }
|
onFilter={ onFilter }
|
||||||
currFilters={ currFilters }
|
currFilters={ currFilters }
|
||||||
onExternalFilter={ onExternalFilter }
|
onExternalFilter={ onExternalFilter }
|
||||||
sortOrder={ sortOrder }
|
filterPosition={ filterPosition }
|
||||||
isLastSorting={ isLastSorting }
|
|
||||||
/>);
|
/>);
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
@@ -94,7 +96,12 @@ Header.propTypes = {
|
|||||||
currFilters: PropTypes.object,
|
currFilters: PropTypes.object,
|
||||||
onExternalFilter: PropTypes.func,
|
onExternalFilter: PropTypes.func,
|
||||||
className: PropTypes.string,
|
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;
|
export default Header;
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
export default ExtendBase =>
|
export default ExtendBase =>
|
||||||
class ColumnResolver extends ExtendBase {
|
class ColumnResolver extends ExtendBase {
|
||||||
visibleColumnSize(includeSelectColumn = true) {
|
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 (!includeSelectColumn) return columnLen;
|
||||||
if (this.props.selectRow && !this.props.selectRow.hideSelectColumn) {
|
if (this.props.selectRow && !this.props.selectRow.hideSelectColumn) {
|
||||||
columnLen += 1;
|
columnLen += 1;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export default class ExpandCell extends Component {
|
|||||||
if (tabIndex !== -1) attrs.tabIndex = tabIndex;
|
if (tabIndex !== -1) attrs.tabIndex = tabIndex;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<td onClick={ this.handleClick } { ...attrs }>
|
<td className="expand-cell" onClick={ this.handleClick } { ...attrs }>
|
||||||
{
|
{
|
||||||
expandColumnRenderer ? expandColumnRenderer({
|
expandColumnRenderer ? expandColumnRenderer({
|
||||||
expandable,
|
expandable,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export default class ExpansionHeaderCell extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<th data-row-selection { ...attrs }>
|
<th className="expand-cell-header" data-row-selection { ...attrs }>
|
||||||
{
|
{
|
||||||
expandHeaderColumnRenderer ?
|
expandHeaderColumnRenderer ?
|
||||||
expandHeaderColumnRenderer({ isAnyExpands }) :
|
expandHeaderColumnRenderer({ isAnyExpands }) :
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export default (Component) => {
|
|||||||
const key = props.value;
|
const key = props.value;
|
||||||
const selected = _.contains(selectRow.selected, key);
|
const selected = _.contains(selectRow.selected, key);
|
||||||
const selectable = !selectRow.nonSelectable || !_.contains(selectRow.nonSelectable, key);
|
const selectable = !selectRow.nonSelectable || !_.contains(selectRow.nonSelectable, key);
|
||||||
|
const notSelectable = _.contains(selectRow.nonSelectable, key);
|
||||||
|
|
||||||
let {
|
let {
|
||||||
style,
|
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 (
|
return (
|
||||||
<Component
|
<Component
|
||||||
{ ...props }
|
{ ...props }
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export default class SelectionCell extends Component {
|
|||||||
<BootstrapContext.Consumer>
|
<BootstrapContext.Consumer>
|
||||||
{
|
{
|
||||||
({ bootstrap4 }) => (
|
({ bootstrap4 }) => (
|
||||||
<td onClick={ this.handleClick } { ...attrs }>
|
<td className="selection-cell" onClick={ this.handleClick } { ...attrs }>
|
||||||
{
|
{
|
||||||
selectionRenderer ? selectionRenderer({
|
selectionRenderer ? selectionRenderer({
|
||||||
mode: inputType,
|
mode: inputType,
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ export default class SelectionHeaderCell extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
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';
|
import { getRowByRowId } from './rows';
|
||||||
|
|
||||||
export const getSelectionSummary = (
|
export const getSelectionSummary = (
|
||||||
data,
|
data = [],
|
||||||
keyField,
|
keyField,
|
||||||
selected = []
|
selected = []
|
||||||
) => {
|
) => {
|
||||||
let allRowsSelected = data.length > 0;
|
let allRowsSelected = data.length > 0;
|
||||||
let allRowsNotSelected = true;
|
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) {
|
for (let i = 0; i < rowKeys.length; i += 1) {
|
||||||
const curr = rowKeys[i];
|
const curr = rowKeys[i];
|
||||||
if (typeof selected.find(x => x === curr) === 'undefined') {
|
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) {
|
if (skips.length === 0) {
|
||||||
return data.map(row => _.get(row, keyField));
|
return data.map(row => _.get(row, keyField));
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,6 @@ export const unSelectableKeys = (selected, skips = []) => {
|
|||||||
return selected.filter(x => _.contains(skips, x));
|
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);
|
selected.map(k => getRowByRowId(data, keyField, k)).filter(x => !!x);
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ describe('Footer', () => {
|
|||||||
|
|
||||||
describe('simplest footer', () => {
|
describe('simplest footer', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = render(
|
||||||
<Footer
|
<Footer
|
||||||
data={ data }
|
data={ data }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -61,7 +61,7 @@ describe('Footer', () => {
|
|||||||
it('should render successfully', () => {
|
it('should render successfully', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(1);
|
||||||
expect(wrapper.find('tr').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(() => {
|
beforeEach(() => {
|
||||||
wrapper = render(
|
wrapper = render(
|
||||||
<Footer
|
<Footer
|
||||||
|
|||||||
@@ -729,7 +729,13 @@ describe('HeaderCell', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
wrapper = shallow(
|
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
|
filterRenderer
|
||||||
};
|
};
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<HeaderCell column={ column } index={ index } onExternalFilter={ onExternalFilter } />);
|
<HeaderCell
|
||||||
|
column={ column }
|
||||||
|
index={ index }
|
||||||
|
filterPosition="inline"
|
||||||
|
onExternalFilter={ onExternalFilter }
|
||||||
|
/>);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render successfully', () => {
|
it('should render successfully', () => {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
exports[`<SelectionCell /> render should render component correctly 1`] = `
|
exports[`<SelectionCell /> render should render component correctly 1`] = `
|
||||||
<td
|
<td
|
||||||
|
className="selection-cell"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
|
|||||||
@@ -1686,9 +1686,10 @@ class-utils@^0.3.5:
|
|||||||
isobject "^3.0.0"
|
isobject "^3.0.0"
|
||||||
static-extend "^0.1.1"
|
static-extend "^0.1.1"
|
||||||
|
|
||||||
classnames@2.2.5:
|
classnames@^2.2.5:
|
||||||
version "2.2.5"
|
version "2.2.6"
|
||||||
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.5.tgz#fb3801d453467649ef3603c7d61a02bd129bde6d"
|
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:
|
clean-css@4.1.9, clean-css@4.1.x:
|
||||||
version "4.1.9"
|
version "4.1.9"
|
||||||
|
|||||||
Reference in New Issue
Block a user