Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [classes](#classes)
* [wrapperClasses](#wrapperClasses)
* [headerClasses](#headerClasses)
* [headerWrapperClasses](#headerWrapperClasses)
* [cellEdit](#cellEdit)
* [selectRow](#selectRow)
* [expandRow](#expandRow)
Expand Down Expand Up @@ -137,6 +138,9 @@ Customize class on the outer element which wrap up the `table` element.
### <a name='headerClasses'>headerClasses - [String]</a>
Customize class on the header row(`tr`).

### <a name='headerWrapperClasses'>headerWrapperClasses - [String]</a>
Customize class on the `thead`.

### <a name='cellEdit'>cellEdit - [Object]</a>
Makes table cells editable, please see [cellEdit definition](./cell-edit.md) for more detail.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const columns = [{

<BootstrapTable id="bar" keyField='id' data={ products } columns={ columns } />
<BootstrapTable classes="foo" keyField='id' data={ products } columns={ columns } />
<BootstrapTable headerWrapperClasses="foo" keyField="id" data={ products } columns={ columns } />
<BootstrapTable bodyClasses="foo" keyField="id" data={ products } columns={ columns } />
<BootstrapTable wrapperClasses="boo" keyField="id" data={ products } columns={ columns } />
`;

Expand All @@ -44,6 +46,12 @@ export default () => (
<h4> Customized table className </h4>
<BootstrapTable classes="foo" keyField="id" data={ products } columns={ columns } />

<h4> Customized thead className </h4>
<BootstrapTable headerWrapperClasses="foo" keyField="id" data={ products } columns={ columns } />

<h4> Customized tbody className </h4>
<BootstrapTable bodyClasses="foo" keyField="id" data={ products } columns={ columns } />

<h4> Customized wrapper className </h4>
<BootstrapTable wrapperClasses="boo" keyField="id" data={ products } columns={ columns } />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ const columns = [{
data={ products }
columns={ columns }
exportCSV={ {
fileName: 'custom.csv',
separator: '|',
ignoreHeader: true,
noAutoBOM: false,
blobType: 'text/csv;charset=ansi'
ignoreFooter: false
} }
>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
table.foo {
.foo {
background-color: $grey-500;
}

Expand Down
18 changes: 18 additions & 0 deletions packages/react-bootstrap-table2-toolkit/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ class ToolkitProvider extends statelessDecorator(React.Component) {
this.state = state;
}

// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps(nextProps) {
let columnToggle = this.state.columnToggle;
if (nextProps.columnToggle) {
columnToggle = nextProps.columns
.reduce((obj, column) => {
obj[column.dataField] = !column.hidden;
return obj;
}, {});
} else {
columnToggle = null;
}
this.setState({
...this.state,
columnToggle
});
}

onSearch(searchText) {
if (searchText !== this.state.searchText) {
this.setState({ searchText });
Expand Down
2 changes: 1 addition & 1 deletion packages/react-bootstrap-table2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
],
"dependencies": {
"classnames": "2.2.5",
"classnames": "^2.2.5",
"react-transition-group": "2.5.3",
"underscore": "1.9.1"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/react-bootstrap-table2/src/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class Body extends React.Component {
rowStyle,
rowClasses,
rowEvents,
expandRow
expandRow,
className
} = this.props;

let content;
Expand Down Expand Up @@ -110,7 +111,7 @@ class Body extends React.Component {
}

return (
<tbody>{ content }</tbody>
<tbody className={ className }>{ content }</tbody>
);
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/react-bootstrap-table2/src/bootstrap-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
<Header
columns={ columns }
className={ this.props.headerClasses }
wrapperClasses={ this.props.headerWrapperClasses }
sortField={ this.props.sortField }
sortOrder={ this.props.sortOrder }
onSort={ this.props.onSort }
Expand All @@ -119,6 +120,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
/>
)}
<Body
className={ this.props.bodyClasses }
data={ this.getData() }
keyField={ keyField }
tabIndexCell={ tabIndexCell }
Expand Down Expand Up @@ -163,7 +165,10 @@ BootstrapTable.propTypes = {
tabIndexCell: PropTypes.bool,
id: PropTypes.string,
classes: PropTypes.string,
headerClasses: PropTypes.string,
bodyClasses: PropTypes.string,
wrapperClasses: PropTypes.string,
headerWrapperClasses: PropTypes.string,
condensed: PropTypes.bool,
caption: PropTypes.oneOfType([
PropTypes.node,
Expand Down Expand Up @@ -221,7 +226,6 @@ BootstrapTable.propTypes = {
rowStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
rowEvents: PropTypes.object,
rowClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
headerClasses: PropTypes.string,
filtersClasses: PropTypes.string,
filterPosition: PropTypes.oneOf([
Const.FILTERS_POSITION_TOP,
Expand Down
6 changes: 6 additions & 0 deletions packages/react-bootstrap-table2/src/contexts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ const withContext = Base =>
}

UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.columns.filter(col => col.sort).length > 0 && !this.SortContext) {
this.SortContext = createSortContext(
dataOperator, this.isRemoteSort, this.handleRemoteSortChange);
} else {
this.SortContext = null;
}
if (!nextProps.pagination && this.props.pagination) {
this.PaginationContext = null;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/react-bootstrap-table2/src/header-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ class HeaderCell extends eventDelegater(React.Component) {

if (sort) {
const customClick = cellAttrs.onClick;
cellAttrs.onKeyUp = (e) => {
if (e.key === 'Enter') {
onSort(column);
if (_.isFunction(customClick)) customClick(e);
}
};
cellAttrs.onClick = (e) => {
onSort(column);
if (_.isFunction(customClick)) customClick(e);
Expand Down
6 changes: 4 additions & 2 deletions packages/react-bootstrap-table2/src/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const Header = (props) => {
currFilters,
onExternalFilter,
filterPosition,
globalSortCaret
globalSortCaret,
wrapperClasses
} = props;

let SelectionHeaderCellComp = () => null;
Expand Down Expand Up @@ -80,7 +81,7 @@ const Header = (props) => {
}

return (
<thead>
<thead className={ wrapperClasses }>
<tr className={ className }>
{ childrens }
</tr>
Expand All @@ -99,6 +100,7 @@ Header.propTypes = {
onExternalFilter: PropTypes.func,
globalSortCaret: PropTypes.func,
className: PropTypes.string,
wrapperClasses: PropTypes.string,
expandRow: PropTypes.object,
filterPosition: PropTypes.oneOf([
Const.FILTERS_POSITION_TOP,
Expand Down
14 changes: 14 additions & 0 deletions packages/react-bootstrap-table2/test/header-cell.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,25 @@ describe('HeaderCell', () => {
expect(wrapper.find('th').prop('onClick')).toBeDefined();
});

it('should have onKeyUp event on header cell', () => {
expect(wrapper.find('th').prop('onKeyUp')).toBeDefined();
});

it('should trigger onSort callback when click on header cell', () => {
wrapper.find('th').simulate('click');
expect(onSortCallBack.callCount).toBe(1);
});

it('should trigger onSort callback when keyup Enter on header cell', () => {
wrapper.find('th').simulate('keyup', { key: 'Enter' });
expect(onSortCallBack.callCount).toBe(1);
});

it('should not trigger onSort callback when keyup key is not Enter on header cell', () => {
wrapper.find('th').simulate('keyup', { key: 'test-key' });
expect(onSortCallBack.callCount).toBe(0);
});

describe('and sorting prop is false', () => {
it('header should render SortSymbol as default', () => {
expect(wrapper.find(SortSymbol).length).toBe(1);
Expand Down