mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 05:30:05 +00:00
Compare commits
10 Commits
react-boot
...
react-boot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a7c1def5b | ||
|
|
77b8ed53bf | ||
|
|
6bc54ef3ec | ||
|
|
6168bd7532 | ||
|
|
36fa9b8630 | ||
|
|
737922a5a4 | ||
|
|
0f37fae23d | ||
|
|
ce7e05d7f9 | ||
|
|
067006eb72 | ||
|
|
8fa10e3b6f |
@@ -20,6 +20,7 @@
|
|||||||
* [hideSelectAll](#hideSelectAll)
|
* [hideSelectAll](#hideSelectAll)
|
||||||
* [selectionRenderer](#selectionRenderer)
|
* [selectionRenderer](#selectionRenderer)
|
||||||
* [selectionHeaderRenderer](#selectionHeaderRenderer)
|
* [selectionHeaderRenderer](#selectionHeaderRenderer)
|
||||||
|
* [headerColumnStyle](#headerColumnStyle)
|
||||||
|
|
||||||
### <a name="mode">selectRow.mode - [String]</a>
|
### <a name="mode">selectRow.mode - [String]</a>
|
||||||
|
|
||||||
@@ -198,6 +199,31 @@ const selectRow = {
|
|||||||
|
|
||||||
> By default, `react-bootstrap-table2` will help you to handle the click event, it's not necessary to handle again by developer.
|
> By default, `react-bootstrap-table2` will help you to handle the click event, it's not necessary to handle again by developer.
|
||||||
|
|
||||||
|
|
||||||
|
### <a name='headerColumnStyle'>selectRow.headerColumnStyle - [Object | Function]</a>
|
||||||
|
A way to custome the selection header cell. `headerColumnStyle` not only accept a simple style object but also a callback function for more flexible customization:
|
||||||
|
|
||||||
|
### Style Object
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
headerColumnStyle: { backgroundColor: 'blue' }
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Callback Function
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
headerColumnStyle: (status) => (
|
||||||
|
// status available value is checked, indeterminate and unchecked
|
||||||
|
return { backgroundColor: 'blue' };
|
||||||
|
)
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### <a name='onSelect'>selectRow.onSelect - [Function]</a>
|
### <a name='onSelect'>selectRow.onSelect - [Function]</a>
|
||||||
This callback function will be called when a row is select/unselect and pass following three arguments:
|
This callback function will be called when a row is select/unselect and pass following three arguments:
|
||||||
`row`, `isSelect`, `rowIndex` and `e`.
|
`row`, `isSelect`, `rowIndex` and `e`.
|
||||||
|
|||||||
@@ -45,8 +45,12 @@ class ExposedFunctionTable extends React.Component {
|
|||||||
console.log(this.node.table.props.data);
|
console.log(this.node.table.props.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleGetCurrentData = () => {
|
||||||
|
console.log(this.node.table.props.data);
|
||||||
|
}
|
||||||
|
|
||||||
handleGetSelectedData = () => {
|
handleGetSelectedData = () => {
|
||||||
console.log(this.node.selectionContext.state.selected);
|
console.log(this.node.selectionContext.selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleGetExpandedData = () => {
|
handleGetExpandedData = () => {
|
||||||
@@ -117,7 +121,7 @@ export default class ExposedFunctionTable extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleGetSelectedData = () => {
|
handleGetSelectedData = () => {
|
||||||
console.log(this.node.selectionContext.state.selected);
|
console.log(this.node.selectionContext.selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleGetExpandedData = () => {
|
handleGetExpandedData = () => {
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ const columns = [{
|
|||||||
}];
|
}];
|
||||||
|
|
||||||
const expandRow = {
|
const expandRow = {
|
||||||
|
onlyOneExpanding: true,
|
||||||
renderer: row => (
|
renderer: row => (
|
||||||
<div>
|
<div>
|
||||||
<p>{ \`This Expand row is belong to rowKey $\{row.id}\` }</p>
|
<p>{ \`This Expand row is belong to rowKey $\{row.id}\` }</p>
|
||||||
|
|||||||
111
packages/react-bootstrap-table2-example/examples/row-selection/header-style.js
vendored
Normal file
111
packages/react-bootstrap-table2-example/examples/row-selection/header-style.js
vendored
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator(2);
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const selectRow1 = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
headerColumnStyle: {
|
||||||
|
backgroundColor: 'blue'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode1 = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = ...
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
headerColumnStyle: {
|
||||||
|
backgroundColor: 'blue'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const selectRow2 = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
headerColumnStyle: (status) => {
|
||||||
|
if (status === 'checked') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'yellow'
|
||||||
|
};
|
||||||
|
} else if (status === 'indeterminate') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'pink'
|
||||||
|
};
|
||||||
|
} else if (status === 'unchecked') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'grey'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const sourceCode2 = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = ...
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
headerColumnStyle: (status) => {
|
||||||
|
if (status === 'checked') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'yellow'
|
||||||
|
};
|
||||||
|
} else if (status === 'indeterminate') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'pink'
|
||||||
|
};
|
||||||
|
} else if (status === 'unchecked') {
|
||||||
|
return {
|
||||||
|
backgroundColor: 'grey'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow1 } />
|
||||||
|
<Code>{ sourceCode1 }</Code>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow2 } />
|
||||||
|
<Code>{ sourceCode2 }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-example",
|
"name": "react-bootstrap-table2-example",
|
||||||
"version": "1.0.24",
|
"version": "1.0.25",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ import SelectionWithExpansionTable from 'examples/row-selection/selection-with-e
|
|||||||
import SelectionNoDataTable from 'examples/row-selection/selection-no-data';
|
import SelectionNoDataTable from 'examples/row-selection/selection-no-data';
|
||||||
import SelectionStyleTable from 'examples/row-selection/selection-style';
|
import SelectionStyleTable from 'examples/row-selection/selection-style';
|
||||||
import SelectionClassTable from 'examples/row-selection/selection-class';
|
import SelectionClassTable from 'examples/row-selection/selection-class';
|
||||||
|
import HeaderStyleTable from 'examples/row-selection/header-style';
|
||||||
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
|
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
|
||||||
import CustomSelectionTable from 'examples/row-selection/custom-selection';
|
import CustomSelectionTable from 'examples/row-selection/custom-selection';
|
||||||
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
|
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
|
||||||
@@ -385,6 +386,7 @@ storiesOf('Row Selection', module)
|
|||||||
.add('Selection without Data', () => <SelectionNoDataTable />)
|
.add('Selection without Data', () => <SelectionNoDataTable />)
|
||||||
.add('Selection Style', () => <SelectionStyleTable />)
|
.add('Selection Style', () => <SelectionStyleTable />)
|
||||||
.add('Selection Class', () => <SelectionClassTable />)
|
.add('Selection Class', () => <SelectionClassTable />)
|
||||||
|
.add('Custom Selection Column Header Style', () => <HeaderStyleTable />)
|
||||||
.add('Hide Select All', () => <HideSelectAllTable />)
|
.add('Hide Select All', () => <HideSelectAllTable />)
|
||||||
.add('Custom Selection', () => <CustomSelectionTable />)
|
.add('Custom Selection', () => <CustomSelectionTable />)
|
||||||
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-toolkit",
|
"name": "react-bootstrap-table2-toolkit",
|
||||||
"version": "1.4.1",
|
"version": "1.4.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": {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export const transform = (
|
|||||||
cellContent = m.formatter(cellContent, row, rowIndex, m.formatExtraData);
|
cellContent = m.formatter(cellContent, row, rowIndex, m.formatExtraData);
|
||||||
}
|
}
|
||||||
if (m.type === String) {
|
if (m.type === String) {
|
||||||
return `"${cellContent}"`;
|
return `"${`${cellContent}`.replace(/"/g, '""')}"`;
|
||||||
}
|
}
|
||||||
return cellContent;
|
return cellContent;
|
||||||
}).join(separator)).join('\n');
|
}).join(separator)).join('\n');
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ SearchBar.defaultProps = {
|
|||||||
placeholder: 'Search',
|
placeholder: 'Search',
|
||||||
delay: 250,
|
delay: 250,
|
||||||
searchText: '',
|
searchText: '',
|
||||||
tableId: 0
|
tableId: '0'
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SearchBar;
|
export default SearchBar;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table-next",
|
"name": "react-bootstrap-table-next",
|
||||||
"version": "3.1.1",
|
"version": "3.1.2",
|
||||||
"description": "Next generation of react-bootstrap-table",
|
"description": "Next generation of react-bootstrap-table",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -167,7 +167,8 @@ BootstrapTable.propTypes = {
|
|||||||
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
hideSelectColumn: PropTypes.bool,
|
hideSelectColumn: PropTypes.bool,
|
||||||
selectionRenderer: PropTypes.func,
|
selectionRenderer: PropTypes.func,
|
||||||
selectionHeaderRenderer: PropTypes.func
|
selectionHeaderRenderer: PropTypes.func,
|
||||||
|
headerColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
|
||||||
}),
|
}),
|
||||||
expandRow: PropTypes.shape({
|
expandRow: PropTypes.shape({
|
||||||
renderer: PropTypes.func,
|
renderer: PropTypes.func,
|
||||||
|
|||||||
21
packages/react-bootstrap-table2/src/cell.js
vendored
21
packages/react-bootstrap-table2/src/cell.js
vendored
@@ -8,7 +8,7 @@ import _ from './utils';
|
|||||||
class Cell extends eventDelegater(Component) {
|
class Cell extends eventDelegater(Component) {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.handleEditingCell = this.handleEditingCell.bind(this);
|
this.createHandleEditingCell = this.createHandleEditingCell.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps) {
|
shouldComponentUpdate(nextProps) {
|
||||||
@@ -43,17 +43,10 @@ class Cell extends eventDelegater(Component) {
|
|||||||
return shouldUpdate;
|
return shouldUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEditingCell(e) {
|
createHandleEditingCell = originFunc => (e) => {
|
||||||
const { column, onStart, rowIndex, columnIndex, clickToEdit, dbclickToEdit } = this.props;
|
const { onStart, rowIndex, columnIndex, clickToEdit, dbclickToEdit } = this.props;
|
||||||
const { events } = column;
|
if ((clickToEdit || dbclickToEdit) && _.isFunction(originFunc)) {
|
||||||
if (events) {
|
originFunc(e);
|
||||||
if (clickToEdit) {
|
|
||||||
const customClick = events.onClick;
|
|
||||||
if (_.isFunction(customClick)) customClick(e);
|
|
||||||
} else if (dbclickToEdit) {
|
|
||||||
const customDbClick = events.onDoubleClick;
|
|
||||||
if (_.isFunction(customDbClick)) customDbClick(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (onStart) {
|
if (onStart) {
|
||||||
onStart(rowIndex, columnIndex);
|
onStart(rowIndex, columnIndex);
|
||||||
@@ -85,9 +78,9 @@ class Cell extends eventDelegater(Component) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (clickToEdit && editable) {
|
if (clickToEdit && editable) {
|
||||||
attrs.onClick = this.handleEditingCell;
|
attrs.onClick = this.createHandleEditingCell(attrs.onClick);
|
||||||
} else if (dbclickToEdit && editable) {
|
} else if (dbclickToEdit && editable) {
|
||||||
attrs.onDoubleClick = this.handleEditingCell;
|
attrs.onDoubleClick = this.createHandleEditingCell(attrs.onDoubleClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import dataOperator from '../store/operators';
|
import dataOperator from '../store/operators';
|
||||||
|
import _ from '../utils';
|
||||||
|
|
||||||
const RowExpandContext = React.createContext();
|
const RowExpandContext = React.createContext();
|
||||||
|
|
||||||
@@ -81,7 +82,7 @@ class RowExpandProvider extends React.Component {
|
|||||||
if (expandAll) {
|
if (expandAll) {
|
||||||
currExpanded = expanded.concat(dataOperator.expandableKeys(data, keyField, nonExpandable));
|
currExpanded = expanded.concat(dataOperator.expandableKeys(data, keyField, nonExpandable));
|
||||||
} else {
|
} else {
|
||||||
currExpanded = expanded.filter(s => typeof data.find(d => d[keyField] === s) === 'undefined');
|
currExpanded = expanded.filter(s => typeof data.find(d => _.get(d, keyField) === s) === 'undefined');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onExpandAll) {
|
if (onExpandAll) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import React, { Component } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Const from '../const';
|
import Const from '../const';
|
||||||
import { BootstrapContext } from '../contexts/bootstrap';
|
import { BootstrapContext } from '../contexts/bootstrap';
|
||||||
|
import _ from '../utils';
|
||||||
|
|
||||||
export const CheckBox = ({ className, checked, indeterminate }) => (
|
export const CheckBox = ({ className, checked, indeterminate }) => (
|
||||||
<input
|
<input
|
||||||
@@ -28,7 +29,8 @@ export default class SelectionHeaderCell extends Component {
|
|||||||
checkedStatus: PropTypes.string,
|
checkedStatus: PropTypes.string,
|
||||||
onAllRowsSelect: PropTypes.func,
|
onAllRowsSelect: PropTypes.func,
|
||||||
hideSelectAll: PropTypes.bool,
|
hideSelectAll: PropTypes.bool,
|
||||||
selectionHeaderRenderer: PropTypes.func
|
selectionHeaderRenderer: PropTypes.func,
|
||||||
|
headerColumnStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -64,7 +66,13 @@ export default class SelectionHeaderCell extends Component {
|
|||||||
CHECKBOX_STATUS_CHECKED, CHECKBOX_STATUS_INDETERMINATE, ROW_SELECT_MULTIPLE
|
CHECKBOX_STATUS_CHECKED, CHECKBOX_STATUS_INDETERMINATE, ROW_SELECT_MULTIPLE
|
||||||
} = Const;
|
} = Const;
|
||||||
|
|
||||||
const { mode, checkedStatus, selectionHeaderRenderer, hideSelectAll } = this.props;
|
const {
|
||||||
|
mode,
|
||||||
|
checkedStatus,
|
||||||
|
selectionHeaderRenderer,
|
||||||
|
hideSelectAll,
|
||||||
|
headerColumnStyle
|
||||||
|
} = this.props;
|
||||||
if (hideSelectAll) {
|
if (hideSelectAll) {
|
||||||
return <th data-row-selection />;
|
return <th data-row-selection />;
|
||||||
}
|
}
|
||||||
@@ -79,6 +87,10 @@ export default class SelectionHeaderCell extends Component {
|
|||||||
attrs.onClick = this.handleCheckBoxClick;
|
attrs.onClick = this.handleCheckBoxClick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
attrs.style = _.isFunction(headerColumnStyle) ?
|
||||||
|
headerColumnStyle(checkedStatus) :
|
||||||
|
headerColumnStyle;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BootstrapContext.Consumer>
|
<BootstrapContext.Consumer>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
|
import _ from '../utils';
|
||||||
|
|
||||||
export const matchRow = (keyField, id) => row => row[keyField] === id;
|
export const matchRow = (keyField, id) => row => _.get(row, keyField) === id;
|
||||||
|
|
||||||
export const getRowByRowId = (data, keyField, id) => data.find(matchRow(keyField, id));
|
export const getRowByRowId = (data, keyField, id) => data.find(matchRow(keyField, id));
|
||||||
|
|||||||
@@ -124,10 +124,10 @@ describe('Cell', () => {
|
|||||||
onClick: sinon.stub()
|
onClick: sinon.stub()
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
it('should calling custom onClick callback also', () => {
|
|
||||||
|
it('should call onStart correctly', () => {
|
||||||
wrapper.find('td').simulate('click');
|
wrapper.find('td').simulate('click');
|
||||||
expect(onStartCallBack.callCount).toBe(1);
|
expect(onStartCallBack.callCount).toBe(1);
|
||||||
expect(column.events.onClick.callCount).toBe(1);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -164,10 +164,10 @@ describe('Cell', () => {
|
|||||||
onDoubleClick: sinon.stub()
|
onDoubleClick: sinon.stub()
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
it('should calling custom onDoubleClick callback also', () => {
|
|
||||||
|
it('should call onStart correctly', () => {
|
||||||
wrapper.find('td').simulate('doubleclick');
|
wrapper.find('td').simulate('doubleclick');
|
||||||
expect(onStartCallBack.callCount).toBe(1);
|
expect(onStartCallBack.callCount).toBe(1);
|
||||||
expect(column.events.onDoubleClick.callCount).toBe(1);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user