Skip to content

Commit c228b22

Browse files
authored
Merge pull request #595 from react-bootstrap-table/develop
20181007 release
2 parents ae0cd8a + 10adbf4 commit c228b22

File tree

10 files changed

+338
-5
lines changed

10 files changed

+338
-5
lines changed

docs/columns.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Available properties in a column object:
1313
* [formatExtraData](#formatExtraData)
1414
* [sort](#sort)
1515
* [sortFunc](#sortFunc)
16+
* [sortCaret](#sortCaret)
1617
* [onSort](#onSort)
1718
* [classes](#classes)
1819
* [style](#style)
@@ -154,6 +155,20 @@ Enable the column sort via a `true` value given.
154155
}
155156
```
156157

158+
## <a name='sortCaret'>column.sortCaret - [Function]</a>
159+
Use`column.sortCaret` to custom the sort caret. This callback function accept two arguments: `order` and `column`
160+
161+
```js
162+
{
163+
// omit...
164+
sort: true,
165+
sortCaret: (order, column) => {
166+
return //...
167+
}
168+
}
169+
```
170+
> The possible value of `order` argument is **`asc`**, **`desc`** and **`undefined`**.
171+
157172
## <a name='classes'>column.classes - [String | Function]</a>
158173
It's available to have custom class on table column:
159174

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/* eslint no-return-assign: 0 */
2+
/* eslint no-console: 0 */
3+
import React from 'react';
4+
5+
import BootstrapTable from 'react-bootstrap-table-next';
6+
import paginationFactory from 'react-bootstrap-table2-paginator';
7+
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
8+
import Code from 'components/common/code-block';
9+
import { productsGenerator } from 'utils/common';
10+
11+
const products = productsGenerator(63);
12+
13+
const columns = [{
14+
dataField: 'id',
15+
text: 'Product ID',
16+
sort: true
17+
}, {
18+
dataField: 'name',
19+
text: 'Product Name',
20+
sort: true,
21+
filter: textFilter()
22+
}, {
23+
dataField: 'price',
24+
text: 'Product Price',
25+
sort: true,
26+
filter: textFilter()
27+
}];
28+
29+
const sourceCode = `\
30+
import BootstrapTable from 'react-bootstrap-table-next';
31+
32+
const columns = [{
33+
dataField: 'id',
34+
text: 'Product ID'
35+
}, {
36+
dataField: 'name',
37+
text: 'Product Name'
38+
}, {
39+
dataField: 'price',
40+
text: 'Product Price'
41+
}];
42+
43+
class ExposedFunctionTable extends React.Component {
44+
handleGetCurrentData = () => {
45+
console.log(this.node.table.props.data);
46+
}
47+
48+
handleGetSelectedData = () => {
49+
console.log(this.node.selectionContext.state.selected);
50+
}
51+
52+
handleGetExpandedData = () => {
53+
console.log(this.node.rowExpandContext.state.expanded);
54+
}
55+
56+
handleGetCurrentPage = () => {
57+
console.log(this.node.paginationContext.currPage);
58+
}
59+
60+
handleGetCurrentSizePerPage = () => {
61+
console.log(this.node.paginationContext.currSizePerPage);
62+
}
63+
64+
handleGetCurrentSortColumn = () => {
65+
console.log(this.node.sortContext.state.sortColumn);
66+
}
67+
68+
handleGetCurrentSortOrder = () => {
69+
console.log(this.node.sortContext.state.sortOrder);
70+
}
71+
72+
handleGetCurrentFilter = () => {
73+
console.log(this.node.filterContext.currFilters);
74+
}
75+
76+
render() {
77+
const expandRow = {
78+
renderer: row => (
79+
<div>
80+
<p>.....</p>
81+
<p>You can render anything here, also you can add additional data on every row object</p>
82+
<p>expandRow.renderer callback will pass the origin row object to you</p>
83+
</div>
84+
),
85+
showExpandColumn: true
86+
};
87+
return (
88+
<div>
89+
<button className="btn btn-default" onClick={ this.handleGetCurrentData }>Get Current Display Rows</button>
90+
<button className="btn btn-default" onClick={ this.handleGetSelectedData }>Get Current Selected Rows</button>
91+
<button className="btn btn-default" onClick={ this.handleGetExpandedData }>Get Current Expanded Rows</button>
92+
<button className="btn btn-default" onClick={ this.handleGetCurrentPage }>Get Current Page</button>
93+
<button className="btn btn-default" onClick={ this.handleGetCurrentSizePerPage }>Get Current Size Per Page</button>
94+
<button className="btn btn-default" onClick={ this.handleGetCurrentSortColumn }>Get Current Sort Column</button>
95+
<button className="btn btn-default" onClick={ this.handleGetCurrentSortOrder }>Get Current Sort Order</button>
96+
<button className="btn btn-default" onClick={ this.handleGetCurrentFilter }>Get Current Filter Information</button>
97+
<BootstrapTable
98+
ref={ n => this.node = n }
99+
keyField="id"
100+
data={ products }
101+
columns={ columns }
102+
filter={ filterFactory() }
103+
pagination={ paginationFactory() }
104+
selectRow={ { mode: 'checkbox', clickToSelect: true } }
105+
expandRow={ expandRow }
106+
/>
107+
<Code>{ sourceCode }</Code>
108+
</div>
109+
);
110+
}
111+
}
112+
`;
113+
114+
export default class ExposedFunctionTable extends React.Component {
115+
handleGetCurrentData = () => {
116+
console.log(this.node.table.props.data);
117+
}
118+
119+
handleGetSelectedData = () => {
120+
console.log(this.node.selectionContext.state.selected);
121+
}
122+
123+
handleGetExpandedData = () => {
124+
console.log(this.node.rowExpandContext.state.expanded);
125+
}
126+
127+
handleGetCurrentPage = () => {
128+
console.log(this.node.paginationContext.currPage);
129+
}
130+
131+
handleGetCurrentSizePerPage = () => {
132+
console.log(this.node.paginationContext.currSizePerPage);
133+
}
134+
135+
handleGetCurrentSortColumn = () => {
136+
console.log(this.node.sortContext.state.sortColumn);
137+
}
138+
139+
handleGetCurrentSortOrder = () => {
140+
console.log(this.node.sortContext.state.sortOrder);
141+
}
142+
143+
handleGetCurrentFilter = () => {
144+
console.log(this.node.filterContext.currFilters);
145+
}
146+
147+
render() {
148+
const expandRow = {
149+
renderer: row => (
150+
<div>
151+
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
152+
<p>You can render anything here, also you can add additional data on every row object</p>
153+
<p>expandRow.renderer callback will pass the origin row object to you</p>
154+
</div>
155+
),
156+
showExpandColumn: true
157+
};
158+
return (
159+
<div>
160+
<button className="btn btn-default" onClick={ this.handleGetCurrentData }>Get Current Display Rows</button>
161+
<button className="btn btn-default" onClick={ this.handleGetSelectedData }>Get Current Selected Rows</button>
162+
<button className="btn btn-default" onClick={ this.handleGetExpandedData }>Get Current Expanded Rows</button>
163+
<button className="btn btn-default" onClick={ this.handleGetCurrentPage }>Get Current Page</button>
164+
<button className="btn btn-default" onClick={ this.handleGetCurrentSizePerPage }>Get Current Size Per Page</button>
165+
<button className="btn btn-default" onClick={ this.handleGetCurrentSortColumn }>Get Current Sort Column</button>
166+
<button className="btn btn-default" onClick={ this.handleGetCurrentSortOrder }>Get Current Sort Order</button>
167+
<button className="btn btn-default" onClick={ this.handleGetCurrentFilter }>Get Current Filter Information</button>
168+
<BootstrapTable
169+
ref={ n => this.node = n }
170+
keyField="id"
171+
data={ products }
172+
columns={ columns }
173+
filter={ filterFactory() }
174+
pagination={ paginationFactory() }
175+
selectRow={ { mode: 'checkbox', clickToSelect: true } }
176+
expandRow={ expandRow }
177+
/>
178+
<Code>{ sourceCode }</Code>
179+
</div>
180+
);
181+
}
182+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* eslint no-unused-vars: 0 */
2+
import React from 'react';
3+
4+
import BootstrapTable from 'react-bootstrap-table-next';
5+
import Code from 'components/common/code-block';
6+
import { productsGenerator } from 'utils/common';
7+
8+
const products = productsGenerator();
9+
10+
const columns = [{
11+
dataField: 'id',
12+
text: 'Product ID',
13+
sort: true
14+
}, {
15+
dataField: 'name',
16+
text: 'Product Name',
17+
sort: true,
18+
sortCaret: (order, column) => {
19+
if (!order) return (<span>&nbsp;&nbsp;Desc/Asc</span>);
20+
else if (order === 'asc') return (<span>&nbsp;&nbsp;Desc/<font color="red">Asc</font></span>);
21+
else if (order === 'desc') return (<span>&nbsp;&nbsp;<font color="red">Desc</font>/Asc</span>);
22+
return null;
23+
}
24+
}, {
25+
dataField: 'price',
26+
text: 'Product Price'
27+
}];
28+
29+
const sourceCode = `\
30+
import BootstrapTable from 'react-bootstrap-table-next';
31+
32+
const columns = [{
33+
dataField: 'id',
34+
text: 'Product ID',
35+
sort: true
36+
}, {
37+
dataField: 'name',
38+
text: 'Product Name',
39+
sort: true,
40+
sortCaret: (order, column) => {
41+
if (!order) return (<span>&nbsp;&nbsp;Desc/Asc</span>);
42+
else if (order === 'asc') return (<span>&nbsp;&nbsp;Desc/<font color="red">Asc</font></span>);
43+
else if (order === 'desc') return (<span>&nbsp;&nbsp;<font color="red">Desc</font>/Asc</span>);
44+
return null;
45+
}
46+
}, {
47+
dataField: 'price',
48+
text: 'Product Price'
49+
}];
50+
51+
<BootstrapTable keyField='id' data={ products } columns={ columns } />
52+
`;
53+
54+
export default () => (
55+
<div>
56+
<BootstrapTable keyField="id" data={ products } columns={ columns } />
57+
<Code>{ sourceCode }</Code>
58+
</div>
59+
);

packages/react-bootstrap-table2-example/stories/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import NoDataTable from 'examples/basic/no-data-table';
1313
import CustomizedIdClassesTable from 'examples/basic/customized-id-classes';
1414
import CaptionTable from 'examples/basic/caption-table';
1515
import LargeTable from 'examples/basic/large-table';
16+
import ExposedAPITable from 'examples/basic/exposed-function';
1617

1718
// bootstrap 4
1819
import Bootstrap4DefaultSortTable from 'examples/bootstrap4/sort';
@@ -83,6 +84,7 @@ import DefaultSortTable from 'examples/sort/default-sort-table';
8384
import DefaultSortDirectionTable from 'examples/sort/default-sort-direction';
8485
import SortEvents from 'examples/sort/sort-events';
8586
import CustomSortTable from 'examples/sort/custom-sort-table';
87+
import CustomSortCaretTable from 'examples/sort/custom-sort-caret';
8688
import HeaderSortingClassesTable from 'examples/sort/header-sorting-classes';
8789
import HeaderSortingStyleTable from 'examples/sort/header-sorting-style';
8890

@@ -189,7 +191,8 @@ storiesOf('Basic Table', module)
189191
.add('Indication For Empty Table', () => <NoDataTable />)
190192
.add('Customized id and class table', () => <CustomizedIdClassesTable />)
191193
.add('Table with caption', () => <CaptionTable />)
192-
.add('Large Table', () => <LargeTable />);
194+
.add('Large Table', () => <LargeTable />)
195+
.add('Exposed API', () => <ExposedAPITable />);
193196

194197
storiesOf('Bootstrap 4', module)
195198
.addDecorator(bootstrapStyle(BOOTSTRAP_VERSION.FOUR))
@@ -267,6 +270,7 @@ storiesOf('Sort Table', module)
267270
.add('Default Sort Direction Table', () => <DefaultSortDirectionTable />)
268271
.add('Sort Events', () => <SortEvents />)
269272
.add('Custom Sort Fuction', () => <CustomSortTable />)
273+
.add('Custom Sort Caret', () => <CustomSortCaretTable />)
270274
.add('Custom Classes on Sorting Header Column', () => <HeaderSortingClassesTable />)
271275
.add('Custom Style on Sorting Header Column', () => <HeaderSortingStyleTable />);
272276

packages/react-bootstrap-table2-paginator/src/context.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export default (
6868
currPage = newPage;
6969
needNewState = true;
7070
}
71+
} else {
72+
this.currPage = nextProps.pagination.options.page;
73+
this.currSizePerPage = nextProps.pagination.options.sizePerPage;
7174
}
7275

7376
if (needNewState) {

packages/react-bootstrap-table2-paginator/test/context.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,27 @@ describe('PaginationContext', () => {
160160
});
161161
});
162162

163+
describe('when remote pagination is enable', () => {
164+
beforeEach(() => {
165+
wrapper = shallow(shallowContext({ ...defaultPagination }, true));
166+
instance = wrapper.instance();
167+
wrapper.render();
168+
nextProps = {
169+
data,
170+
pagination: { ...defaultPagination, options: { page: 3, sizePerPage: 5 } }
171+
};
172+
instance.componentWillReceiveProps(nextProps);
173+
});
174+
175+
it('should always set currPage from nextProps.pagination.options.page', () => {
176+
expect(instance.currPage).toEqual(nextProps.pagination.options.page);
177+
});
178+
179+
it('should always set currSizePerPage from nextProps.pagination.options.sizePerPage', () => {
180+
expect(instance.currSizePerPage).toEqual(nextProps.pagination.options.sizePerPage);
181+
});
182+
});
183+
163184
describe('when page is not align', () => {
164185
beforeEach(() => {
165186
wrapper = shallow(shallowContext({

packages/react-bootstrap-table2-toolkit/src/search/context.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ export default (options = {
3939
const { data, columns } = this.props;
4040
let { searchText } = this.props;
4141

42-
if (isRemoteSearch() && this.performRemoteSearch) {
43-
handleRemoteSearchChange(searchText);
42+
if (isRemoteSearch()) {
43+
if (this.performRemoteSearch) {
44+
handleRemoteSearchChange(searchText);
45+
}
4446
return data;
4547
}
4648

packages/react-bootstrap-table2/src/contexts/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const withContext = Base =>
6666
selectionProps
6767
) => (
6868
<Base
69+
ref={ n => this.table = n }
6970
{ ...this.props }
7071
{ ...selectionProps }
7172
{ ...sortProps }
@@ -91,6 +92,7 @@ const withContext = Base =>
9192
) => (
9293
<this.SelectionContext.Provider
9394
{ ...baseProps }
95+
ref={ n => this.selectionContext = n }
9496
selectRow={ this.props.selectRow }
9597
data={ rootProps.getData(filterProps, searchProps, sortProps, paginationProps) }
9698
>
@@ -123,6 +125,7 @@ const withContext = Base =>
123125
) => (
124126
<this.RowExpandContext.Provider
125127
{ ...baseProps }
128+
ref={ n => this.rowExpandContext = n }
126129
expandRow={ this.props.expandRow }
127130
data={ rootProps.getData(filterProps, searchProps, sortProps, paginationProps) }
128131
>

0 commit comments

Comments
 (0)