mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
Merge pull request #576 from react-bootstrap-table/develop
20180930 release
This commit is contained in:
commit
51c82cdfb3
@ -13,7 +13,7 @@ Rebuilt [react-bootstrap-table](https://github.com/AllenFang/react-bootstrap-tab
|
||||
* [`react-bootstrap-table2-overlay`](https://www.npmjs.com/package/react-bootstrap-table2-overlay)
|
||||
* [`react-bootstrap-table2-toolkit`](https://www.npmjs.com/package/react-bootstrap-table2-toolkit)
|
||||
|
||||
This can help your application with less bundled size and also help us have clean design to avoid handling to much logic in kernal module(SRP).
|
||||
This can help your application with less bundled size and also help us have clean design to avoid handling to much logic in kernel module(SRP).
|
||||
|
||||
## Migration
|
||||
If you are the user from legacy [`react-bootstrap-table`](https://github.com/AllenFang/react-bootstrap-table/), please have a look on [this](./docs/migration.md).
|
||||
@ -40,4 +40,4 @@ $ yarn storybook
|
||||
$ Go to localhost:6006
|
||||
```
|
||||
|
||||
**Storybook examples: [`packages/react-bootstrap-table2-example/examples`](https://github.com/react-bootstrap-table/react-bootstrap-table2/tree/master/packages/react-bootstrap-table2-example/examples)**
|
||||
**Storybook examples: [`packages/react-bootstrap-table2-example/examples`](https://github.com/react-bootstrap-table/react-bootstrap-table2/tree/master/packages/react-bootstrap-table2-example/examples)**
|
||||
|
||||
@ -10,6 +10,7 @@ $ npm install react-bootstrap-table2-editor --save
|
||||
* [blurToSave](#blurToSave)
|
||||
* [nonEditableRows](#nonEditableRows)
|
||||
* [timeToCloseMessage](#timeToCloseMessage)
|
||||
* [autoSelectText](#autoSelectText)
|
||||
* [beforeSaveCell](#beforeSaveCell)
|
||||
* [afterSaveCell](#afterSaveCell)
|
||||
* [errorMessage](#errorMessage)
|
||||
@ -43,6 +44,11 @@ Default is `false`, enable it will be able to save the cell automatically when b
|
||||
### <a name='nonEditableRows'>cellEdit.nonEditableRows - [Function]</a>
|
||||
`cellEdit.nonEditableRows` accept a callback function and expect return an array which used to restrict all the columns of some rows as non-editable. So the each item in return array should be rowkey(`keyField`)
|
||||
|
||||
### <a name='autoSelectText'>cellEdit.autoSelectText - [Bool]</a>
|
||||
Default is false, when enable it, `react-bootstrap-table2` will help you to select the text in the text input automatically when editing.
|
||||
|
||||
> NOTE: This props only work for `text` and `textarea`.
|
||||
|
||||
### <a name='timeToCloseMessage'>cellEdit.timeToCloseMessage - [Function]</a>
|
||||
If a [`column.validator`](./columns.md#validator) defined and the new value is invalid, `react-bootstrap-table2` will popup a alert at the bottom of editor. `cellEdit.timeToCloseMessage` is a chance to let you decide how long the alert should be stay. Default is 3000 millisecond.
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
* [onExpand](#onExpand)
|
||||
* [onExpandAll](#onExpandAll)
|
||||
* [showExpandColumn](#showExpandColumn)
|
||||
* [onlyOneExpanding](#onlyOneExpanding)
|
||||
* [expandColumnRenderer](#expandColumnRenderer)
|
||||
* [expandHeaderColumnRenderer](#expandHeaderColumnRenderer)
|
||||
|
||||
@ -127,3 +128,13 @@ const expandRow = {
|
||||
showExpandColumn: true
|
||||
};
|
||||
```
|
||||
|
||||
### <a name='onlyOneExpanding'>expandRow.onlyOneExpanding - [Bool]</a>
|
||||
Default is `false`. Enable this will only allow one row get expand at the same time.
|
||||
|
||||
```js
|
||||
const expandRow = {
|
||||
renderer: (row) => ...
|
||||
onlyOneExpanding: true
|
||||
};
|
||||
```
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
* [onSelect](#onSelect)
|
||||
* [onSelectAll](#onSelectAll)
|
||||
* [hideSelectColumn](#hideSelectColumn)
|
||||
* [hideSelectAll](#hideSelectAll)
|
||||
* [selectionRenderer](#selectionRenderer)
|
||||
* [selectionHeaderRenderer](#selectionHeaderRenderer)
|
||||
|
||||
@ -222,3 +223,13 @@ const selectRow = {
|
||||
bgColor: 'red'
|
||||
};
|
||||
```
|
||||
|
||||
### <a name='hideSelectAll'>selectRow.hideSelectAll - [Bool]</a>
|
||||
Default is `false`, if you don't want to render the select all checkbox on the header of selection column, give this prop as `true`!
|
||||
|
||||
```js
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
hideSelectAll: true
|
||||
};
|
||||
```
|
||||
|
||||
@ -24,6 +24,7 @@ export default (_, onStartEdit) =>
|
||||
onUpdate: PropTypes.func.isRequired,
|
||||
onEscape: PropTypes.func.isRequired,
|
||||
timeToCloseMessage: PropTypes.number,
|
||||
autoSelectText: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
style: PropTypes.object
|
||||
}
|
||||
@ -31,6 +32,7 @@ export default (_, onStartEdit) =>
|
||||
static defaultProps = {
|
||||
timeToCloseMessage: TIME_TO_CLOSE_MESSAGE,
|
||||
className: null,
|
||||
autoSelectText: false,
|
||||
style: {}
|
||||
}
|
||||
|
||||
@ -121,7 +123,7 @@ export default (_, onStartEdit) =>
|
||||
|
||||
render() {
|
||||
let editor;
|
||||
const { row, column, className, style, rowIndex, columnIndex } = this.props;
|
||||
const { row, column, className, style, rowIndex, columnIndex, autoSelectText } = this.props;
|
||||
const { dataField } = column;
|
||||
|
||||
const value = _.get(row, dataField);
|
||||
@ -174,13 +176,13 @@ export default (_, onStartEdit) =>
|
||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.SELECT) {
|
||||
editor = <DropdownEditor { ...editorProps } />;
|
||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.TEXTAREA) {
|
||||
editor = <TextAreaEditor { ...editorProps } />;
|
||||
editor = <TextAreaEditor { ...editorProps } autoSelectText={ autoSelectText } />;
|
||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.CHECKBOX) {
|
||||
editor = <CheckBoxEditor { ...editorProps } />;
|
||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.DATE) {
|
||||
editor = <DateEditor { ...editorProps } />;
|
||||
} else {
|
||||
editor = <TextEditor { ...editorProps } />;
|
||||
editor = <TextEditor { ...editorProps } autoSelectText={ autoSelectText } />;
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -5,9 +5,10 @@ import PropTypes from 'prop-types';
|
||||
|
||||
class TextEditor extends Component {
|
||||
componentDidMount() {
|
||||
const { defaultValue, didMount } = this.props;
|
||||
const { defaultValue, didMount, autoSelectText } = this.props;
|
||||
this.text.value = defaultValue;
|
||||
this.text.focus();
|
||||
if (autoSelectText) this.text.select();
|
||||
if (didMount) didMount();
|
||||
}
|
||||
|
||||
@ -16,7 +17,7 @@ class TextEditor extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { defaultValue, didMount, className, ...rest } = this.props;
|
||||
const { defaultValue, didMount, className, autoSelectText, ...rest } = this.props;
|
||||
const editorClass = cs('form-control editor edit-text', className);
|
||||
return (
|
||||
<input
|
||||
@ -38,11 +39,13 @@ TextEditor.propTypes = {
|
||||
PropTypes.string,
|
||||
PropTypes.number
|
||||
]),
|
||||
autoSelectText: PropTypes.bool,
|
||||
didMount: PropTypes.func
|
||||
};
|
||||
TextEditor.defaultProps = {
|
||||
className: null,
|
||||
defaultValue: '',
|
||||
autoSelectText: false,
|
||||
didMount: undefined
|
||||
};
|
||||
export default TextEditor;
|
||||
|
||||
@ -10,9 +10,10 @@ class TextAreaEditor extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { defaultValue, didMount } = this.props;
|
||||
const { defaultValue, didMount, autoSelectText } = this.props;
|
||||
this.text.value = defaultValue;
|
||||
this.text.focus();
|
||||
if (autoSelectText) this.text.select();
|
||||
if (didMount) didMount();
|
||||
}
|
||||
|
||||
@ -28,7 +29,7 @@ class TextAreaEditor extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { defaultValue, didMount, className, ...rest } = this.props;
|
||||
const { defaultValue, didMount, className, autoSelectText, ...rest } = this.props;
|
||||
const editorClass = cs('form-control editor edit-textarea', className);
|
||||
return (
|
||||
<textarea
|
||||
@ -52,11 +53,13 @@ TextAreaEditor.propTypes = {
|
||||
PropTypes.number
|
||||
]),
|
||||
onKeyDown: PropTypes.func,
|
||||
autoSelectText: PropTypes.bool,
|
||||
didMount: PropTypes.func
|
||||
};
|
||||
TextAreaEditor.defaultProps = {
|
||||
className: '',
|
||||
defaultValue: '',
|
||||
autoSelectText: false,
|
||||
onKeyDown: undefined,
|
||||
didMount: undefined
|
||||
};
|
||||
|
||||
78
packages/react-bootstrap-table2-example/examples/cell-edit/auto-select-text-input-table.js
vendored
Normal file
78
packages/react-bootstrap-table2-example/examples/cell-edit/auto-select-text-input-table.js
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
/* eslint react/prefer-stateless-function: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||
import Code from 'components/common/code-block';
|
||||
import { jobsGenerator } from 'utils/common';
|
||||
|
||||
const jobs = jobsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Job ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Job Name'
|
||||
}, {
|
||||
dataField: 'owner',
|
||||
text: 'Job Owner'
|
||||
}, {
|
||||
dataField: 'type',
|
||||
text: 'Job Type',
|
||||
editor: {
|
||||
type: Type.TEXTAREA
|
||||
}
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import cellEditFactory, { Type } from 'react-bootstrap-table2-editor';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Job ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Job Name'
|
||||
}, {
|
||||
dataField: 'owner',
|
||||
text: 'Job Owner'
|
||||
}, {
|
||||
dataField: 'type',
|
||||
text: 'Job Type',
|
||||
editor: {
|
||||
type: Type.TEXTAREA
|
||||
}
|
||||
}];
|
||||
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ jobs }
|
||||
columns={ columns }
|
||||
cellEdit={
|
||||
cellEditFactory({
|
||||
mode: 'click',
|
||||
autoSelectText: true
|
||||
})
|
||||
}
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<h3>Auto Select Text Input Field When Editing</h3>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ jobs }
|
||||
columns={ columns }
|
||||
cellEdit={
|
||||
cellEditFactory({
|
||||
mode: 'click',
|
||||
autoSelectText: true
|
||||
})
|
||||
}
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
73
packages/react-bootstrap-table2-example/examples/row-expand/expand-only-one.js
vendored
Normal file
73
packages/react-bootstrap-table2-example/examples/row-expand/expand-only-one.js
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsExpandRowsGenerator } from 'utils/common';
|
||||
|
||||
const products = productsExpandRowsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const expandRow = {
|
||||
onlyOneExpanding: true,
|
||||
renderer: row => (
|
||||
<div>
|
||||
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
|
||||
<p>You can render anything here, also you can add additional data on every row object</p>
|
||||
<p>expandRow.renderer callback will pass the origin row object to you</p>
|
||||
</div>
|
||||
)
|
||||
};
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const expandRow = {
|
||||
renderer: row => (
|
||||
<div>
|
||||
<p>{ \`This Expand row is belong to rowKey $\{row.id}\` }</p>
|
||||
<p>You can render anything here, also you can add additional data on every row object</p>
|
||||
<p>expandRow.renderer callback will pass the origin row object to you</p>
|
||||
</div>
|
||||
)
|
||||
};
|
||||
|
||||
<BootstrapTable
|
||||
keyField='id'
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
expandRow={ expandRow }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
expandRow={ expandRow }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
59
packages/react-bootstrap-table2-example/examples/row-selection/hide-select-all.js
vendored
Normal file
59
packages/react-bootstrap-table2-example/examples/row-selection/hide-select-all.js
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
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();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true,
|
||||
hideSelectAll: true
|
||||
};
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const selectRow = {
|
||||
mode: 'checkbox',
|
||||
clickToSelect: true,
|
||||
hideSelectAll: true
|
||||
};
|
||||
|
||||
<BootstrapTable
|
||||
keyField='id'
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
selectRow={ selectRow }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<BootstrapTable keyField="id" data={ products } columns={ columns } selectRow={ selectRow } />
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
83
packages/react-bootstrap-table2-example/examples/search/default-search.js
vendored
Normal file
83
packages/react-bootstrap-table2-example/examples/search/default-search.js
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
/* eslint react/prop-types: 0 */
|
||||
import React from 'react';
|
||||
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';
|
||||
import Code from 'components/common/code-block';
|
||||
import { productsGenerator } from 'utils/common';
|
||||
|
||||
const { SearchBar } = Search;
|
||||
const products = productsGenerator();
|
||||
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
const sourceCode = `\
|
||||
import BootstrapTable from 'react-bootstrap-table-next';
|
||||
import ToolkitProvider, { Search } from 'react-bootstrap-table2-toolkit';
|
||||
|
||||
const { SearchBar } = Search;
|
||||
const columns = [{
|
||||
dataField: 'id',
|
||||
text: 'Product ID'
|
||||
}, {
|
||||
dataField: 'name',
|
||||
text: 'Product Name'
|
||||
}, {
|
||||
dataField: 'price',
|
||||
text: 'Product Price'
|
||||
}];
|
||||
|
||||
<ToolkitProvider
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
search={ { defaultSearch: '2101' } }
|
||||
>
|
||||
{
|
||||
props => (
|
||||
<div>
|
||||
<h3>Input something at below input field:</h3>
|
||||
<SearchBar { ...props.searchProps } />
|
||||
<hr />
|
||||
<BootstrapTable
|
||||
{ ...props.baseProps }
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</ToolkitProvider>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<ToolkitProvider
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
search={ { defaultSearch: '2101' } }
|
||||
>
|
||||
{
|
||||
props => (
|
||||
<div>
|
||||
<h3>Input something at below input field:</h3>
|
||||
<SearchBar { ...props.searchProps } />
|
||||
<hr />
|
||||
<BootstrapTable
|
||||
{ ...props.baseProps }
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
</ToolkitProvider>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
@ -97,6 +97,7 @@ import CellEditHooks from 'examples/cell-edit/cell-edit-hooks-table';
|
||||
import CellEditValidator from 'examples/cell-edit/cell-edit-validator-table';
|
||||
import CellEditStyleTable from 'examples/cell-edit/cell-edit-style-table';
|
||||
import CellEditClassTable from 'examples/cell-edit/cell-edit-class-table';
|
||||
import AutoSelectTextInput from 'examples/cell-edit/auto-select-text-input-table';
|
||||
import EditorStyleTable from 'examples/cell-edit/editor-style-table';
|
||||
import EditorClassTable from 'examples/cell-edit/editor-class-table';
|
||||
import DropdownEditorTable from 'examples/cell-edit/dropdown-editor-table';
|
||||
@ -115,6 +116,7 @@ import ClickToSelectWithCellEditTable from 'examples/row-selection/click-to-sele
|
||||
import SelectionNoDataTable from 'examples/row-selection/selection-no-data';
|
||||
import SelectionStyleTable from 'examples/row-selection/selection-style';
|
||||
import SelectionClassTable from 'examples/row-selection/selection-class';
|
||||
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
|
||||
import CustomSelectionTable from 'examples/row-selection/custom-selection';
|
||||
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
|
||||
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
|
||||
@ -126,6 +128,7 @@ import BasicRowExpand from 'examples/row-expand';
|
||||
import RowExpandManagement from 'examples/row-expand/expand-management';
|
||||
import NonExpandableRows from 'examples/row-expand/non-expandable-rows';
|
||||
import ExpandColumn from 'examples/row-expand/expand-column';
|
||||
import ExpandOnlyOne from 'examples/row-expand/expand-only-one';
|
||||
import CustomExpandColumn from 'examples/row-expand/custom-expand-column';
|
||||
import ExpandHooks from 'examples/row-expand/expand-hooks';
|
||||
|
||||
@ -136,6 +139,7 @@ import CustomPaginationTable from 'examples/pagination/custom-pagination';
|
||||
|
||||
// search
|
||||
import SearchTable from 'examples/search';
|
||||
import DefaultSearch from 'examples/search/default-search';
|
||||
import DefaultCustomSearch from 'examples/search/default-custom-search';
|
||||
import FullyCustomSearch from 'examples/search/fully-custom-search';
|
||||
import SearchFormattedData from 'examples/search/search-formatted';
|
||||
@ -276,6 +280,7 @@ storiesOf('Cell Editing', module)
|
||||
.add('Cell Level Editable', () => <CellLevelEditable />)
|
||||
.add('Rich Hook Functions', () => <CellEditHooks />)
|
||||
.add('Validation', () => <CellEditValidator />)
|
||||
.add('Auto Select Text Input', () => <AutoSelectTextInput />)
|
||||
.add('Custom Cell Style', () => <CellEditStyleTable />)
|
||||
.add('Custom Cell Classes', () => <CellEditClassTable />)
|
||||
.add('Custom Editor Classes', () => <EditorClassTable />)
|
||||
@ -297,6 +302,7 @@ storiesOf('Row Selection', module)
|
||||
.add('Selection without Data', () => <SelectionNoDataTable />)
|
||||
.add('Selection Style', () => <SelectionStyleTable />)
|
||||
.add('Selection Class', () => <SelectionClassTable />)
|
||||
.add('Hide Select All', () => <HideSelectAllTable />)
|
||||
.add('Custom Selection', () => <CustomSelectionTable />)
|
||||
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
||||
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
|
||||
@ -309,6 +315,7 @@ storiesOf('Row Expand', module)
|
||||
.add('Expand Management', () => <RowExpandManagement />)
|
||||
.add('Non Expandabled Rows', () => <NonExpandableRows />)
|
||||
.add('Expand Indicator', () => <ExpandColumn />)
|
||||
.add('Expand Only One Row at The Same Time', () => <ExpandOnlyOne />)
|
||||
.add('Custom Expand Indicator', () => <CustomExpandColumn />)
|
||||
.add('Expand Hooks', () => <ExpandHooks />);
|
||||
|
||||
@ -321,6 +328,7 @@ storiesOf('Pagination', module)
|
||||
storiesOf('Table Search', module)
|
||||
.addDecorator(bootstrapStyle())
|
||||
.add('Basic Search Table', () => <SearchTable />)
|
||||
.add('Default Search Table', () => <DefaultSearch />)
|
||||
.add('Default Custom Search', () => <DefaultCustomSearch />)
|
||||
.add('Fully Custom Search', () => <FullyCustomSearch />)
|
||||
.add('Search Fromatted Value', () => <SearchFormattedData />)
|
||||
|
||||
@ -63,6 +63,22 @@ const { SearchBar } = Search;
|
||||
|
||||
### Search Options
|
||||
|
||||
#### defaultSearch - [string]
|
||||
Accept a string that will be used for default searching when first time table render.
|
||||
|
||||
```js
|
||||
<ToolkitProvider
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
search={ {
|
||||
defaultSearch: 'search something here'
|
||||
} }
|
||||
>
|
||||
// ...
|
||||
</ToolkitProvider>
|
||||
```
|
||||
|
||||
#### searchFormatted - [bool]
|
||||
If you want to search on the formatted data, you are supposed to enable this props. `react-bootstrap-table2` will check if you define the `column.formatter` when doing search.
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ class ToolkitProvider extends statelessDrcorator(React.Component) {
|
||||
search: PropTypes.oneOfType([
|
||||
PropTypes.bool,
|
||||
PropTypes.shape({
|
||||
defaultSearch: PropTypes.string,
|
||||
searchFormatted: PropTypes.bool
|
||||
})
|
||||
]),
|
||||
@ -42,7 +43,7 @@ class ToolkitProvider extends statelessDrcorator(React.Component) {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
searchText: ''
|
||||
searchText: typeof props.search === 'object' ? (props.search.defaultSearch || '') : ''
|
||||
};
|
||||
this._ = null;
|
||||
this.onSearch = this.onSearch.bind(this);
|
||||
@ -85,6 +86,7 @@ class ToolkitProvider extends statelessDrcorator(React.Component) {
|
||||
return (
|
||||
<ToolkitContext.Provider value={ {
|
||||
searchProps: {
|
||||
searchText: this.state.searchText,
|
||||
onSearch: this.onSearch
|
||||
},
|
||||
csvProps: {
|
||||
|
||||
@ -58,7 +58,7 @@ export const save = (
|
||||
}
|
||||
) => {
|
||||
FileSaver.saveAs(
|
||||
new Blob(['\ufeff', content], { type: 'text/plain;charset=utf-8' }),
|
||||
new Blob([content], { type: 'text/plain;charset=utf-8' }),
|
||||
fileName,
|
||||
noAutoBOM
|
||||
);
|
||||
|
||||
@ -47,6 +47,7 @@ const SearchBar = ({
|
||||
style={ style }
|
||||
onKeyUp={ () => debounceCallback() }
|
||||
className={ `form-control ${className}` }
|
||||
defaultValue={ searchText }
|
||||
placeholder={ placeholder || SearchBar.defaultProps.placeholder }
|
||||
{ ...rest }
|
||||
/>
|
||||
|
||||
@ -146,6 +146,7 @@ BootstrapTable.propTypes = {
|
||||
mode: PropTypes.oneOf([Const.ROW_SELECT_SINGLE, Const.ROW_SELECT_MULTIPLE]).isRequired,
|
||||
clickToSelect: PropTypes.bool,
|
||||
clickToEdit: PropTypes.bool,
|
||||
hideSelectAll: PropTypes.bool,
|
||||
onSelect: PropTypes.func,
|
||||
onSelectAll: PropTypes.func,
|
||||
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||
@ -165,6 +166,7 @@ BootstrapTable.propTypes = {
|
||||
onExpandAll: PropTypes.func,
|
||||
nonExpandable: PropTypes.array,
|
||||
showExpandColumn: PropTypes.bool,
|
||||
onlyOneExpanding: PropTypes.bool,
|
||||
expandColumnRenderer: PropTypes.func,
|
||||
expandHeaderColumnRenderer: PropTypes.func
|
||||
}),
|
||||
|
||||
@ -25,12 +25,13 @@ export default (
|
||||
}
|
||||
|
||||
handleRowExpand = (rowKey, expanded, rowIndex, e) => {
|
||||
const { data, keyField, expandRow: { onExpand } } = this.props;
|
||||
const { data, keyField, expandRow: { onExpand, onlyOneExpanding } } = this.props;
|
||||
|
||||
let currExpanded = [...this.state.expanded];
|
||||
|
||||
if (expanded) {
|
||||
currExpanded.push(rowKey);
|
||||
if (onlyOneExpanding) currExpanded = [rowKey];
|
||||
else currExpanded.push(rowKey);
|
||||
} else {
|
||||
currExpanded = currExpanded.filter(value => value !== rowKey);
|
||||
}
|
||||
|
||||
@ -80,7 +80,15 @@ export default (
|
||||
}
|
||||
|
||||
if (onSelectAll) {
|
||||
onSelectAll(!isUnSelect, dataOperator.getSelectedRows(data, keyField, currSelected), e);
|
||||
onSelectAll(
|
||||
!isUnSelect,
|
||||
dataOperator.getSelectedRows(
|
||||
data,
|
||||
keyField,
|
||||
isUnSelect ? this.state.selected : currSelected
|
||||
),
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
this.setState(() => ({ selected: currSelected }));
|
||||
|
||||
@ -49,6 +49,7 @@ const HeaderCell = (props) => {
|
||||
|
||||
if (headerStyle) {
|
||||
cellStyle = _.isFunction(headerStyle) ? headerStyle(column, index) : headerStyle;
|
||||
cellStyle = cellStyle ? { ...cellStyle } : cellStyle;
|
||||
}
|
||||
|
||||
if (headerTitle) {
|
||||
|
||||
@ -5,7 +5,8 @@ const events = [
|
||||
'onClick',
|
||||
'onDoubleClick',
|
||||
'onMouseEnter',
|
||||
'onMouseLeave'
|
||||
'onMouseLeave',
|
||||
'onContextMenu'
|
||||
];
|
||||
|
||||
export default ExtendBase =>
|
||||
|
||||
@ -27,6 +27,7 @@ export default class SelectionHeaderCell extends Component {
|
||||
mode: PropTypes.string.isRequired,
|
||||
checkedStatus: PropTypes.string,
|
||||
onAllRowsSelect: PropTypes.func,
|
||||
hideSelectAll: PropTypes.bool,
|
||||
selectionHeaderRenderer: PropTypes.func
|
||||
}
|
||||
|
||||
@ -63,7 +64,10 @@ export default class SelectionHeaderCell extends Component {
|
||||
CHECKBOX_STATUS_CHECKED, CHECKBOX_STATUS_INDETERMINATE, ROW_SELECT_MULTIPLE
|
||||
} = Const;
|
||||
|
||||
const { mode, checkedStatus, selectionHeaderRenderer } = this.props;
|
||||
const { mode, checkedStatus, selectionHeaderRenderer, hideSelectAll } = this.props;
|
||||
if (hideSelectAll) {
|
||||
return <th data-row-selection />;
|
||||
}
|
||||
|
||||
const checked = checkedStatus === CHECKBOX_STATUS_CHECKED;
|
||||
|
||||
|
||||
@ -220,6 +220,25 @@ describe('DataContext', () => {
|
||||
it('should set state.selected correctly', () => {
|
||||
expect(wrapper.state('selected')).toEqual(data.map(d => d[keyField]));
|
||||
});
|
||||
|
||||
describe('when selectRow.onSelectAll is defined', () => {
|
||||
const onSelectAll = jest.fn();
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(shallowContext({
|
||||
...defaultSelectRow,
|
||||
onSelectAll
|
||||
}));
|
||||
wrapper.instance().handleAllRowsSelect(e, false);
|
||||
});
|
||||
|
||||
it('should call selectRow.onSelectAll correctly', () => {
|
||||
expect(onSelectAll).toHaveBeenCalledWith(
|
||||
true,
|
||||
dataOperator.getSelectedRows(data, keyField, wrapper.state('selected')),
|
||||
e
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when isUnSelect argument is true', () => {
|
||||
@ -234,24 +253,25 @@ describe('DataContext', () => {
|
||||
it('should set state.selected correctly', () => {
|
||||
expect(wrapper.state('selected')).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when selectRow.onSelectAll is defined', () => {
|
||||
const onSelectAll = jest.fn();
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(shallowContext({
|
||||
...defaultSelectRow,
|
||||
onSelectAll
|
||||
}));
|
||||
wrapper.instance().handleAllRowsSelect(e, false);
|
||||
});
|
||||
describe('when selectRow.onSelectAll is defined', () => {
|
||||
const onSelectAll = jest.fn();
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(shallowContext({
|
||||
...defaultSelectRow,
|
||||
selected: data.map(d => d[keyField]),
|
||||
onSelectAll
|
||||
}));
|
||||
wrapper.instance().handleAllRowsSelect(e, true);
|
||||
});
|
||||
|
||||
it('should call selectRow.onSelectAll correctly', () => {
|
||||
expect(onSelectAll).toHaveBeenCalledWith(
|
||||
true,
|
||||
dataOperator.getSelectedRows(data, keyField, wrapper.state('selected')),
|
||||
e
|
||||
);
|
||||
it('should call selectRow.onSelectAll correctly', () => {
|
||||
expect(onSelectAll).toHaveBeenCalledWith(
|
||||
false,
|
||||
dataOperator.getSelectedRows(data, keyField, data.map(d => d[keyField])),
|
||||
e
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -104,6 +104,22 @@ describe('<SelectionHeaderCell />', () => {
|
||||
});
|
||||
|
||||
describe('render', () => {
|
||||
describe('when props.hideSelectAll is true', () => {
|
||||
beforeEach(() => {
|
||||
const checkedStatus = Const.CHECKBOX_STATUS_CHECKED;
|
||||
|
||||
wrapper = shallow(
|
||||
<SelectionHeaderCell mode="checkbox" checkedStatus={ checkedStatus } hideSelectAll />
|
||||
);
|
||||
});
|
||||
|
||||
it('should render empty th element', () => {
|
||||
expect(wrapper.find('th').length).toBe(1);
|
||||
expect(wrapper.find('th[data-row-selection]').length).toBe(1);
|
||||
expect(wrapper.find(CheckBox).length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when props.mode is radio', () => {
|
||||
beforeEach(() => {
|
||||
const checkedStatus = Const.CHECKBOX_STATUS_CHECKED;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user