Compare commits

..

19 Commits

Author SHA1 Message Date
AllenFang
956f1cef4d Publish
- react-bootstrap-table2-example@1.0.20
 - react-bootstrap-table2-filter@1.1.6
 - react-bootstrap-table2-paginator@2.0.4
 - react-bootstrap-table2-toolkit@1.3.2
 - react-bootstrap-table-next@3.0.1
2019-03-10 13:38:21 +08:00
Allen
c45deee590 Merge pull request #846 from react-bootstrap-table/develop
20190310 release
2019-03-10 13:37:02 +08:00
AllenFang
2aab4301dd fix #835 2019-03-09 23:01:21 +08:00
AllenFang
43aa280761 Merge branch 'develop' of https://github.com/react-bootstrap-table/react-bootstrap-table2 into develop 2019-03-09 23:00:59 +08:00
AllenFang
3af30a0265 fix #840 2019-03-09 22:35:49 +08:00
AllenFang
4b8b8b261e update story 2019-03-09 22:31:24 +08:00
Norbert Nemeth
e44782f222 fix #863 - expanded row column span does not update (#837) 2019-03-09 18:46:04 +08:00
AllenFang
921e8c7ecc fix #830 2019-03-09 18:18:20 +08:00
AllenFang
a3b3ce0dc4 Merge branch 'develop' of https://github.com/react-bootstrap-table/react-bootstrap-table2 into develop 2019-03-09 15:52:37 +08:00
AllenFang
e9f08d278d fix #826 2019-03-09 15:52:10 +08:00
Sartaj Singh Baveja
b4973c826c Minor update to docs (#841) 2019-03-06 22:28:41 +08:00
AllenFang
6cac7f6dc8 Publish
- react-bootstrap-table2-example@1.0.19
 - react-bootstrap-table2-filter@1.1.5
 - react-bootstrap-table2-toolkit@1.3.1
 - react-bootstrap-table-next@3.0.0
2019-02-24 17:01:52 +08:00
Allen
da5b93c3cf Merge pull request #818 from react-bootstrap-table/develop
20190224 release
2019-02-24 16:59:43 +08:00
AllenFang
3ffccce1fe fix #817 2019-02-24 16:20:44 +08:00
AllenFang
09f21e8130 allow to custom className on clear search and export csv button 2019-02-24 16:11:38 +08:00
AllenFang
bf0c5c43a2 fix #735 2019-02-24 15:50:13 +08:00
AllenFang
c01f45a719 fix #789 2019-02-24 14:56:27 +08:00
AllenFang
d26c13b9be fix #815 2019-02-24 14:11:05 +08:00
AllenFang
8e940112f5 fix #811 2019-02-23 16:13:40 +08:00
32 changed files with 699 additions and 165 deletions

View File

@@ -69,7 +69,7 @@ const cellEdit: {
// omit... // omit...
beforeSaveCell(oldValue, newValue, row, column, done) { beforeSaveCell(oldValue, newValue, row, column, done) {
setTimeout(() => { setTimeout(() => {
if (confirm('Do you want to accep this change?')) { if (confirm('Do you want to accept this change?')) {
done(); // contine to save the changes done(); // contine to save the changes
} else { } else {
done(false); // reject the changes done(false); // reject the changes

View File

@@ -0,0 +1,90 @@
/* eslint react/prop-types: 0 */
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import ToolkitProvider, { Search, CSVExport } from 'react-bootstrap-table2-toolkit';
import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common';
const { SearchBar, ClearSearchButton } = Search;
const { ExportCSVButton } = CSVExport;
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, CSVExport } from 'react-bootstrap-table2-toolkit';
const { SearchBar, ClearSearchButton } = Search;
const { ExportCSVButton } = CSVExport;
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name'
}, {
dataField: 'price',
text: 'Product Price'
}];
<ToolkitProvider
keyField="id"
data={ products }
columns={ columns }
search
>
{
props => (
<div>
<h3>Input something at below input field:</h3>
<SearchBar { ...props.searchProps } />
<ClearSearchButton { ...props.searchProps } />
<hr />
<BootstrapTable
{ ...props.baseProps }
/>
<ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
</div>
)
}
</ToolkitProvider>
`;
export default () => (
<div>
<ToolkitProvider
keyField="id"
data={ products }
columns={ columns }
search
>
{
props => (
<div>
<h3>Input something at below input field:</h3>
<SearchBar { ...props.searchProps } />
<ClearSearchButton { ...props.searchProps } />
<hr />
<BootstrapTable
{ ...props.baseProps }
/>
<ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
</div>
)
}
</ToolkitProvider>
<Code>{ sourceCode }</Code>
</div>
);

View File

@@ -18,6 +18,11 @@ class QualityRanger extends React.Component {
static defaultProps = { static defaultProps = {
value: 0 value: 0
} }
componentDidMount() {
this.range.focus();
}
getValue() { getValue() {
return parseInt(this.range.value, 10); return parseInt(this.range.value, 10);
} }

View File

@@ -7,7 +7,7 @@ import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';
import Code from 'components/common/code-block'; import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common'; import { productsGenerator } from 'utils/common';
const products = productsGenerator(21); const products = productsGenerator(40);
const { SearchBar } = Search; const { SearchBar } = Search;
const columns = [{ const columns = [{
@@ -24,6 +24,12 @@ import paginationFactory, { PaginationProvider, PaginationListStandalone } from
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
class Table extends React.Component { class Table extends React.Component {
state = { products }
loadData = () => {
this.setState({ products: productsGenerator(17) });
}
render() { render() {
const options = { const options = {
custom: true, custom: true,
@@ -38,70 +44,84 @@ class Table extends React.Component {
firstPageTitle: 'Next page', firstPageTitle: 'Next page',
lastPageTitle: 'Last page', lastPageTitle: 'Last page',
showTotal: true, showTotal: true,
totalSize: products.length totalSize: this.state.products.length
};
const contentTable = ({ paginationProps, paginationTableProps }) => (
<div>
<PaginationListStandalone { ...paginationProps } />
<div>
<div>
<BootstrapTable
striped
hover
keyField="id"
data={ products }
columns={ columns }
filter={ filterFactory() }
cellEdit={ cellEditFactory() }
{ ...paginationTableProps }
/>
</div>
</div>
<PaginationListStandalone { ...paginationProps } />
</div>
);
return (
<div>
<h2>PaginationProvider will care the data size change. You dont do anything</h2>
<PaginationProvider
pagination={
paginationFactory(options)
}
>
{ contentTable }
</PaginationProvider>
<Code>{ sourceCode }</Code>
</div >
);
}
}
`;
export default class Table extends React.Component {
render() {
const options = {
custom: true,
paginationSize: 4,
pageStartIndex: 1,
firstPageText: 'First',
prePageText: 'Back',
nextPageText: 'Next',
lastPageText: 'Last',
nextPageTitle: 'First page',
prePageTitle: 'Pre page',
firstPageTitle: 'Next page',
lastPageTitle: 'Last page',
showTotal: true,
totalSize: products.length
}; };
const contentTable = ({ paginationProps, paginationTableProps }) => ( const contentTable = ({ paginationProps, paginationTableProps }) => (
<div> <div>
<button className="btn btn-default" onClick={ this.loadData }>Load Another Data</button>
<PaginationListStandalone { ...paginationProps } /> <PaginationListStandalone { ...paginationProps } />
<ToolkitProvider <ToolkitProvider
keyField="id" keyField="id"
columns={ columns } columns={ columns }
data={ products } data={ this.state.products }
search
>
{
toolkitprops => (
<div>
<SearchBar { ...toolkitprops.searchProps } />
<BootstrapTable
striped
hover
{ ...toolkitprops.baseProps }
{ ...paginationTableProps }
/>
</div>
)
}
</ToolkitProvider>
<PaginationListStandalone { ...paginationProps } />
</div>
);
return (
<div>
<h2>PaginationProvider will care the data size change. You dont do anything</h2>
<PaginationProvider
pagination={
paginationFactory(options)
}
>
{ contentTable }
</PaginationProvider>
<Code>{ sourceCode }</Code>
</div >
);
}
}
`;
export default class Table extends React.Component {
state = { products }
loadData = () => {
this.setState({ products: productsGenerator(17) });
}
render() {
const options = {
custom: true,
paginationSize: 4,
pageStartIndex: 1,
firstPageText: 'First',
prePageText: 'Back',
nextPageText: 'Next',
lastPageText: 'Last',
nextPageTitle: 'First page',
prePageTitle: 'Pre page',
firstPageTitle: 'Next page',
lastPageTitle: 'Last page',
showTotal: true,
totalSize: this.state.products.length
};
const contentTable = ({ paginationProps, paginationTableProps }) => (
<div>
<button className="btn btn-default" onClick={ this.loadData }>Load Another Data</button>
<PaginationListStandalone { ...paginationProps } />
<ToolkitProvider
keyField="id"
columns={ columns }
data={ this.state.products }
search search
> >
{ {

View File

@@ -3,28 +3,70 @@ import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next'; import BootstrapTable from 'react-bootstrap-table-next';
import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator'; import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; import filterFactory, { textFilter, selectFilter } from 'react-bootstrap-table2-filter';
import Code from 'components/common/code-block'; import Code from 'components/common/code-block';
import { productsGenerator } from 'utils/common'; import { productsQualityGenerator } from 'utils/common';
const products = productsGenerator(21); const products = productsQualityGenerator(21);
const selectOptions = {
0: 'good',
1: 'Bad',
2: 'unknown'
};
const columns = [{ const columns = [{
dataField: 'id', dataField: 'id',
text: 'Product ID', text: 'Product ID'
filter: textFilter({})
}, { }, {
dataField: 'name', dataField: 'name',
text: 'Product Name', text: 'Product Name',
filter: textFilter() filter: textFilter()
}, {
dataField: 'quality',
text: 'Product Quailty',
formatter: cell => selectOptions[cell],
filter: selectFilter({
options: selectOptions,
defaultValue: 0
})
}]; }];
const sourceCode = `\ const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next'; import BootstrapTable from 'react-bootstrap-table-next';
import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator'; import paginationFactory, { PaginationProvider, PaginationListStandalone } from 'react-bootstrap-table2-paginator';
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; import filterFactory, { textFilter, selectFilter } from 'react-bootstrap-table2-filter';
const selectOptions = {
0: 'good',
1: 'Bad',
2: 'unknown'
};
const columns = [{
dataField: 'id',
text: 'Product ID'
}, {
dataField: 'name',
text: 'Product Name',
filter: textFilter()
}, {
dataField: 'quality',
text: 'Product Quailty',
formatter: cell => selectOptions[cell],
filter: selectFilter({
options: selectOptions,
defaultValue: 0
})
}];
class Table extends React.Component { class Table extends React.Component {
state = { products }
loadData = () => {
this.setState({ products: productsQualityGenerator(40, 7) });
}
render() { render() {
const options = { const options = {
custom: true, custom: true,
@@ -39,10 +81,11 @@ class Table extends React.Component {
firstPageTitle: 'Next page', firstPageTitle: 'Next page',
lastPageTitle: 'Last page', lastPageTitle: 'Last page',
showTotal: true, showTotal: true,
totalSize: products.length totalSize: this.state.products.length
}; };
const contentTable = ({ paginationProps, paginationTableProps }) => ( const contentTable = ({ paginationProps, paginationTableProps }) => (
<div> <div>
<button className="btn btn-default" onClick={ this.loadData }>Load Another Data</button>
<PaginationListStandalone { ...paginationProps } /> <PaginationListStandalone { ...paginationProps } />
<div> <div>
<div> <div>
@@ -50,10 +93,9 @@ class Table extends React.Component {
striped striped
hover hover
keyField="id" keyField="id"
data={ products } data={ this.state.products }
columns={ columns } columns={ columns }
filter={ filterFactory() } filter={ filterFactory() }
cellEdit={ cellEditFactory() }
{ ...paginationTableProps } { ...paginationTableProps }
/> />
</div> </div>
@@ -72,7 +114,6 @@ class Table extends React.Component {
> >
{ contentTable } { contentTable }
</PaginationProvider> </PaginationProvider>
<Code>{ sourceCode }</Code>
</div > </div >
); );
} }
@@ -80,6 +121,12 @@ class Table extends React.Component {
`; `;
export default class Table extends React.Component { export default class Table extends React.Component {
state = { products }
loadData = () => {
this.setState({ products: productsQualityGenerator(40, 7) });
}
render() { render() {
const options = { const options = {
custom: true, custom: true,
@@ -94,10 +141,11 @@ export default class Table extends React.Component {
firstPageTitle: 'Next page', firstPageTitle: 'Next page',
lastPageTitle: 'Last page', lastPageTitle: 'Last page',
showTotal: true, showTotal: true,
totalSize: products.length totalSize: this.state.products.length
}; };
const contentTable = ({ paginationProps, paginationTableProps }) => ( const contentTable = ({ paginationProps, paginationTableProps }) => (
<div> <div>
<button className="btn btn-default" onClick={ this.loadData }>Load Another Data</button>
<PaginationListStandalone { ...paginationProps } /> <PaginationListStandalone { ...paginationProps } />
<div> <div>
<div> <div>
@@ -105,7 +153,7 @@ export default class Table extends React.Component {
striped striped
hover hover
keyField="id" keyField="id"
data={ products } data={ this.state.products }
columns={ columns } columns={ columns }
filter={ filterFactory() } filter={ filterFactory() }
{ ...paginationTableProps } { ...paginationTableProps }

View File

@@ -0,0 +1,150 @@
import React from 'react';
import BootstrapTable from 'react-bootstrap-table-next';
import paginationFactory from 'react-bootstrap-table2-paginator';
import Code from 'components/common/code-block';
const sourceCode = `\
import BootstrapTable from 'react-bootstrap-table-next';
import paginationFactory from 'react-bootstrap-table2-paginator';
class BookList extends React.Component {
state = {
books: [
{ id: '1', name: 'Book 1' },
{ id: '2', name: 'Book 2' },
{ id: '3', name: 'Book 3' },
{ id: '4', name: 'Book 4' },
{ id: '5', name: 'Book 5' },
{ id: '6', name: 'Book 6' }
]
};
deleteBookWithId = () => {
const lastOneId = this.state.books.length;
const updatedBooks = this.state.books.filter(m => m.id !== lastOneId.toString());
this.setState({ books: updatedBooks });
};
addBook = () => {
const lastOneId = this.state.books.length + 1;
this.setState({ books: [...this.state.books, {
id: \`$\{lastOneId}\`, name: \`Book $\{lastOneId}\`
}] });
}
render() {
const options = {
// pageStartIndex: 0,
sizePerPage: 5,
hideSizePerPage: true,
hidePageListOnlyOnePage: true
};
const columns = [
{
dataField: 'id',
text: 'Product ID',
Cell: row => (
<div>
<span title={ row.value }>{ row.value }</span>
</div>
)
},
{
dataField: 'name',
text: 'Product Name'
}
];
return (
<React.Fragment>
<BootstrapTable
keyField="id"
data={ this.state.books }
columns={ columns }
pagination={ paginationFactory(options) }
/>
<button className="btn btn-default" onClick={ () => this.deleteBookWithId() }>
delete last one book
</button>
<button className="btn btn-default" onClick={ () => this.addBook() }>
Add a book to the end
</button>
<Code>{ sourceCode }</Code>
</React.Fragment>
);
}
`;
export default class BookList extends React.Component {
state = {
books: [
{ id: '1', name: 'Book 1' },
{ id: '2', name: 'Book 2' },
{ id: '3', name: 'Book 3' },
{ id: '4', name: 'Book 4' },
{ id: '5', name: 'Book 5' },
{ id: '6', name: 'Book 6' },
{ id: '7', name: 'Book 6' },
{ id: '8', name: 'Book 6' },
{ id: '9', name: 'Book 6' },
{ id: '10', name: 'Book 6' },
{ id: '11', name: 'Book 6' }
]
};
deleteBookWithId = () => {
const lastOneId = this.state.books.length;
const updatedBooks = this.state.books.filter(m => m.id !== lastOneId.toString());
this.setState({ books: updatedBooks });
};
addBook = () => {
const lastOneId = this.state.books.length + 1;
this.setState({ books: [...this.state.books, {
id: `${lastOneId}`, name: `Book ${lastOneId}`
}] });
}
render() {
const options = {
// pageStartIndex: 0,
sizePerPage: 5,
hideSizePerPage: true,
hidePageListOnlyOnePage: true
};
const columns = [
{
dataField: 'id',
text: 'Product ID',
Cell: row => (
<div>
<span title={ row.value }>{ row.value }</span>
</div>
)
},
{
dataField: 'name',
text: 'Product Name'
}
];
return (
<React.Fragment>
<BootstrapTable
keyField="id"
data={ this.state.books }
columns={ columns }
pagination={ paginationFactory(options) }
/>
<button className="btn btn-default" onClick={ () => this.deleteBookWithId() }>
delete last one book
</button>
<button className="btn btn-default" onClick={ () => this.addBook() }>
Add a book to the end
</button>
<Code>{ sourceCode }</Code>
</React.Fragment>
);
}
}

View File

@@ -84,6 +84,7 @@ export default class StandaloneSizePerPage extends React.Component {
<div> <div>
<SizePerPageDropdownStandalone <SizePerPageDropdownStandalone
{ ...paginationProps } { ...paginationProps }
btnContextual="btn btn-primary"
/> />
<BootstrapTable <BootstrapTable
keyField="id" keyField="id"

View File

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

View File

@@ -29,10 +29,10 @@ export const withOnSale = rows => rows.map((row) => {
return row; return row;
}); });
export const productsQualityGenerator = (quantity = 5) => export const productsQualityGenerator = (quantity = 5, factor = 0) =>
Array.from({ length: quantity }, (value, index) => ({ Array.from({ length: quantity }, (value, index) => ({
id: index, id: index + factor,
name: `Item name ${index}`, name: `Item name ${index + factor}`,
quality: index % 3 quality: index % 3
})); }));

View File

@@ -21,6 +21,7 @@ import Bootstrap4DefaultSortTable from 'examples/bootstrap4/sort';
import Bootstrap4RowSelectionTable from 'examples/bootstrap4/row-selection'; import Bootstrap4RowSelectionTable from 'examples/bootstrap4/row-selection';
import Bootstrap4PaginationTable from 'examples/bootstrap4/pagination'; import Bootstrap4PaginationTable from 'examples/bootstrap4/pagination';
import Bootstrap4ColumnToggleTable from 'examples/bootstrap4/column-toggle'; import Bootstrap4ColumnToggleTable from 'examples/bootstrap4/column-toggle';
import ToolkitsTable from 'examples/bootstrap4/toolkits';
// work on columns // work on columns
import NestedDataTable from 'examples/columns/nested-data-table'; import NestedDataTable from 'examples/columns/nested-data-table';
@@ -162,6 +163,7 @@ import ExpandHooks from 'examples/row-expand/expand-hooks';
// pagination // pagination
import PaginationTable from 'examples/pagination'; import PaginationTable from 'examples/pagination';
import PaginationHooksTable from 'examples/pagination/pagination-hooks'; import PaginationHooksTable from 'examples/pagination/pagination-hooks';
import PaginationWithDynamicData from 'examples/pagination/pagination-with-dynamic-data';
import CustomPaginationTable from 'examples/pagination/custom-pagination'; import CustomPaginationTable from 'examples/pagination/custom-pagination';
import CustomPageButtonTable from 'examples/pagination/custom-page-button'; import CustomPageButtonTable from 'examples/pagination/custom-page-button';
import CustomSizePerPageOptionTable from 'examples/pagination/custom-size-per-page-option'; import CustomSizePerPageOptionTable from 'examples/pagination/custom-size-per-page-option';
@@ -249,7 +251,8 @@ storiesOf('Bootstrap 4', module)
.add('Sort table with bootstrap 4', () => <Bootstrap4DefaultSortTable />) .add('Sort table with bootstrap 4', () => <Bootstrap4DefaultSortTable />)
.add('Row selection table with bootstrap 4', () => <Bootstrap4RowSelectionTable />) .add('Row selection table with bootstrap 4', () => <Bootstrap4RowSelectionTable />)
.add('Pagination table with bootstrap 4', () => <Bootstrap4PaginationTable />) .add('Pagination table with bootstrap 4', () => <Bootstrap4PaginationTable />)
.add('Column Toggle with bootstrap 4', () => <Bootstrap4ColumnToggleTable />); .add('Column Toggle with bootstrap 4', () => <Bootstrap4ColumnToggleTable />)
.add('toolkits Table bootstrap 4', () => <ToolkitsTable />);
storiesOf('Work on Columns', module) storiesOf('Work on Columns', module)
.addDecorator(bootstrapStyle()) .addDecorator(bootstrapStyle())
@@ -402,6 +405,7 @@ storiesOf('Pagination', module)
.addDecorator(bootstrapStyle()) .addDecorator(bootstrapStyle())
.add('Basic Pagination Table', () => <PaginationTable />) .add('Basic Pagination Table', () => <PaginationTable />)
.add('Pagination Hooks', () => <PaginationHooksTable />) .add('Pagination Hooks', () => <PaginationHooksTable />)
.add('Pagination with Dynamic Data', () => <PaginationWithDynamicData />)
.add('Custom Pagination', () => <CustomPaginationTable />) .add('Custom Pagination', () => <CustomPaginationTable />)
.add('Custom Page Button', () => <CustomPageButtonTable />) .add('Custom Page Button', () => <CustomPageButtonTable />)
.add('Custom Page List', () => <CustomPageListTable />) .add('Custom Page List', () => <CustomPageListTable />)

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-bootstrap-table2-filter", "name": "react-bootstrap-table2-filter",
"version": "1.1.4", "version": "1.1.6",
"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": {

View File

@@ -27,9 +27,8 @@ export default (
this.onFilter = this.onFilter.bind(this); this.onFilter = this.onFilter.bind(this);
this.doFilter = this.doFilter.bind(this); this.doFilter = this.doFilter.bind(this);
this.onExternalFilter = this.onExternalFilter.bind(this); this.onExternalFilter = this.onExternalFilter.bind(this);
this.state = { this.data = props.data;
data: props.data this.isEmitDataChange = false;
};
} }
componentDidMount() { componentDidMount() {
@@ -39,13 +38,10 @@ export default (
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
let nextData = nextProps.data; // let nextData = nextProps.data;
if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.props.data)) { if (!isRemoteFiltering() && !_.isEqual(nextProps.data, this.data)) {
nextData = this.doFilter(nextProps); this.doFilter(nextProps, undefined, this.isEmitDataChange);
} }
this.setState({
data: nextData
});
} }
onFilter(column, filterType, initialize = false) { onFilter(column, filterType, initialize = false) {
@@ -83,9 +79,7 @@ export default (
if (filter.props.onFilter) { if (filter.props.onFilter) {
result = filter.props.onFilter(filterVal); result = filter.props.onFilter(filterVal);
} }
this.doFilter(this.props, result);
result = this.doFilter(this.props, result);
this.setState({ data: result });
}; };
} }
@@ -95,21 +89,25 @@ export default (
}; };
} }
doFilter(props, customResult) { doFilter(props, customResult, ignoreEmitDataChange = false) {
let result = customResult; let result = customResult;
const { dataChangeListener, data, columns } = props; const { dataChangeListener, data, columns } = props;
result = result || filters(data, columns, _)(this.currFilters); result = result || filters(data, columns, _)(this.currFilters);
if (dataChangeListener) { this.data = result;
if (dataChangeListener && !ignoreEmitDataChange) {
this.isEmitDataChange = true;
dataChangeListener.emit('filterChanged', result.length); dataChangeListener.emit('filterChanged', result.length);
} else {
this.isEmitDataChange = false;
this.forceUpdate();
} }
return result;
} }
render() { render() {
return ( return (
<FilterContext.Provider value={ { <FilterContext.Provider value={ {
data: this.state.data, data: this.data,
onFilter: this.onFilter, onFilter: this.onFilter,
onExternalFilter: this.onExternalFilter onExternalFilter: this.onExternalFilter
} } } }

View File

@@ -283,9 +283,9 @@ describe('FilterContext', () => {
expect(onFilter).toHaveBeenCalledWith(filterVal); expect(onFilter).toHaveBeenCalledWith(filterVal);
}); });
it('should set state.data correctly', () => { it('should set data correctly', () => {
instance.onFilter(customColumns[1], FILTER_TYPE.TEXT)(filterVal); instance.onFilter(customColumns[1], FILTER_TYPE.TEXT)(filterVal);
expect(instance.state.data).toEqual(mockReturn); expect(instance.data).toEqual(mockReturn);
}); });
}); });

View File

@@ -190,6 +190,19 @@ import paginationFactory, {
That's it!! The benifit for using standalone is you can much easier to render the standalone component in any posistion. In the future, we will implement more featue like applying `style`, `className` etc on standalone components. That's it!! The benifit for using standalone is you can much easier to render the standalone component in any posistion. In the future, we will implement more featue like applying `style`, `className` etc on standalone components.
##### Customizable props for `PaginationListStandalone`
* N/A
##### Customizable props for `SizePerPageDropdownStandalone`
* `open`: `true` to make dropdown show.
* `hidden`: `true` to hide the size per page dropdown.
* `btnContextual`: Set the button contextual
* `variation`: Variation for dropdown, available value is `dropdown` and `dropup`.
* `className`: Custom the class on size per page dropdown
##### Customizable props for `SizePerPageDropdownStandalone`
* N/A
#### 4.2 Customization Everything #### 4.2 Customization Everything
If you choose to custom the pagination component by yourself, the `paginationProps` will be important for you. Becasue you have to know for example how to change page or what's the current page etc. Hence, following is all the props in `paginationProps` object: If you choose to custom the pagination component by yourself, the `paginationProps` will be important for you. Becasue you have to know for example how to change page or what's the current page etc. Hence, following is all the props in `paginationProps` object:

View File

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

View File

@@ -32,7 +32,12 @@ class PaginationDataProvider extends Provider {
// user should align the page when the page is not fit to the data size when remote enable // user should align the page when the page is not fit to the data size when remote enable
if (!this.isRemotePagination() && !custom) { if (!this.isRemotePagination() && !custom) {
const newPage = alignPage( const newPage = alignPage(
nextProps.data.length, this.currPage, currSizePerPage, pageStartIndex); nextProps.data.length,
this.props.data.length,
this.currPage,
currSizePerPage,
pageStartIndex
);
if (this.currPage !== newPage) { if (this.currPage !== newPage) {
if (onPageChange) { if (onPageChange) {

View File

@@ -1,3 +1,5 @@
import Const from './const';
const getNormalizedPage = ( const getNormalizedPage = (
page, page,
pageStartIndex pageStartIndex
@@ -19,12 +21,20 @@ const startIndex = (
export const alignPage = ( export const alignPage = (
dataSize, dataSize,
prevDataSize,
page, page,
sizePerPage, sizePerPage,
pageStartIndex pageStartIndex
) => { ) => {
if (page < pageStartIndex || page > (Math.floor(dataSize / sizePerPage) + pageStartIndex)) { if (prevDataSize < dataSize) return page;
return pageStartIndex; if (page < pageStartIndex) return pageStartIndex;
if (dataSize <= 0) return pageStartIndex;
if ((page >= (Math.floor(dataSize / sizePerPage) + pageStartIndex)) && pageStartIndex === 1) {
return Math.ceil(dataSize / sizePerPage);
}
if (page >= Math.floor(dataSize / sizePerPage) && pageStartIndex === 0) {
const newPage = Math.ceil(dataSize / sizePerPage);
return newPage - Math.abs((Const.PAGE_START_INDEX - pageStartIndex));
} }
return page; return page;
}; };

View File

@@ -48,6 +48,7 @@ const sizePerPageDropdownAdapter = WrappedComponent =>
} }
return ( return (
<WrappedComponent <WrappedComponent
{ ...this.props }
currSizePerPage={ `${currSizePerPage}` } currSizePerPage={ `${currSizePerPage}` }
options={ this.calculateSizePerPageStatus() } options={ this.calculateSizePerPageStatus() }
optionRenderer={ sizePerPageOptionRenderer } optionRenderer={ sizePerPageOptionRenderer }

View File

@@ -50,11 +50,17 @@ class StateProvider extends React.Component {
// user should align the page when the page is not fit to the data size when remote enable // user should align the page when the page is not fit to the data size when remote enable
if (this.isRemotePagination() || custom) { if (this.isRemotePagination() || custom) {
if (typeof nextProps.pagination.options.page !== 'undefined') {
this.currPage = nextProps.pagination.options.page; this.currPage = nextProps.pagination.options.page;
}
if (typeof nextProps.pagination.options.sizePerPage !== 'undefined') {
this.currSizePerPage = nextProps.pagination.options.sizePerPage; this.currSizePerPage = nextProps.pagination.options.sizePerPage;
}
if (typeof nextProps.pagination.options.totalSize !== 'undefined') {
this.dataSize = nextProps.pagination.options.totalSize; this.dataSize = nextProps.pagination.options.totalSize;
} }
} }
}
getPaginationProps = () => { getPaginationProps = () => {
const { pagination: { options }, bootstrap4 } = this.props; const { pagination: { options }, bootstrap4 } = this.props;
@@ -117,13 +123,14 @@ class StateProvider extends React.Component {
const { pagination: { options } } = this.props; const { pagination: { options } } = this.props;
const pageStartIndex = typeof options.pageStartIndex === 'undefined' ? const pageStartIndex = typeof options.pageStartIndex === 'undefined' ?
Const.PAGE_START_INDEX : options.pageStartIndex; Const.PAGE_START_INDEX : options.pageStartIndex;
this.dataSize = newDataSize;
this.currPage = alignPage( this.currPage = alignPage(
newDataSize, newDataSize,
this.dataSize,
this.currPage, this.currPage,
this.currSizePerPage, this.currSizePerPage,
pageStartIndex pageStartIndex
); );
this.dataSize = newDataSize;
this.forceUpdate(); this.forceUpdate();
} }

View File

@@ -43,18 +43,132 @@ describe('Page Functions', () => {
}); });
describe('alignPage', () => { describe('alignPage', () => {
const pageStartIndex = 1; let newDataSize;
const sizePerPage = 10; let prevDataSize;
const page = 3; let currPage;
describe('if the page does not fit the pages which calculated from the length of data', () => { let pageStartIndex;
it('should return pageStartIndex argument', () => { let sizePerPage;
expect(alignPage(15, page, sizePerPage, pageStartIndex)).toEqual(pageStartIndex);
describe('if prevDataSize < newDataSize', () => {
beforeEach(() => {
newDataSize = 10;
prevDataSize = 6;
currPage = 2;
pageStartIndex = 1;
sizePerPage = 5;
});
it('should return same page', () => {
expect(alignPage(
newDataSize,
prevDataSize,
currPage,
sizePerPage,
pageStartIndex
)).toEqual(currPage);
}); });
}); });
describe('if the length of store.data is large than the end page index', () => { describe('if currPage < newDataSize', () => {
it('should return current page', () => { beforeEach(() => {
expect(alignPage(30, page, sizePerPage, pageStartIndex)).toEqual(page); newDataSize = 10;
prevDataSize = 12;
currPage = 0;
pageStartIndex = 1;
sizePerPage = 5;
});
it('should return correct page', () => {
expect(alignPage(
newDataSize,
prevDataSize,
currPage,
sizePerPage,
pageStartIndex
)).toEqual(pageStartIndex);
});
});
describe('if partStartIndex is default 1', () => {
describe('and currPage is bigger than newest last page', () => {
beforeEach(() => {
newDataSize = 9;
prevDataSize = 12;
currPage = 3;
pageStartIndex = 1;
sizePerPage = 5;
});
it('should return correct page', () => {
expect(alignPage(
newDataSize,
prevDataSize,
currPage,
sizePerPage,
pageStartIndex
)).toEqual(2);
});
});
describe('and currPage is short than newest last page', () => {
beforeEach(() => {
newDataSize = 11;
prevDataSize = 12;
currPage = 3;
pageStartIndex = 1;
sizePerPage = 5;
});
it('should return correct page', () => {
expect(alignPage(
newDataSize,
prevDataSize,
currPage,
sizePerPage,
pageStartIndex
)).toEqual(currPage);
});
});
});
describe('if partStartIndex is default 0', () => {
describe('and currPage is bigger than newest last page', () => {
beforeEach(() => {
newDataSize = 8;
prevDataSize = 11;
currPage = 2;
pageStartIndex = 0;
sizePerPage = 5;
});
it('should return correct page', () => {
expect(alignPage(
newDataSize,
prevDataSize,
currPage,
sizePerPage,
pageStartIndex
)).toEqual(1);
});
});
describe('and currPage is short than newest last page', () => {
beforeEach(() => {
newDataSize = 11;
prevDataSize = 12;
currPage = 2;
pageStartIndex = 0;
sizePerPage = 5;
});
it('should return correct page', () => {
expect(alignPage(
newDataSize,
prevDataSize,
currPage,
sizePerPage,
pageStartIndex
)).toEqual(currPage);
});
}); });
}); });
}); });

View File

@@ -67,6 +67,19 @@ const { SearchBar } = Search;
3. You should render `SearchBar` with `searchProps` as well. The position of `SearchBar` is depends on you. 3. You should render `SearchBar` with `searchProps` as well. The position of `SearchBar` is depends on you.
### `SearchBar` Props
#### className - [string]
Custom the class on input element.
#### placeholder - [string]
Custom the placeholder on input element.
#### style - [object]
Custom the style on input element.
#### delay = [number]
milionsecond for debounce user input.
### Search Options ### Search Options
#### defaultSearch - [string] #### defaultSearch - [string]
@@ -127,6 +140,8 @@ const { SearchBar, ClearSearchButton } = Search;
</ToolkitProvider> </ToolkitProvider>
``` ```
-----
## Export CSV ## Export CSV
There are two steps to enable the export CSV functionality: There are two steps to enable the export CSV functionality:
@@ -176,6 +191,8 @@ Default is `true`. `false` will only export current data which display on table.
#### onlyExportSelection - [bool] #### onlyExportSelection - [bool]
Default is `false`. `true` will only export the data which is selected. Default is `false`. `true` will only export the data which is selected.
-----
## Column Toggle ## Column Toggle
Let's see how to render the column toggle in your react component: Let's see how to render the column toggle in your react component:

View File

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

View File

@@ -5,12 +5,14 @@ const ExportCSVButton = (props) => {
const { const {
onExport, onExport,
children, children,
className,
...rest ...rest
} = props; } = props;
return ( return (
<button <button
type="button" type="button"
className={ `react-bs-table-csv-btn btn btn-default ${className}` }
onClick={ () => onExport() } onClick={ () => onExport() }
{ ...rest } { ...rest }
> >
@@ -26,7 +28,7 @@ ExportCSVButton.propTypes = {
style: PropTypes.object style: PropTypes.object
}; };
ExportCSVButton.defaultProps = { ExportCSVButton.defaultProps = {
className: 'react-bs-table-csv-btn btn btn-default', className: '',
style: {} style: {}
}; };

View File

@@ -3,18 +3,21 @@ import PropTypes from 'prop-types';
const ClearButton = ({ const ClearButton = ({
onClear, onClear,
text text,
className
}) => ( }) => (
<button className="btn btn-default" onClick={ onClear }>{ text }</button> <button className={ `btn btn-default ${className}` } onClick={ onClear }>{ text }</button>
); );
ClearButton.propTypes = { ClearButton.propTypes = {
onClear: PropTypes.func.isRequired, onClear: PropTypes.func.isRequired,
className: PropTypes.string,
text: PropTypes.string text: PropTypes.string
}; };
ClearButton.defaultProps = { ClearButton.defaultProps = {
text: 'Clear' text: 'Clear',
className: ''
}; };
export default ClearButton; export default ClearButton;

View File

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

View File

@@ -17,7 +17,6 @@ class Body extends React.Component {
super(props); super(props);
const { const {
keyField, keyField,
visibleColumnSize,
cellEdit, cellEdit,
selectRow, selectRow,
expandRow expandRow
@@ -34,7 +33,7 @@ class Body extends React.Component {
const expandRowEnabled = !!expandRow.renderer; const expandRowEnabled = !!expandRow.renderer;
if (expandRowEnabled) { if (expandRowEnabled) {
RowComponent = withRowExpansion(RowAggregator, visibleColumnSize); RowComponent = withRowExpansion(RowAggregator);
} }
if (selectRowEnabled) { if (selectRowEnabled) {

View File

@@ -23,7 +23,10 @@ class Cell extends eventDelegater(Component) {
if (shouldUpdate) return true; if (shouldUpdate) return true;
// if (nextProps.formatter)
shouldUpdate = shouldUpdate =
nextProps.column.formatter ? !_.isEqual(this.props.row, nextProps.row) : false ||
this.props.column.hidden !== nextProps.column.hidden || this.props.column.hidden !== nextProps.column.hidden ||
this.props.rowIndex !== nextProps.rowIndex || this.props.rowIndex !== nextProps.rowIndex ||
this.props.columnIndex !== nextProps.columnIndex || this.props.columnIndex !== nextProps.columnIndex ||

View File

@@ -294,6 +294,7 @@ const withContext = Base =>
return rootProps => ( return rootProps => (
<this.CellEditContext.Provider <this.CellEditContext.Provider
{ ...baseProps } { ...baseProps }
ref={ n => this.cellEditContext = n }
selectRow={ this.props.selectRow } selectRow={ this.props.selectRow }
cellEdit={ this.props.cellEdit } cellEdit={ this.props.cellEdit }
data={ rootProps.getData() } data={ rootProps.getData() }

View File

@@ -14,26 +14,27 @@ class SelectionProvider extends React.Component {
keyField: PropTypes.string.isRequired keyField: PropTypes.string.isRequired
} }
state = { selected: this.props.selectRow.selected || [] }; constructor(props) {
super(props);
this.selected = props.selectRow.selected || [];
}
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (nextProps.selectRow) { if (nextProps.selectRow) {
this.setState(() => ({ this.selected = nextProps.selectRow.selected || this.selected;
selected: nextProps.selectRow.selected || this.state.selected
}));
} }
} }
// exposed API // exposed API
getSelected() { getSelected() {
return this.state.selected; return this.selected;
} }
handleRowSelect = (rowKey, checked, rowIndex, e) => { handleRowSelect = (rowKey, checked, rowIndex, e) => {
const { data, keyField, selectRow: { mode, onSelect } } = this.props; const { data, keyField, selectRow: { mode, onSelect } } = this.props;
const { ROW_SELECT_SINGLE } = Const; const { ROW_SELECT_SINGLE } = Const;
let currSelected = [...this.state.selected]; let currSelected = [...this.selected];
let result = true; let result = true;
if (onSelect) { if (onSelect) {
@@ -41,7 +42,6 @@ class SelectionProvider extends React.Component {
result = onSelect(row, checked, rowIndex, e); result = onSelect(row, checked, rowIndex, e);
} }
this.setState(() => {
if (result === true || result === undefined) { if (result === true || result === undefined) {
if (mode === ROW_SELECT_SINGLE) { // when select mode is radio if (mode === ROW_SELECT_SINGLE) { // when select mode is radio
currSelected = [rowKey]; currSelected = [rowKey];
@@ -51,8 +51,8 @@ class SelectionProvider extends React.Component {
currSelected = currSelected.filter(value => value !== rowKey); currSelected = currSelected.filter(value => value !== rowKey);
} }
} }
return { selected: currSelected }; this.selected = currSelected;
}); this.forceUpdate();
} }
handleAllRowsSelect = (e, isUnSelect) => { handleAllRowsSelect = (e, isUnSelect) => {
@@ -64,7 +64,7 @@ class SelectionProvider extends React.Component {
nonSelectable nonSelectable
} }
} = this.props; } = this.props;
const { selected } = this.state; const { selected } = this;
let currSelected; let currSelected;
@@ -81,7 +81,7 @@ class SelectionProvider extends React.Component {
dataOperator.getSelectedRows( dataOperator.getSelectedRows(
data, data,
keyField, keyField,
isUnSelect ? this.state.selected : currSelected isUnSelect ? selected : currSelected
), ),
e e
); );
@@ -89,7 +89,8 @@ class SelectionProvider extends React.Component {
currSelected = result; currSelected = result;
} }
} }
this.setState(() => ({ selected: currSelected })); this.selected = currSelected;
this.forceUpdate();
} }
render() { render() {
@@ -99,7 +100,7 @@ class SelectionProvider extends React.Component {
} = getSelectionSummary( } = getSelectionSummary(
this.props.data, this.props.data,
this.props.keyField, this.props.keyField,
this.state.selected this.selected
); );
let checkedStatus; let checkedStatus;
@@ -113,7 +114,7 @@ class SelectionProvider extends React.Component {
<SelectionContext.Provider <SelectionContext.Provider
value={ { value={ {
...this.props.selectRow, ...this.props.selectRow,
selected: this.state.selected, selected: this.selected,
onRowSelect: this.handleRowSelect, onRowSelect: this.handleRowSelect,
onAllRowsSelect: this.handleAllRowsSelect, onAllRowsSelect: this.handleAllRowsSelect,
allRowsSelected, allRowsSelected,

View File

@@ -3,7 +3,7 @@ import React from 'react';
import ExpandRow from './expand-row'; import ExpandRow from './expand-row';
import ExpansionContext from '../contexts/row-expand-context'; import ExpansionContext from '../contexts/row-expand-context';
export default (Component, visibleColumnSize) => { export default (Component) => {
const renderWithExpansion = (props, expandRow) => { const renderWithExpansion = (props, expandRow) => {
const key = props.value; const key = props.value;
@@ -20,7 +20,7 @@ export default (Component, visibleColumnSize) => {
/>, />,
expanded ? <ExpandRow expanded ? <ExpandRow
key={ `${key}-expanding` } key={ `${key}-expanding` }
colSpan={ visibleColumnSize } colSpan={ props.visibleColumnSize }
> >
{ expandRow.renderer(props.row) } { expandRow.renderer(props.row) }
</ExpandRow> : null </ExpandRow> : null

View File

@@ -218,6 +218,47 @@ describe('Cell', () => {
}); });
}); });
describe('when props.row is change', () => {
describe('and column.formatter is enable', () => {
const column = { dataField: 'name', text: 'Product Name', formatter: () => 123 };
beforeEach(() => {
props = {
row,
columnIndex: 1,
rowIndex: 1,
tabIndex: 5,
column
};
wrapper = shallow(
<Cell { ...props } />);
});
it('should return true', () => {
nextProps = { ...props, row: { ...row, alert: 'test' } };
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
});
});
describe('but column.formatter is disable', () => {
const column = { dataField: 'name', text: 'Product Name' };
beforeEach(() => {
props = {
row,
columnIndex: 1,
rowIndex: 1,
tabIndex: 5,
column
};
wrapper = shallow(
<Cell { ...props } />);
});
it('should return true', () => {
nextProps = { ...props, row: { ...row, alert: 'test' } };
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(false);
});
});
});
describe('if column.isDummyField is true', () => { describe('if column.isDummyField is true', () => {
describe('when content is change', () => { describe('when content is change', () => {
const column = { dataField: '', text: 'Product Name', isDummyField: true }; const column = { dataField: '', text: 'Product Name', isDummyField: true };

View File

@@ -73,15 +73,15 @@ describe('DataContext', () => {
expect(SelectionContext.Consumer).toBeDefined(); expect(SelectionContext.Consumer).toBeDefined();
}); });
it('should have correct state.data', () => { it('should have correct this.selected', () => {
expect(wrapper.state().selected).toEqual([]); expect(wrapper.instance().selected).toEqual([]);
}); });
it('should pass correct sort props to children element', () => { it('should pass correct sort props to children element', () => {
expect(wrapper.length).toBe(1); expect(wrapper.length).toBe(1);
expect(mockBase).toHaveBeenCalledWith({ expect(mockBase).toHaveBeenCalledWith({
...defaultSelectRow, ...defaultSelectRow,
selected: wrapper.state().selected, selected: wrapper.instance().selected,
onRowSelect: wrapper.instance().handleRowSelect, onRowSelect: wrapper.instance().handleRowSelect,
onAllRowsSelect: wrapper.instance().handleAllRowsSelect, onAllRowsSelect: wrapper.instance().handleAllRowsSelect,
allRowsNotSelected: true, allRowsNotSelected: true,
@@ -104,8 +104,8 @@ describe('DataContext', () => {
}); });
}); });
it('should have correct state.selected', () => { it('should have correct this.selected', () => {
expect(wrapper.state().selected).toEqual(newSelectRow.selected); expect(wrapper.instance().selected).toEqual(newSelectRow.selected);
}); });
describe('if nextProps.selectRow is not existing', () => { describe('if nextProps.selectRow is not existing', () => {
@@ -120,8 +120,8 @@ describe('DataContext', () => {
}); });
}); });
it('should keep origin state.selected', () => { it('should keep origin this.selected', () => {
expect(wrapper.state().selected).toEqual(defaultSelected); expect(wrapper.instance().selected).toEqual(defaultSelected);
}); });
}); });
@@ -131,8 +131,8 @@ describe('DataContext', () => {
wrapper.instance().componentWillReceiveProps({}); wrapper.instance().componentWillReceiveProps({});
}); });
it('should not set state.selected', () => { it('should not set this.selected', () => {
expect(wrapper.state().selected).toEqual([]); expect(wrapper.instance().selected).toEqual([]);
}); });
}); });
}); });
@@ -148,8 +148,8 @@ describe('DataContext', () => {
wrapper = shallow(shallowContext(selectRow)); wrapper = shallow(shallowContext(selectRow));
}); });
it('should have correct state.data', () => { it('should have correct this.selected', () => {
expect(wrapper.state().selected).toEqual(selectRow.selected); expect(wrapper.instance().selected).toEqual(selectRow.selected);
}); });
}); });
@@ -164,12 +164,12 @@ describe('DataContext', () => {
wrapper = shallow(shallowContext(selectRow)); wrapper = shallow(shallowContext(selectRow));
}); });
it('should set state.selected correctly', () => { it('should set this.selected correctly', () => {
wrapper.instance().handleRowSelect(firstSelectedRow, true, rowIndex); wrapper.instance().handleRowSelect(firstSelectedRow, true, rowIndex);
expect(wrapper.state('selected')).toEqual([firstSelectedRow]); expect(wrapper.instance().selected).toEqual([firstSelectedRow]);
wrapper.instance().handleRowSelect(secondSelectedRow, true, rowIndex); wrapper.instance().handleRowSelect(secondSelectedRow, true, rowIndex);
expect(wrapper.state('selected')).toEqual([secondSelectedRow]); expect(wrapper.instance().selected).toEqual([secondSelectedRow]);
}); });
}); });
@@ -178,18 +178,19 @@ describe('DataContext', () => {
wrapper = shallow(shallowContext()); wrapper = shallow(shallowContext());
}); });
it('should set state.selected correctly', () => { it('should set this.selected correctly', () => {
wrapper.instance().handleRowSelect(firstSelectedRow, true, rowIndex); wrapper.instance().handleRowSelect(firstSelectedRow, true, rowIndex);
expect(wrapper.state('selected')).toEqual(expect.arrayContaining([firstSelectedRow])); expect(wrapper.instance().selected).toEqual(expect.arrayContaining([firstSelectedRow]));
wrapper.instance().handleRowSelect(secondSelectedRow, true, rowIndex); wrapper.instance().handleRowSelect(secondSelectedRow, true, rowIndex);
expect(wrapper.state('selected')).toEqual(expect.arrayContaining([firstSelectedRow, secondSelectedRow])); expect(wrapper.instance().selected)
.toEqual(expect.arrayContaining([firstSelectedRow, secondSelectedRow]));
wrapper.instance().handleRowSelect(firstSelectedRow, false, rowIndex); wrapper.instance().handleRowSelect(firstSelectedRow, false, rowIndex);
expect(wrapper.state('selected')).toEqual(expect.arrayContaining([secondSelectedRow])); expect(wrapper.instance().selected).toEqual(expect.arrayContaining([secondSelectedRow]));
wrapper.instance().handleRowSelect(secondSelectedRow, false, rowIndex); wrapper.instance().handleRowSelect(secondSelectedRow, false, rowIndex);
expect(wrapper.state('selected')).toEqual([]); expect(wrapper.instance().selected).toEqual([]);
}); });
}); });
@@ -220,8 +221,8 @@ describe('DataContext', () => {
wrapper.instance().handleAllRowsSelect(e, false); wrapper.instance().handleAllRowsSelect(e, false);
}); });
it('should set state.selected correctly', () => { it('should set this.selected correctly', () => {
expect(wrapper.state('selected')).toEqual(data.map(d => d[keyField])); expect(wrapper.instance().selected).toEqual(data.map(d => d[keyField]));
}); });
describe('when selectRow.onSelectAll is defined', () => { describe('when selectRow.onSelectAll is defined', () => {
@@ -237,7 +238,7 @@ describe('DataContext', () => {
it('should call selectRow.onSelectAll correctly', () => { it('should call selectRow.onSelectAll correctly', () => {
expect(onSelectAll).toHaveBeenCalledWith( expect(onSelectAll).toHaveBeenCalledWith(
true, true,
dataOperator.getSelectedRows(data, keyField, wrapper.state('selected')), dataOperator.getSelectedRows(data, keyField, wrapper.instance().selected),
e e
); );
}); });
@@ -253,8 +254,8 @@ describe('DataContext', () => {
wrapper.instance().handleAllRowsSelect(e, true); wrapper.instance().handleAllRowsSelect(e, true);
}); });
it('should set state.selected correctly', () => { it('should set this.selected correctly', () => {
expect(wrapper.state('selected')).toEqual([]); expect(wrapper.instance().selected).toEqual([]);
}); });
describe('when selectRow.onSelectAll is defined', () => { describe('when selectRow.onSelectAll is defined', () => {