Compare commits

...

30 Commits

Author SHA1 Message Date
dependabot[bot]
cbd0194f45 Bump eslint from 4.5.0 to 4.18.2
Bumps [eslint](https://github.com/eslint/eslint) from 4.5.0 to 4.18.2.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v4.5.0...v4.18.2)

Signed-off-by: dependabot[bot] <support@github.com>
2019-11-09 07:02:45 +00:00
Allen
ec742a43f6 Merge pull request #1149 from react-bootstrap-table/develop
20191109 release
2019-11-09 15:01:06 +08:00
AllenFang
7138b68559 fix test cases 2019-11-09 14:49:42 +08:00
AllenFang
e6e7d6f9d2 Merge branch 'aliogaili-master' into develop 2019-10-26 15:23:49 +08:00
AllenFang
909a6e211e close #1005 2019-10-26 15:23:14 +08:00
Ali Ogaili
83c9d69e27 More eslint errors fixing. 2019-10-26 14:31:52 +08:00
Ali Ogaili
aad2ad3823 Fix eslint errors. 2019-10-26 14:31:52 +08:00
Ali Ogaili
9190cfc6d9 fix https://github.com/react-bootstrap-table/react-bootstrap-table2/issues/1005 2019-10-26 14:31:09 +08:00
AllenFang
45b133579b fix #1124 2019-10-26 14:22:44 +08:00
AllenFang
970f7c0d15 update yarn lock file 2019-10-13 13:30:40 +08:00
Mark J. Lehman
def898f636 Avoid exact version lock for classnames (#1107)
Fixes #732
2019-10-13 13:22:46 +08:00
AllenFang
be916d81a3 Publish
- react-bootstrap-table2-example@1.0.32
 - react-bootstrap-table-next@3.2.1
2019-09-30 13:04:37 +08:00
Allen
49d1ce8812 Merge pull request #1109 from react-bootstrap-table/develop
20190929 release
2019-09-30 13:01:54 +08:00
AllenFang
18caf0ac8d try to fix #1085 and #1098 2019-09-29 16:36:32 +08:00
AllenFang
1b9bd63370 fix #1104 2019-09-29 16:30:49 +08:00
AllenFang
b2121fdf24 fix #1099 #1101 2019-09-29 16:19:36 +08:00
AllenFang
4aaf140de5 fix wrong story code 2019-09-29 15:06:11 +08:00
ebfg
569aa0195e Note in defaultSorted docs that only one column is supported. #1083 (#1088) 2019-09-15 14:36:10 +08:00
AllenFang
cf5b24e9e8 Publish
- react-bootstrap-table2-editor@1.4.0
 - react-bootstrap-table2-example@1.0.31
 - react-bootstrap-table2-filter@1.2.0
 - react-bootstrap-table2-paginator@2.1.0
 - react-bootstrap-table2-toolkit@2.1.0
 - react-bootstrap-table-next@3.2.0
2019-09-08 15:31:51 +08:00
Allen
da86b4aa1a Merge pull request #1087 from react-bootstrap-table/develop
20190908 release
2019-09-08 15:30:23 +08:00
AllenFang
7d28d46185 enhance footer event 2019-09-07 16:27:18 +08:00
AllenFang
16128e77e6 fix #1077 2019-09-07 16:25:49 +08:00
AllenFang
ec1f96cd1f fix #1082 2019-09-07 15:56:13 +08:00
AllenFang
00b1558df0 fix #1078 2019-09-07 14:44:18 +08:00
AllenFang
4dc5e6099f Merge branch 'chimericdream-master' into develop 2019-08-31 14:19:15 +08:00
AllenFang
d9acbace67 refine #1073 2019-08-31 14:18:55 +08:00
Bill Parrott
7c8bf00cde execute react-codemod on entire codebase to remove warnings on React 16.9.x 2019-08-28 15:32:22 -05:00
Bill Parrott
63df43a1e0 Merge branch 'master' of github.com:react-bootstrap-table/react-bootstrap-table2 2019-08-28 14:32:12 -05:00
Bill Parrott
2b410fb8ac Merge branch 'master' of github.com:react-bootstrap-table/react-bootstrap-table2 2019-08-12 13:34:14 -05:00
Bill Parrott
e31b5eb691 set tabindex to 0 for table headers; fixes #955 2019-06-03 09:26:15 -05:00
52 changed files with 953 additions and 313 deletions

View File

@@ -32,6 +32,7 @@
* [defaultSortDirection](#defaultSortDirection)
* [pagination](#pagination)
* [filter](#filter)
* [filterPosition](filterPosition)
* [onTableChange](#onTableChange)
* [onDataSizeChange](#onDataSizeChange)
@@ -208,6 +209,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 +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>
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:

View File

@@ -13,6 +13,7 @@ Available properties in a column object:
* [formatExtraData](#formatExtraData)
* [type](#type)
* [sort](#sort)
* [sortValue](#sortValue)
* [sortFunc](#sortFunc)
* [sortCaret](#sortCaret)
* [onSort](#onSort)
@@ -141,8 +142,42 @@ Specify the data type on column. Available value so far is `string`, `number`, `
## <a name='sort'>column.sort - [Bool]</a>
Enable the column sort via a `true` value given.
## <a name='sortValue'>column.sortValue - [Function]</a>
`column.sortValue` only work when `column.sort` enabled. This prop allow you to replace the value when table sorting.
For example, consider following data:
```js
const types = ['Cloud Service', 'Message Service', 'Add Service', 'Edit Service', 'Money'];
const data = [{id: 1, type: 2}, {id: 2, type: 1}, {id: 3, type:0}];
const columns = [{
dataField: 'id',
text: 'Job ID'
}, {
dataField: 'type',
text: 'Job Type'
sort: true,
formatter: (cell, row) => types[cell]
}]
```
In above case, when user try to sort Job Type column which will sort the original value: 0, 1, 2 but we display the type name via [`column.formatter`](#formatter), which will lead confuse because we are sorting by type value instead of type name. So `sortValue` is a way for you to decide what kind of value should be adopted when sorting on a specify column:
```js
const columns = [{
dataField: 'id',
text: 'Job ID'
}, {
dataField: 'type',
text: 'Job Type'
sort: true,
formatter: (cell, row) => types[cell],
sortValue: (cell, row) => types[cell] // we use type name to sort.
}]
```
## <a name='sortFunc'>column.sortFunc - [Function]</a>
`column.sortFunc` only work when `column.sort` is enable. `sortFunc` allow you to define your sorting algorithm. This callback function accept six arguments:
`column.sortFunc` only work when `column.sort` enabled. `sortFunc` allow you to define your sorting algorithm. This callback function accept six arguments:
```js
{
@@ -421,7 +456,7 @@ If the events is not listed above, the callback function will only pass the `eve
{
// omit...
headerEvents: {
onClick: e => { ... }
onClick: (e, column, columnIndex) => { ... }
}
}
```
@@ -631,7 +666,7 @@ It's also available to custom via a callback function:
{
// omit...
footerEvents: {
onClick: e => { ... }
onClick: (e, column, columnIndex) => { ... }
}
}
```

View File

@@ -53,7 +53,7 @@
"enzyme": "3.4.0",
"enzyme-adapter-react-16.3": "1.0.0",
"enzyme-to-json": "3.3.4",
"eslint": "4.5.0",
"eslint": "4.18.2",
"eslint-config-airbnb": "15.1.0",
"eslint-loader": "1.9.0",
"eslint-plugin-import": "2.7.0",
@@ -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",

View File

@@ -1,6 +1,6 @@
{
"name": "react-bootstrap-table2-editor",
"version": "1.3.2",
"version": "1.4.0",
"description": "it's the editor addon for react-bootstrap-table2",
"main": "./lib/index.js",
"scripts": {

View File

@@ -1,5 +1,8 @@
/* eslint disable-next-line: 0 */
/* eslint react/prop-types: 0 */
/* eslint react/require-default-props: 0 */
/* eslint camelcase: 0 */
/* eslint react/no-unused-prop-types: 0 */
import React from 'react';
import PropTypes from 'prop-types';
import { CLICK_TO_CELL_EDIT, DBCLICK_TO_CELL_EDIT } from './const';
@@ -43,7 +46,7 @@ export default (
};
}
componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.cellEdit && isRemoteCellEdit()) {
if (nextProps.cellEdit.options.errorMessage) {
this.setState(() => ({

View File

@@ -2,6 +2,7 @@
/* eslint no-return-assign: 0 */
/* eslint class-methods-use-this: 0 */
/* eslint jsx-a11y/no-noninteractive-element-interactions: 0 */
/* eslint camelcase: 0 */
import React, { Component } from 'react';
import cs from 'classnames';
import PropTypes from 'prop-types';
@@ -51,7 +52,11 @@ export default (_, onStartEdit) =>
};
}
componentWillReceiveProps({ message }) {
componentWillUnmount() {
this.clearTimer();
}
UNSAFE_componentWillReceiveProps({ message }) {
if (_.isDefined(message)) {
this.createTimer();
this.setState(() => ({
@@ -60,10 +65,6 @@ export default (_, onStartEdit) =>
}
}
componentWillUnmount() {
this.clearTimer();
}
clearTimer() {
if (this.indicatorTimer) {
clearTimeout(this.indicatorTimer);

View File

@@ -117,7 +117,7 @@ describe('CellEditContext', () => {
wrapper = shallow(shallowContext());
wrapper.setState(initialState);
wrapper.render();
wrapper.instance().componentWillReceiveProps({});
wrapper.instance().UNSAFE_componentWillReceiveProps({});
});
it('should not set state.message', () => {
@@ -138,7 +138,7 @@ describe('CellEditContext', () => {
wrapper = shallow(shallowContext());
wrapper.setState(initialState);
wrapper.render();
wrapper.instance().componentWillReceiveProps({
wrapper.instance().UNSAFE_componentWillReceiveProps({
cellEdit: cellEditFactory(defaultCellEdit)
});
});
@@ -164,7 +164,7 @@ describe('CellEditContext', () => {
wrapper = shallow(shallowContext(defaultCellEdit, true));
wrapper.setState(initialState);
wrapper.render();
wrapper.instance().componentWillReceiveProps({
wrapper.instance().UNSAFE_componentWillReceiveProps({
cellEdit: cellEditFactory({
...defaultCellEdit,
errorMessage: message
@@ -190,7 +190,7 @@ describe('CellEditContext', () => {
beforeEach(() => {
wrapper = shallow(shallowContext(defaultCellEdit, true));
wrapper.setState(initialState);
wrapper.instance().componentWillReceiveProps({
wrapper.instance().UNSAFE_componentWillReceiveProps({
cellEdit: cellEditFactory({ ...defaultCellEdit })
});
wrapper.update();

View File

@@ -0,0 +1,93 @@
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"
/>
`;
export default () => (
<div>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
filter={ filterFactory() }
filterPosition="top"
/>
<Code>{ sourceCode1 }</Code>
<BootstrapTable
keyField="id"
data={ products }
columns={ columns }
filter={ filterFactory() }
filterPosition="bottom"
/>
<Code>{ sourceCode2 }</Code>
</div>
);

View File

@@ -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>

View File

@@ -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>
);
};

View File

@@ -12,7 +12,7 @@ const columns = [{
dataField: 'id',
text: 'Product ID',
footerEvents: {
onClick: () => alert('Click on Product ID footer column')
onClick: (e, column, columnIndex) => alert(`Click on Product ID header column, columnIndex: ${columnIndex}`)
},
footer: 'Footer 1'
}, {
@@ -32,7 +32,7 @@ const columns = [{
dataField: 'id',
text: 'Product ID',
footerEvents: {
onClick: () => alert('Click on Product ID footer column')
onClick: (e, column, columnIndex) => alert('Click on Product ID footer column')
},
footer: 'Footer 1'
}, {

View File

@@ -12,7 +12,7 @@ const columns = [{
dataField: 'id',
text: 'Product ID',
headerEvents: {
onClick: () => alert('Click on Product ID header column')
onClick: (e, column, columnIndex) => alert(`Click on Product ID header column, columnIndex: ${columnIndex}`)
}
}, {
dataField: 'name',
@@ -29,7 +29,7 @@ const columns = [{
dataField: 'id',
text: 'Product ID',
headerEvents: {
onClick: () => alert('Click on Product ID header column')
onClick: (e, column, columnIndex) => alert('Click on Product ID header column')
}
}, {
dataField: 'name',

View File

@@ -0,0 +1,116 @@
/* eslint react/prop-types: 0 */
/* eslint no-unused-vars: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const { SearchBar } = Search;
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';
import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';
const { SearchBar } = Search;
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
// Implement startWith instead of contain
function customMatchFunc({
searchText,
value,
column,
row
}) {
if (typeof value !== 'undefined') {
return value.startsWith(searchText);
}
return false;
}
export default () => (
<div>
<ToolkitProvider
keyField="id"
data={ products }
columns={ columns }
search={ { customMatchFunc } }
>
{
props => (
<div>
<h3>Input something at below input field:</h3>
<SearchBar { ...props.searchProps } />
<hr />
<BootstrapTable
{ ...props.baseProps }
/>
</div>
)
}
</ToolkitProvider>
<Code>{ sourceCode }</Code>
</div>
);
`;
// Implement startWith instead of contain
function customMatchFunc({
searchText,
value,
column,
row
}) {
if (typeof value !== 'undefined') {
return `${value}`.toLowerCase().startsWith(searchText.toLowerCase());
}
return false;
}
export default () => (
<div>
<h1>Custom a search match function by startWith instead of contain</h1>
<ToolkitProvider
keyField="id"
data={ products }
columns={ columns }
search={ { onColumnMatch: customMatchFunc } }
>
{
props => (
<div>
<h3>Input something at below input field:</h3>
<SearchBar { ...props.searchProps } />
<hr />
<BootstrapTable
{ ...props.baseProps }
/>
</div>
)
}
</ToolkitProvider>
<Code>{ sourceCode }</Code>
</div>
);

View File

@@ -0,0 +1,78 @@
/* eslint no-unused-vars: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import Code from 'components/common/code-block';
import { jobsGenerator1 } from 'utils/common';
const jobs = jobsGenerator1(8);
const types = ['Cloud Service', 'Message Service', 'Add Service', 'Edit Service', 'Money'];
const columns = [{
dataField: 'id',
text: 'Job ID'
}, {
dataField: 'name',
text: 'Job Name'
}, {
dataField: 'owner',
text: 'Job Owner'
}, {
dataField: 'type',
text: 'Job Type',
sort: true,
formatter: (cell, row) => types[cell],
sortValue: (cell, row) => types[cell]
}];
const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';
const types = ['Cloud Service', 'Message Service', 'Add Service', 'Edit Service', 'Money'];
const columns = [{
dataField: 'id',
text: 'Job ID'
}, {
dataField: 'name',
text: 'Job Name'
}, {
dataField: 'owner',
text: 'Job Owner'
}, {
dataField: 'type',
text: 'Job Type',
sort: true,
formatter: (cell, row) => types[cell],
sortValue: (cell, row) => types[cell]
}];
<BootstrapTable keyField='id' data={ products } columns={ columns } />
`;
export default class Test extends React.Component {
constructor(props) {
super(props);
this.state = { data: jobs };
}
handleClick = () => {
this.setState(() => {
const newProducts = jobsGenerator1(21);
return {
data: newProducts
};
});
}
render() {
return (
<div>
<button className="btn btn-default" onClick={ this.handleClick }>Change Data</button>
<BootstrapTable keyField="id" data={ this.state.data } columns={ columns } />
<Code>{ sourceCode }</Code>
</div>
);
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "react-bootstrap-table2-example",
"version": "1.0.30",
"version": "1.0.32",
"description": "",
"main": "index.js",
"private": true,

View File

@@ -29,6 +29,11 @@ export const withOnSale = rows => rows.map((row) => {
return row;
});
export const withRandomPrice = rows => rows.map((row) => {
row.price = Math.floor((Math.random() * 10) + 2000);
return row;
});
export const productsQualityGenerator = (quantity = 5, factor = 0) =>
Array.from({ length: quantity }, (value, index) => ({
id: index + factor,

View File

@@ -92,6 +92,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 +105,7 @@ 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 CustomSortValue from 'examples/sort/custom-sort-value';
import CustomSortTable from 'examples/sort/custom-sort-table';
import CustomSortCaretTable from 'examples/sort/custom-sort-caret';
import HeaderSortingClassesTable from 'examples/sort/header-sorting-classes';
@@ -195,6 +197,7 @@ import FullyCustomSearch from 'examples/search/fully-custom-search';
import SearchFormattedData from 'examples/search/search-formatted';
import CustomSearchValue from 'examples/search/custom-search-value';
import SearchableColumn from 'examples/search/searchable-column';
import CustomMatchFunction from 'examples/search/custom-match-function';
// CSV
import ExportCSV from 'examples/csv';
@@ -312,6 +315,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 />)
@@ -356,6 +360,7 @@ storiesOf('Sort Table', module)
.add('Default Sort Table', () => <DefaultSortTable />)
.add('Default Sort Direction Table', () => <DefaultSortDirectionTable />)
.add('Sort Events', () => <SortEvents />)
.add('Custom Sort Value', () => <CustomSortValue />)
.add('Custom Sort Fuction', () => <CustomSortTable />)
.add('Custom Sort Caret', () => <CustomSortCaretTable />)
.add('Custom Classes on Sorting Header Column', () => <HeaderSortingClassesTable />)
@@ -451,7 +456,8 @@ storiesOf('Table Search', module)
.add('Searchable Column', () => <SearchableColumn />)
.add('Fully Custom Search', () => <FullyCustomSearch />)
.add('Search Formatted Value', () => <SearchFormattedData />)
.add('Custom Search Value', () => <CustomSearchValue />);
.add('Custom Search Value', () => <CustomSearchValue />)
.add('Custom match function', () => <CustomMatchFunction />);
storiesOf('Column Toggle', module)
.addDecorator(bootstrapStyle())

View File

@@ -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"
/>
```

View File

@@ -1,6 +1,6 @@
{
"name": "react-bootstrap-table2-filter",
"version": "1.1.12",
"version": "1.2.0",
"description": "it's a column filter addon for react-bootstrap-table2",
"main": "./lib/index.js",
"repository": {

View File

@@ -1,6 +1,7 @@
/* eslint react/require-default-props: 0 */
/* eslint react/prop-types: 0 */
/* eslint no-return-assign: 0 */
/* eslint camelcase: 0 */
import React, { Component } from 'react';
import { PropTypes } from 'prop-types';
@@ -41,16 +42,16 @@ class TextFilter extends Component {
}
}
componentWillReceiveProps(nextProps) {
componentWillUnmount() {
this.cleanTimer();
}
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.defaultValue !== this.props.defaultValue) {
this.applyFilter(nextProps.defaultValue);
}
}
componentWillUnmount() {
this.cleanTimer();
}
filter(e) {
e.stopPropagation();
this.cleanTimer();

View File

@@ -1,5 +1,6 @@
/* eslint react/prop-types: 0 */
/* eslint react/require-default-props: 0 */
/* eslint camelcase: 0 */
import React from 'react';
import PropTypes from 'prop-types';
@@ -37,15 +38,6 @@ export default (
}
}
componentWillReceiveProps(nextProps) {
// let nextData = nextProps.data;
if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.data)) {
this.doFilter(nextProps, this.isEmitDataChange);
} else {
this.data = nextProps.data;
}
}
onFilter(column, filterType, initialize = false) {
return (filterVal) => {
// watch out here if migration to context API, #334
@@ -90,6 +82,15 @@ export default (
return this.data;
}
UNSAFE_componentWillReceiveProps(nextProps) {
// let nextData = nextProps.data;
if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.data)) {
this.doFilter(nextProps, this.isEmitDataChange);
} else {
this.data = nextProps.data;
}
}
doFilter(props, ignoreEmitDataChange = false) {
const { dataChangeListener, data, columns } = props;
const result = filters(data, columns, _)(this.currFilters);

View File

@@ -144,7 +144,7 @@ describe('Text Filter', () => {
<TextFilter onFilter={ onFilter } column={ column } />
);
instance = wrapper.instance();
instance.componentWillReceiveProps(nextProps);
instance.UNSAFE_componentWillReceiveProps(nextProps);
});
it('should setting state correctly when props.defaultValue is changed', () => {

View File

@@ -1,6 +1,6 @@
{
"name": "react-bootstrap-table2-paginator",
"version": "2.0.8",
"version": "2.1.0",
"description": "it's the pagination addon for react-bootstrap-table2",
"main": "./lib/index.js",
"repository": {

View File

@@ -21,8 +21,9 @@ class PaginationDataProvider extends Provider {
isRemotePagination: PropTypes.func.isRequired
}
componentWillReceiveProps(nextProps) {
super.componentWillReceiveProps(nextProps);
// eslint-disable-next-line camelcase, react/sort-comp
UNSAFE_componentWillReceiveProps(nextProps) {
super.UNSAFE_componentWillReceiveProps(nextProps);
const { currSizePerPage } = this;
const { custom, onPageChange } = nextProps.pagination.options;

View File

@@ -1,4 +1,5 @@
/* eslint react/prop-types: 0 */
/* eslint camelcase: 0 */
import React, { Component } from 'react';
import pageResolver from './page-resolver';
@@ -12,7 +13,7 @@ export default WrappedComponent =>
this.state = this.initialState();
}
componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
const { dataSize, currSizePerPage } = nextProps;
if (currSizePerPage !== this.props.currSizePerPage || dataSize !== this.props.dataSize) {
const totalPages = this.calculateTotalPage(currSizePerPage, dataSize);

View File

@@ -1,6 +1,7 @@
/* eslint react/prop-types: 0 */
/* eslint react/require-default-props: 0 */
/* eslint no-lonely-if: 0 */
/* eslint camelcase: 0 */
import React from 'react';
import EventEmitter from 'events';
import Const from './const';
@@ -45,23 +46,6 @@ class StateProvider extends React.Component {
this.dataChangeListener.on('filterChanged', this.handleDataSizeChange);
}
componentWillReceiveProps(nextProps) {
const { custom } = nextProps.pagination.options;
// user should align the page when the page is not fit to the data size when remote enable
if (this.isRemotePagination() || custom) {
if (typeof nextProps.pagination.options.page !== 'undefined') {
this.currPage = nextProps.pagination.options.page;
}
if (typeof nextProps.pagination.options.sizePerPage !== 'undefined') {
this.currSizePerPage = nextProps.pagination.options.sizePerPage;
}
if (typeof nextProps.pagination.options.totalSize !== 'undefined') {
this.dataSize = nextProps.pagination.options.totalSize;
}
}
}
getPaginationProps = () => {
const { pagination: { options }, bootstrap4 } = this.props;
const { currPage, currSizePerPage, dataSize } = this;
@@ -113,6 +97,23 @@ class StateProvider extends React.Component {
getPaginationRemoteEmitter = () => this.remoteEmitter || this.props.remoteEmitter;
UNSAFE_componentWillReceiveProps(nextProps) {
const { custom } = nextProps.pagination.options;
// user should align the page when the page is not fit to the data size when remote enable
if (this.isRemotePagination() || custom) {
if (typeof nextProps.pagination.options.page !== 'undefined') {
this.currPage = nextProps.pagination.options.page;
}
if (typeof nextProps.pagination.options.sizePerPage !== 'undefined') {
this.currSizePerPage = nextProps.pagination.options.sizePerPage;
}
if (typeof nextProps.pagination.options.totalSize !== 'undefined') {
this.dataSize = nextProps.pagination.options.totalSize;
}
}
}
isRemotePagination = () => {
const e = {};
this.remoteEmitter.emit('isRemotePagination', e);

View File

@@ -174,7 +174,7 @@ describe('PaginationDataContext', () => {
data: [],
pagination: { ...defaultPagination }
};
instance.componentWillReceiveProps(nextProps);
instance.UNSAFE_componentWillReceiveProps(nextProps);
});
it('should reset currPage to first page', () => {
@@ -195,7 +195,7 @@ describe('PaginationDataContext', () => {
data: [],
pagination: { ...defaultPagination, options: { onPageChange } }
};
instance.componentWillReceiveProps(nextProps);
instance.UNSAFE_componentWillReceiveProps(nextProps);
});
it('should call options.onPageChange correctly', () => {

View File

@@ -164,13 +164,13 @@ describe('paginationHandler', () => {
});
it('should setting correct state.totalPages', () => {
instance.componentWillReceiveProps(nextProps);
instance.UNSAFE_componentWillReceiveProps(nextProps);
expect(instance.state.totalPages).toEqual(
instance.calculateTotalPage(nextProps.currSizePerPage));
});
it('should setting correct state.lastPage', () => {
instance.componentWillReceiveProps(nextProps);
instance.UNSAFE_componentWillReceiveProps(nextProps);
const totalPages = instance.calculateTotalPage(nextProps.currSizePerPage);
expect(instance.state.lastPage).toEqual(
instance.calculateLastPage(totalPages));
@@ -186,13 +186,13 @@ describe('paginationHandler', () => {
});
it('should setting correct state.totalPages', () => {
instance.componentWillReceiveProps(nextProps);
instance.UNSAFE_componentWillReceiveProps(nextProps);
expect(instance.state.totalPages).toEqual(
instance.calculateTotalPage(nextProps.currSizePerPage, nextProps.dataSize));
});
it('should setting correct state.lastPage', () => {
instance.componentWillReceiveProps(nextProps);
instance.UNSAFE_componentWillReceiveProps(nextProps);
const totalPages = instance.calculateTotalPage(
nextProps.currSizePerPage, nextProps.dataSize);
expect(instance.state.lastPage).toEqual(

View File

@@ -156,7 +156,7 @@ describe('PaginationStateContext', () => {
data,
pagination: { ...defaultPagination, options: { page: 3, sizePerPage: 5, totalSize: 50 } }
};
instance.componentWillReceiveProps(nextProps);
instance.UNSAFE_componentWillReceiveProps(nextProps);
});
it('should always reset currPage and currSizePerPage', () => {
@@ -181,7 +181,7 @@ describe('PaginationStateContext', () => {
options: { page: 3, sizePerPage: 5, custom: true, totalSize: 50 }
}
};
instance.componentWillReceiveProps(nextProps);
instance.UNSAFE_componentWillReceiveProps(nextProps);
});
it('should always reset currPage and currSizePerPage', () => {

View File

@@ -98,6 +98,33 @@ Accept a string that will be used for default searching when first time table re
</ToolkitProvider>
```
#### onColumnMatch - [function]
Acccpt a function which will be called when table try to match every cells when search happening. This function accept an object like below example:
```js
function onColumnMatch({
searchText,
value,
column,
row
}) {
// implement your custom match logic on every cell value
}
<ToolkitProvider
keyField="id"
data={ products }
columns={ columns }
search={ {
onColumnMatch
} }
>
// ...
</ToolkitProvider>
```
> Notes: You have to return `true` when your match logic is positive and vice versa.
#### searchFormatted - [bool]
If you want to search on the formatted data, you are supposed to enable this props. `react-bootstrap-table2` will check if you define the `column.formatter` when doing search.

View File

@@ -1,6 +1,6 @@
{
"name": "react-bootstrap-table2-toolkit",
"version": "2.0.1",
"version": "2.1.0",
"description": "The toolkit for react-bootstrap-table2",
"main": "./lib/index.js",
"repository": {

View File

@@ -1,3 +1,4 @@
/* eslint camelcase: 0 */
/* eslint no-return-assign: 0 */
import React from 'react';
import PropTypes from 'prop-types';
@@ -34,10 +35,6 @@ class SearchBar extends React.Component {
};
}
componentWillReceiveProps(nextProps) {
this.setState({ value: nextProps.searchText });
}
onChangeValue = (e) => {
this.setState({ value: e.target.value });
}
@@ -50,6 +47,10 @@ class SearchBar extends React.Component {
debounceCallback();
}
UNSAFE_componentWillReceiveProps(nextProps) {
this.setState({ value: nextProps.searchText });
}
render() {
const {
className,

View File

@@ -3,11 +3,13 @@
/* eslint no-continue: 0 */
/* eslint no-lonely-if: 0 */
/* eslint class-methods-use-this: 0 */
/* eslint camelcase: 0 */
import React from 'react';
import PropTypes from 'prop-types';
export default (options = {
searchFormatted: false
searchFormatted: false,
onColumnMatch: null
}) => (
_,
isRemoteSearch,
@@ -35,7 +37,17 @@ export default (options = {
this.state = { data: initialData };
}
componentWillReceiveProps(nextProps) {
getSearched() {
return this.state.data;
}
triggerListener(result) {
if (this.props.dataChangeListener) {
this.props.dataChangeListener.emit('filterChanged', result.length);
}
}
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.searchText !== this.props.searchText) {
if (isRemoteSearch()) {
handleRemoteSearchChange(nextProps.searchText);
@@ -59,16 +71,6 @@ export default (options = {
}
}
getSearched() {
return this.state.data;
}
triggerListener(result) {
if (this.props.dataChangeListener) {
this.props.dataChangeListener.emit('filterChanged', result.length);
}
}
search(props) {
const { data, columns } = props;
const searchText = props.searchText.toLowerCase();
@@ -82,11 +84,22 @@ export default (options = {
} else if (column.filterValue) {
targetValue = column.filterValue(targetValue, row);
}
if (targetValue !== null && typeof targetValue !== 'undefined') {
targetValue = targetValue.toString().toLowerCase();
if (targetValue.indexOf(searchText) > -1) {
if (options.onColumnMatch) {
if (options.onColumnMatch({
searchText,
value: targetValue,
column,
row
})) {
return true;
}
} else {
if (targetValue !== null && typeof targetValue !== 'undefined') {
targetValue = targetValue.toString().toLowerCase();
if (targetValue.indexOf(searchText) > -1) {
return true;
}
}
}
}
return false;

View File

@@ -1,6 +1,6 @@
{
"name": "react-bootstrap-table-next",
"version": "3.1.9",
"version": "3.2.1",
"description": "Next generation of react-bootstrap-table",
"main": "./lib/index.js",
"repository": {

View File

@@ -1,3 +1,4 @@
/* eslint camelcase: 0 */
/* eslint arrow-body-style: 0 */
import React, { Component } from 'react';
@@ -5,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';
@@ -18,7 +20,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
this.validateProps();
}
componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.onDataSizeChange && !nextProps.pagination) {
if (nextProps.data.length !== this.props.data.length) {
nextProps.onDataSizeChange({ dataSize: nextProps.data.length });
@@ -64,7 +66,8 @@ class BootstrapTable extends PropsBaseResolver(Component) {
rowEvents,
selectRow,
expandRow,
cellEdit
cellEdit,
filterPosition
} = this.props;
const tableWrapperClass = cs('react-bootstrap-table', wrapperClasses);
@@ -76,6 +79,8 @@ 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>);
@@ -95,7 +100,19 @@ class BootstrapTable extends PropsBaseResolver(Component) {
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 }
/>
)}
<Body
data={ this.getData() }
keyField={ keyField }
@@ -134,7 +151,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,
@@ -198,6 +215,12 @@ 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,
@@ -239,7 +262,8 @@ BootstrapTable.defaultProps = {
cellEdit: {
mode: null,
nonEditableRows: []
}
},
filterPosition: Const.FILTERS_POSITION_INLINE
};
export default BootstrapTable;

View File

@@ -17,8 +17,8 @@ export default ExtendBase =>
createDefaultEventHandler(cb) {
return (e) => {
const { column, columnIndex } = this.props;
cb(e, column, columnIndex);
const { column, columnIndex, index } = this.props;
cb(e, column, typeof columnIndex !== 'undefined' ? columnIndex : index);
};
}

View File

@@ -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'
};

View File

@@ -1,3 +1,4 @@
/* eslint camelcase: 0 */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
@@ -12,10 +13,6 @@ export default () => {
state = { data: this.props.data };
componentWillReceiveProps(nextProps) {
this.setState(() => ({ data: nextProps.data }));
}
getData = (filterProps, searchProps, sortProps, paginationProps) => {
if (paginationProps) return paginationProps.data;
else if (sortProps) return sortProps.data;
@@ -24,6 +21,10 @@ export default () => {
return this.props.data;
}
UNSAFE_componentWillReceiveProps(nextProps) {
this.setState(() => ({ data: nextProps.data }));
}
render() {
return (
<DataContext.Provider

View File

@@ -1,3 +1,4 @@
/* eslint camelcase: 0 */
/* eslint no-return-assign: 0 */
/* eslint no-param-reassign: 0 */
/* eslint class-methods-use-this: 0 */
@@ -83,7 +84,7 @@ const withContext = Base =>
}
}
componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
if (!nextProps.pagination && this.props.pagination) {
this.PaginationContext = null;
}

View File

@@ -1,3 +1,4 @@
/* eslint camelcase: 0 */
/* eslint react/prop-types: 0 */
import React from 'react';
import PropTypes from 'prop-types';
@@ -16,7 +17,11 @@ class RowExpandProvider extends React.Component {
state = { expanded: this.props.expandRow.expanded || [],
isClosing: this.props.expandRow.isClosing || [] };
componentWillReceiveProps(nextProps) {
onClosed = (closedRow) => {
this.setState({ isClosing: this.state.isClosing.filter(value => value !== closedRow) });
};
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.expandRow) {
const nextExpanded = nextProps.expandRow.expanded || this.state.expanded;
const isClosing = this.state.expanded.reduce((acc, cur) => {
@@ -36,10 +41,6 @@ class RowExpandProvider extends React.Component {
}
}
onClosed = (closedRow) => {
this.setState({ isClosing: this.state.isClosing.filter(value => value !== closedRow) });
};
handleRowExpand = (rowKey, expanded, rowIndex, e) => {
const { data, keyField, expandRow: { onExpand, onlyOneExpanding, nonExpandable } } = this.props;
if (nonExpandable && _.contains(nonExpandable, rowKey)) {

View File

@@ -1,7 +1,9 @@
/* eslint camelcase: 0 */
/* eslint react/prop-types: 0 */
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';
@@ -19,17 +21,17 @@ class SelectionProvider extends React.Component {
this.selected = props.selectRow.selected || [];
}
componentWillReceiveProps(nextProps) {
if (nextProps.selectRow) {
this.selected = nextProps.selectRow.selected || this.selected;
}
}
// exposed API
getSelected() {
return this.selected;
}
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.selectRow) {
this.selected = nextProps.selectRow.selected || this.selected;
}
}
handleRowSelect = (rowKey, checked, rowIndex, e) => {
const { data, keyField, selectRow: { mode, onSelect } } = this.props;
const { ROW_SELECT_SINGLE } = Const;
@@ -71,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;

View 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;

View File

@@ -0,0 +1,69 @@
/* eslint react/require-default-props: 0 */
import React from 'react';
import PropTypes from 'prop-types';
import FiltersCell from './filters-cell';
import Const from './const';
const Filters = (props) => {
const {
columns,
onFilter,
currFilters,
filterPosition,
onExternalFilter,
className
} = props;
const filterColumns = [];
let showFiltersRow = false;
columns.forEach((column, i) => {
filterColumns.push(<FiltersCell
index={ i }
column={ column }
currFilters={ currFilters }
onExternalFilter={ onExternalFilter }
onFilter={ onFilter }
/>);
if (column.filterRenderer || column.filter) {
if (!showFiltersRow) {
showFiltersRow = true;
}
}
});
return (
<tbody
className={ className }
style={ {
display:
filterPosition === Const.FILTERS_POSITION_TOP
? 'table-header-group'
: 'table-footer-group'
} }
>
<tr>{filterColumns}</tr>
</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
};
Filters.defaultProps = {
position: Const.FILTERS_POSITION_TOP
};
export default Filters;

View File

@@ -4,56 +4,61 @@ import cs from 'classnames';
import PropTypes from 'prop-types';
import _ from './utils';
import eventDelegater from './cell-event-delegater';
const FooterCell = (props) => {
const { index, column, columnData } = props;
class FooterCell extends eventDelegater(React.Component) {
render() {
const { index, column, columnData } = this.props;
const {
footer,
footerTitle,
footerAlign,
footerFormatter,
footerEvents,
footerClasses,
footerStyle,
footerAttrs
} = column;
const {
footer,
footerTitle,
footerAlign,
footerFormatter,
footerEvents,
footerClasses,
footerStyle,
footerAttrs
} = column;
const cellAttrs = {
...(_.isFunction(footerAttrs) ? footerAttrs(column, index) : footerAttrs),
...footerEvents
};
const delegateEvents = this.delegate(footerEvents);
const cellAttrs = {
...(_.isFunction(footerAttrs) ? footerAttrs(column, index) : footerAttrs),
...delegateEvents
};
let text = '';
if (_.isString(footer)) {
text = footer;
} else if (_.isFunction(footer)) {
text = footer(columnData, column, index);
let text = '';
if (_.isString(footer)) {
text = footer;
} else if (_.isFunction(footer)) {
text = footer(columnData, column, index);
}
let cellStyle = {};
const cellClasses = _.isFunction(footerClasses) ? footerClasses(column, index) : footerClasses;
if (footerStyle) {
cellStyle = _.isFunction(footerStyle) ? footerStyle(column, index) : footerStyle;
cellStyle = cellStyle ? { ...cellStyle } : cellStyle;
}
if (footerTitle) {
cellAttrs.title = _.isFunction(footerTitle) ? footerTitle(column, index) : text;
}
if (footerAlign) {
cellStyle.textAlign = _.isFunction(footerAlign) ? footerAlign(column, index) : footerAlign;
}
if (cellClasses) cellAttrs.className = cs(cellAttrs.className, cellClasses);
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
const children = footerFormatter ? footerFormatter(column, index) : text;
return React.createElement('th', cellAttrs, children);
}
let cellStyle = {};
const cellClasses = _.isFunction(footerClasses) ? footerClasses(column, index) : footerClasses;
if (footerStyle) {
cellStyle = _.isFunction(footerStyle) ? footerStyle(column, index) : footerStyle;
cellStyle = cellStyle ? { ...cellStyle } : cellStyle;
}
if (footerTitle) {
cellAttrs.title = _.isFunction(footerTitle) ? footerTitle(column, index) : text;
}
if (footerAlign) {
cellStyle.textAlign = _.isFunction(footerAlign) ? footerAlign(column, index) : footerAlign;
}
if (cellClasses) cellAttrs.className = cs(cellAttrs.className, cellClasses);
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
const children = footerFormatter ? footerFormatter(column, index) : text;
return React.createElement('th', cellAttrs, children);
};
}
FooterCell.propTypes = {
columnData: PropTypes.array,

View File

@@ -7,119 +7,131 @@ import Const from './const';
import SortSymbol from './sort/symbol';
import SortCaret from './sort/caret';
import _ from './utils';
import eventDelegater from './cell-event-delegater';
const HeaderCell = (props) => {
const {
column,
index,
onSort,
sorting,
sortOrder,
isLastSorting,
onFilter,
currFilters,
onExternalFilter
} = props;
class HeaderCell extends eventDelegater(React.Component) {
render() {
const {
column,
index,
onSort,
sorting,
sortOrder,
isLastSorting,
onFilter,
currFilters,
filterPosition,
onExternalFilter
} = this.props;
const {
text,
sort,
sortCaret,
filter,
filterRenderer,
headerTitle,
headerAlign,
headerFormatter,
headerEvents,
headerClasses,
headerStyle,
headerAttrs,
headerSortingClasses,
headerSortingStyle
} = column;
const {
text,
sort,
sortCaret,
filter,
filterRenderer,
headerTitle,
headerAlign,
headerFormatter,
headerEvents,
headerClasses,
headerStyle,
headerAttrs,
headerSortingClasses,
headerSortingStyle
} = column;
const cellAttrs = {
..._.isFunction(headerAttrs) ? headerAttrs(column, index) : headerAttrs,
...headerEvents,
tabIndex: 0
};
const delegateEvents = this.delegate(headerEvents);
let sortSymbol;
let filterElm;
let cellStyle = {};
let cellClasses = _.isFunction(headerClasses) ? headerClasses(column, index) : headerClasses;
const customAttrs = _.isFunction(headerAttrs)
? headerAttrs(column, index)
: (headerAttrs || {});
if (headerStyle) {
cellStyle = _.isFunction(headerStyle) ? headerStyle(column, index) : headerStyle;
cellStyle = cellStyle ? { ...cellStyle } : cellStyle;
}
if (headerTitle) {
cellAttrs.title = _.isFunction(headerTitle) ? headerTitle(column, index) : text;
}
if (headerAlign) {
cellStyle.textAlign = _.isFunction(headerAlign) ? headerAlign(column, index) : headerAlign;
}
if (sort) {
const customClick = cellAttrs.onClick;
cellAttrs.onClick = (e) => {
onSort(column);
if (_.isFunction(customClick)) customClick(e);
const cellAttrs = {
...customAttrs,
...delegateEvents,
tabIndex: _.isDefined(customAttrs.tabIndex) ? customAttrs.tabIndex : 0
};
cellAttrs.className = cs(cellAttrs.className, 'sortable');
if (sorting) {
sortSymbol = sortCaret ? sortCaret(sortOrder, column) : <SortCaret order={ sortOrder } />;
let sortSymbol;
let filterElm;
let cellStyle = {};
let cellClasses = _.isFunction(headerClasses) ? headerClasses(column, index) : headerClasses;
// append customized classes or style if table was sorting based on the current column.
cellClasses = cs(
cellClasses,
_.isFunction(headerSortingClasses)
? headerSortingClasses(column, sortOrder, isLastSorting, index)
: headerSortingClasses
);
cellStyle = {
...cellStyle,
..._.isFunction(headerSortingStyle)
? headerSortingStyle(column, sortOrder, isLastSorting, index)
: headerSortingStyle
};
} else {
sortSymbol = sortCaret ? sortCaret(undefined, column) : <SortSymbol />;
if (headerStyle) {
cellStyle = _.isFunction(headerStyle) ? headerStyle(column, index) : headerStyle;
cellStyle = cellStyle ? { ...cellStyle } : cellStyle;
}
if (headerTitle) {
cellAttrs.title = _.isFunction(headerTitle) ? headerTitle(column, index) : text;
}
if (headerAlign) {
cellStyle.textAlign = _.isFunction(headerAlign) ? headerAlign(column, index) : headerAlign;
}
if (sort) {
const customClick = cellAttrs.onClick;
cellAttrs.onClick = (e) => {
onSort(column);
if (_.isFunction(customClick)) customClick(e);
};
cellAttrs.className = cs(cellAttrs.className, 'sortable');
if (sorting) {
sortSymbol = sortCaret ? sortCaret(sortOrder, column) : <SortCaret order={ sortOrder } />;
// append customized classes or style if table was sorting based on the current column.
cellClasses = cs(
cellClasses,
_.isFunction(headerSortingClasses)
? headerSortingClasses(column, sortOrder, isLastSorting, index)
: headerSortingClasses
);
cellStyle = {
...cellStyle,
..._.isFunction(headerSortingStyle)
? headerSortingStyle(column, sortOrder, isLastSorting, index)
: headerSortingStyle
};
} else {
sortSymbol = sortCaret ? sortCaret(undefined, column) : <SortSymbol />;
}
}
if (cellClasses) cellAttrs.className = cs(cellAttrs.className, cellClasses);
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
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 ?
headerFormatter(column, index, { sortElement: sortSymbol, filterElement: filterElm }) :
text;
if (headerFormatter) {
return React.createElement('th', cellAttrs, children);
}
return React.createElement('th', cellAttrs, children, sortSymbol, filterElm);
}
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 }
/>
);
}
const children = headerFormatter ?
headerFormatter(column, index, { sortElement: sortSymbol, filterElement: filterElm }) :
text;
if (headerFormatter) {
return React.createElement('th', cellAttrs, children);
}
return React.createElement('th', cellAttrs, children, sortSymbol, filterElm);
};
}
HeaderCell.propTypes = {
column: PropTypes.shape({
@@ -171,6 +183,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
};

View File

@@ -18,9 +18,10 @@ const Header = (props) => {
sortField,
sortOrder,
selectRow,
expandRow,
currFilters,
onExternalFilter,
expandRow
filterPosition
} = props;
let SelectionHeaderCellComp = () => null;
@@ -50,11 +51,12 @@ const Header = (props) => {
column={ column }
onSort={ onSort }
sorting={ currSort }
sortOrder={ sortOrder }
isLastSorting={ isLastSorting }
onFilter={ onFilter }
currFilters={ currFilters }
onExternalFilter={ onExternalFilter }
sortOrder={ sortOrder }
isLastSorting={ isLastSorting }
filterPosition={ filterPosition }
/>);
})
];
@@ -94,7 +96,12 @@ Header.propTypes = {
currFilters: PropTypes.object,
onExternalFilter: 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;

View File

@@ -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);

View File

@@ -14,14 +14,19 @@ function comparator(a, b) {
return result;
}
export const sort = (data, sortOrder, { dataField, sortFunc }) => {
export const sort = (data, sortOrder, { dataField, sortFunc, sortValue }) => {
const _data = [...data];
_data.sort((a, b) => {
let result;
let valueA = _.get(a, dataField);
let valueB = _.get(b, dataField);
valueA = _.isDefined(valueA) ? valueA : '';
valueB = _.isDefined(valueB) ? valueB : '';
if (sortValue) {
valueA = sortValue(valueA, a);
valueB = sortValue(valueB, b);
} else {
valueA = _.isDefined(valueA) ? valueA : '';
valueB = _.isDefined(valueB) ? valueB : '';
}
if (sortFunc) {
result = sortFunc(valueA, valueB, sortOrder, dataField, a, b);

View File

@@ -81,7 +81,7 @@ describe('DataContext', () => {
beforeEach(() => {
wrapper = shallow(shallowContext());
wrapper.instance().componentWillReceiveProps({
wrapper.instance().UNSAFE_componentWillReceiveProps({
data: newData
});
});

View File

@@ -99,7 +99,7 @@ describe('DataContext', () => {
beforeEach(() => {
wrapper = shallow(shallowContext());
wrapper.instance().componentWillReceiveProps({
wrapper.instance().UNSAFE_componentWillReceiveProps({
selectRow: newSelectRow
});
});
@@ -115,7 +115,7 @@ describe('DataContext', () => {
...defaultSelectRow,
selected: defaultSelected
}));
wrapper.instance().componentWillReceiveProps({
wrapper.instance().UNSAFE_componentWillReceiveProps({
selectRow: defaultSelectRow
});
});
@@ -128,7 +128,7 @@ describe('DataContext', () => {
describe('if nextProps.selectRow is not existing', () => {
beforeEach(() => {
wrapper = shallow(shallowContext());
wrapper.instance().componentWillReceiveProps({});
wrapper.instance().UNSAFE_componentWillReceiveProps({});
});
it('should not set this.selected', () => {

View File

@@ -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', () => {

View File

@@ -54,10 +54,15 @@ acorn@^4.0.3, acorn@^4.0.4:
version "4.0.13"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787"
acorn@^5.0.0, acorn@^5.2.1:
acorn@^5.0.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822"
acorn@^5.5.0:
version "5.7.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279"
integrity sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==
add-stream@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/add-stream/-/add-stream-1.0.0.tgz#6a7990437ca736d5e1288db92bd3266d5f5cb2aa"
@@ -73,7 +78,7 @@ ajv@^4.9.1:
co "^4.6.0"
json-stable-stringify "^1.0.1"
ajv@^5.1.0, ajv@^5.1.5, ajv@^5.2.0, ajv@^5.2.3:
ajv@^5.1.0, ajv@^5.1.5, ajv@^5.2.3, ajv@^5.3.0:
version "5.5.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.5.2.tgz#73b5eeca3fab653e3d3f9422b341ad42205dc965"
dependencies:
@@ -1686,9 +1691,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"
@@ -2532,9 +2538,10 @@ doctrine@1.5.0:
esutils "^2.0.2"
isarray "^1.0.0"
doctrine@^2.0.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.0.2.tgz#68f96ce8efc56cc42651f1faadb4f175273b0075"
doctrine@^2.0.0, doctrine@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d"
integrity sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==
dependencies:
esutils "^2.0.2"
@@ -2951,32 +2958,38 @@ eslint-scope@^3.7.1:
esrecurse "^4.1.0"
estraverse "^4.1.1"
eslint@4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.5.0.tgz#bb75d3b8bde97fb5e13efcd539744677feb019c3"
eslint-visitor-keys@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2"
integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==
eslint@4.18.2:
version "4.18.2"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.18.2.tgz#0f81267ad1012e7d2051e186a9004cc2267b8d45"
integrity sha512-qy4i3wODqKMYfz9LUI8N2qYDkHkoieTbiHpMrYUI/WbjhXJQr7lI4VngixTgaG+yHX+NBCv7nW4hA0ShbvaNKw==
dependencies:
ajv "^5.2.0"
ajv "^5.3.0"
babel-code-frame "^6.22.0"
chalk "^2.1.0"
concat-stream "^1.6.0"
cross-spawn "^5.1.0"
debug "^2.6.8"
doctrine "^2.0.0"
debug "^3.1.0"
doctrine "^2.1.0"
eslint-scope "^3.7.1"
espree "^3.5.0"
eslint-visitor-keys "^1.0.0"
espree "^3.5.2"
esquery "^1.0.0"
estraverse "^4.2.0"
esutils "^2.0.2"
file-entry-cache "^2.0.0"
functional-red-black-tree "^1.0.1"
glob "^7.1.2"
globals "^9.17.0"
globals "^11.0.1"
ignore "^3.3.3"
imurmurhash "^0.1.4"
inquirer "^3.0.6"
is-resolvable "^1.0.0"
js-yaml "^3.9.1"
json-stable-stringify "^1.0.1"
json-stable-stringify-without-jsonify "^1.0.1"
levn "^0.3.0"
lodash "^4.17.4"
minimatch "^3.0.2"
@@ -2984,20 +2997,21 @@ eslint@4.5.0:
natural-compare "^1.4.0"
optionator "^0.8.2"
path-is-inside "^1.0.2"
pluralize "^4.0.0"
pluralize "^7.0.0"
progress "^2.0.0"
require-uncached "^1.0.3"
semver "^5.3.0"
strip-ansi "^4.0.0"
strip-json-comments "~2.0.1"
table "^4.0.1"
table "4.0.2"
text-table "~0.2.0"
espree@^3.5.0:
version "3.5.2"
resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.2.tgz#756ada8b979e9dcfcdb30aad8d1a9304a905e1ca"
espree@^3.5.2:
version "3.5.4"
resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.4.tgz#b0f447187c8a8bed944b815a660bddf5deb5d1a7"
integrity sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==
dependencies:
acorn "^5.2.1"
acorn "^5.5.0"
acorn-jsx "^3.0.0"
esprima@^2.6.0:
@@ -3710,7 +3724,12 @@ global-prefix@^1.0.1:
is-windows "^1.0.1"
which "^1.2.14"
globals@^9.17.0, globals@^9.18.0:
globals@^11.0.1:
version "11.12.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==
globals@^9.18.0:
version "9.18.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a"
@@ -5024,6 +5043,11 @@ json-schema@0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13"
json-stable-stringify-without-jsonify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
integrity sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=
json-stable-stringify@^1.0.0, json-stable-stringify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af"
@@ -6459,9 +6483,10 @@ plugin-error@0.1.2, plugin-error@^0.1.2:
arr-union "^2.0.1"
extend-shallow "^1.1.2"
pluralize@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-4.0.0.tgz#59b708c1c0190a2f692f1c7618c446b052fd1762"
pluralize@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"
integrity sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==
pn@^1.0.0:
version "1.1.0"
@@ -7511,11 +7536,7 @@ semver-greatest-satisfied-range@^1.0.0:
dependencies:
sver-compat "^1.5.0"
"semver@2 || 3 || 4 || 5", semver@^5.0.1, semver@^5.1.0, semver@^5.3.0:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
semver@^5.4.1:
"semver@2 || 3 || 4 || 5", semver@^5.0.1, semver@^5.1.0, semver@^5.3.0, semver@^5.4.1:
version "5.5.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"
@@ -8042,9 +8063,10 @@ symbol-tree@^3.2.1:
version "3.2.2"
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"
table@^4.0.1:
table@4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/table/-/table-4.0.2.tgz#a33447375391e766ad34d3486e6e2aedc84d2e36"
integrity sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==
dependencies:
ajv "^5.2.3"
ajv-keywords "^2.1.0"