mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 13:40:07 +00:00
Compare commits
73 Commits
refactor/s
...
react-boot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1e5c0cb20 | ||
|
|
7ee38a647f | ||
|
|
01ec19344d | ||
|
|
19be67c914 | ||
|
|
ae4d38cae6 | ||
|
|
81a6428a03 | ||
|
|
166affc4c1 | ||
|
|
d0fb46e39f | ||
|
|
828844a1e9 | ||
|
|
774293b76d | ||
|
|
e77cbdb2df | ||
|
|
ef2f828572 | ||
|
|
15731932cf | ||
|
|
dd54294382 | ||
|
|
185c184f01 | ||
|
|
d45345ed10 | ||
|
|
dda8460017 | ||
|
|
6735536fd8 | ||
|
|
95623bbb5f | ||
|
|
9567c7829d | ||
|
|
8499991c41 | ||
|
|
1e76ca9bdb | ||
|
|
fa13550d8c | ||
|
|
709d59ce62 | ||
|
|
66329ecdbf | ||
|
|
ee6cec5a2d | ||
|
|
52fc84899b | ||
|
|
8c10867b8c | ||
|
|
640ada7659 | ||
|
|
73a5c34535 | ||
|
|
2879cf891e | ||
|
|
994ed2e395 | ||
|
|
4b790e4bec | ||
|
|
21e7c3a53a | ||
|
|
6fce0d7066 | ||
|
|
154f1c91c3 | ||
|
|
02d78e5104 | ||
|
|
41cc6b01af | ||
|
|
bd410e7303 | ||
|
|
eced3eef1f | ||
|
|
ca5a41a8b3 | ||
|
|
7a31729ebb | ||
|
|
3a8faf8170 | ||
|
|
532581bb6e | ||
|
|
c228b229d2 | ||
|
|
10adbf472c | ||
|
|
a6e2f0f8f8 | ||
|
|
f1d93853ec | ||
|
|
bb7243c5db | ||
|
|
3ea816b2e6 | ||
|
|
b268c4e0cd | ||
|
|
8b8f336878 | ||
|
|
8517248aee | ||
|
|
ae0cd8a32f | ||
|
|
51c82cdfb3 | ||
|
|
8e087329b3 | ||
|
|
ee2885d055 | ||
|
|
901307e471 | ||
|
|
4ff5be706a | ||
|
|
f8a3fedbb2 | ||
|
|
0bf5831b4e | ||
|
|
dd0b8c6b0f | ||
|
|
8f028d9dd4 | ||
|
|
2c68f22646 | ||
|
|
02d566bb32 | ||
|
|
2b12045017 | ||
|
|
0cdf086d56 | ||
|
|
d4fa9a84e3 | ||
|
|
c84fc84b9e | ||
|
|
ad8cdde513 | ||
|
|
db19e7dd9b | ||
|
|
33b36e5108 | ||
|
|
7209441eb6 |
@@ -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-overlay`](https://www.npmjs.com/package/react-bootstrap-table2-overlay)
|
||||||
* [`react-bootstrap-table2-toolkit`](https://www.npmjs.com/package/react-bootstrap-table2-toolkit)
|
* [`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
|
## 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).
|
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
|
$ 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)**
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
* [hover](#hover)
|
* [hover](#hover)
|
||||||
* [condensed](#condensed)
|
* [condensed](#condensed)
|
||||||
* [id](#id)
|
* [id](#id)
|
||||||
|
* [tabIndexCell](#tabIndexCell)
|
||||||
* [classes](#classes)
|
* [classes](#classes)
|
||||||
* [wrapperClasses](#wrapperClasses)
|
* [wrapperClasses](#wrapperClasses)
|
||||||
* [headerClasses](#headerClasses)
|
* [headerClasses](#headerClasses)
|
||||||
@@ -112,6 +113,10 @@ Same as bootstrap `.table-condensed` class for making a table more compact by cu
|
|||||||
|
|
||||||
### <a name='id'>id - [String]</a>
|
### <a name='id'>id - [String]</a>
|
||||||
Customize id on `table` element.
|
Customize id on `table` element.
|
||||||
|
|
||||||
|
### <a name='tabIndexCell'>tabIndexCell - [Bool]</a>
|
||||||
|
Enable the `tabIndex` attribute on `<td>` element.
|
||||||
|
|
||||||
### <a name='classes'>classes - [String]</a>
|
### <a name='classes'>classes - [String]</a>
|
||||||
Customize class on `table` element.
|
Customize class on `table` element.
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ $ npm install react-bootstrap-table2-editor --save
|
|||||||
* [blurToSave](#blurToSave)
|
* [blurToSave](#blurToSave)
|
||||||
* [nonEditableRows](#nonEditableRows)
|
* [nonEditableRows](#nonEditableRows)
|
||||||
* [timeToCloseMessage](#timeToCloseMessage)
|
* [timeToCloseMessage](#timeToCloseMessage)
|
||||||
|
* [autoSelectText](#autoSelectText)
|
||||||
* [beforeSaveCell](#beforeSaveCell)
|
* [beforeSaveCell](#beforeSaveCell)
|
||||||
* [afterSaveCell](#afterSaveCell)
|
* [afterSaveCell](#afterSaveCell)
|
||||||
* [errorMessage](#errorMessage)
|
* [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>
|
### <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`)
|
`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>
|
### <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.
|
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 @@ Available properties in a column object:
|
|||||||
* [formatExtraData](#formatExtraData)
|
* [formatExtraData](#formatExtraData)
|
||||||
* [sort](#sort)
|
* [sort](#sort)
|
||||||
* [sortFunc](#sortFunc)
|
* [sortFunc](#sortFunc)
|
||||||
|
* [sortCaret](#sortCaret)
|
||||||
* [onSort](#onSort)
|
* [onSort](#onSort)
|
||||||
* [classes](#classes)
|
* [classes](#classes)
|
||||||
* [style](#style)
|
* [style](#style)
|
||||||
@@ -154,6 +155,20 @@ Enable the column sort via a `true` value given.
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## <a name='sortCaret'>column.sortCaret - [Function]</a>
|
||||||
|
Use`column.sortCaret` to custom the sort caret. This callback function accept two arguments: `order` and `column`
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
// omit...
|
||||||
|
sort: true,
|
||||||
|
sortCaret: (order, column) => {
|
||||||
|
return //...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
> The possible value of `order` argument is **`asc`**, **`desc`** and **`undefined`**.
|
||||||
|
|
||||||
## <a name='classes'>column.classes - [String | Function]</a>
|
## <a name='classes'>column.classes - [String | Function]</a>
|
||||||
It's available to have custom class on table column:
|
It's available to have custom class on table column:
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
* [onExpand](#onExpand)
|
* [onExpand](#onExpand)
|
||||||
* [onExpandAll](#onExpandAll)
|
* [onExpandAll](#onExpandAll)
|
||||||
* [showExpandColumn](#showExpandColumn)
|
* [showExpandColumn](#showExpandColumn)
|
||||||
|
* [onlyOneExpanding](#onlyOneExpanding)
|
||||||
|
* [expandByColumnOnly](#expandByColumnOnly)
|
||||||
* [expandColumnRenderer](#expandColumnRenderer)
|
* [expandColumnRenderer](#expandColumnRenderer)
|
||||||
* [expandHeaderColumnRenderer](#expandHeaderColumnRenderer)
|
* [expandHeaderColumnRenderer](#expandHeaderColumnRenderer)
|
||||||
|
|
||||||
@@ -127,3 +129,24 @@ const expandRow = {
|
|||||||
showExpandColumn: true
|
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
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### <a name='expandByColumnOnly'>expandRow.expandByColumnOnly - [Bool]</a>
|
||||||
|
Default is `false`. If you want to restrict user to expand/collapse row via clicking the expand column only, you can enable it.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const expandRow = {
|
||||||
|
renderer: (row) => ...,
|
||||||
|
showExpandColumn: true,
|
||||||
|
expandByColumnOnly: true
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|||||||
@@ -12,10 +12,12 @@
|
|||||||
* [bgColor](#bgColor)
|
* [bgColor](#bgColor)
|
||||||
* [nonSelectable)](#nonSelectable)
|
* [nonSelectable)](#nonSelectable)
|
||||||
* [clickToSelect)](#clickToSelect)
|
* [clickToSelect)](#clickToSelect)
|
||||||
|
* [clickToExpand)](#clickToExpand)
|
||||||
* [clickToEdit](#clickToEdit)
|
* [clickToEdit](#clickToEdit)
|
||||||
* [onSelect](#onSelect)
|
* [onSelect](#onSelect)
|
||||||
* [onSelectAll](#onSelectAll)
|
* [onSelectAll](#onSelectAll)
|
||||||
* [hideSelectColumn](#hideSelectColumn)
|
* [hideSelectColumn](#hideSelectColumn)
|
||||||
|
* [hideSelectAll](#hideSelectAll)
|
||||||
* [selectionRenderer](#selectionRenderer)
|
* [selectionRenderer](#selectionRenderer)
|
||||||
* [selectionHeaderRenderer](#selectionHeaderRenderer)
|
* [selectionHeaderRenderer](#selectionHeaderRenderer)
|
||||||
|
|
||||||
@@ -147,6 +149,16 @@ const selectRow = {
|
|||||||
> Note: When you also enable [cellEdit](./cell-edit.md), the `selectRow.clickToSelect` will deactivate the functionality of cell editing
|
> Note: When you also enable [cellEdit](./cell-edit.md), the `selectRow.clickToSelect` will deactivate the functionality of cell editing
|
||||||
> If you want to click on row to select row and edit cell simultaneously, you are suppose to enable [`selectRow.clickToEdit`](#clickToEdit)
|
> If you want to click on row to select row and edit cell simultaneously, you are suppose to enable [`selectRow.clickToEdit`](#clickToEdit)
|
||||||
|
|
||||||
|
### <a name='clickToExpand'>selectRow.clickToExpand - [Bool]</a>
|
||||||
|
Default is false, enable it will let user able to expand and select row when user clicking on the row.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToExpand: true
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### <a name='clickToEdit'>selectRow.clickToEdit - [Bool]</a>
|
### <a name='clickToEdit'>selectRow.clickToEdit - [Bool]</a>
|
||||||
Able to click to edit cell and select row
|
Able to click to edit cell and select row
|
||||||
|
|
||||||
@@ -222,3 +234,13 @@ const selectRow = {
|
|||||||
bgColor: 'red'
|
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
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|||||||
@@ -82,8 +82,8 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"classnames": "2.2.5",
|
"classnames": "2.2.5",
|
||||||
"prop-types": "15.5.10",
|
"prop-types": "15.5.10",
|
||||||
"react": "16.3.2",
|
"react": "16.4.0",
|
||||||
"react-dom": "16.3.2",
|
"react-dom": "16.4.0",
|
||||||
"underscore": "1.9.1"
|
"underscore": "1.9.1"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import createContext from './src/context';
|
import createContext from './src/context';
|
||||||
import bindRowLevelCellEdit from './src/row-binder';
|
import withRowLevelCellEdit from './src/row-consumer';
|
||||||
import createEditingCell from './src/editing-cell-binder';
|
import createEditingCell from './src/editing-cell-consumer';
|
||||||
import {
|
import {
|
||||||
EDITTYPE,
|
EDITTYPE,
|
||||||
DBCLICK_TO_CELL_EDIT,
|
DBCLICK_TO_CELL_EDIT,
|
||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
export default (options = {}) => ({
|
export default (options = {}) => ({
|
||||||
createContext,
|
createContext,
|
||||||
createEditingCell,
|
createEditingCell,
|
||||||
bindRowLevelCellEdit,
|
withRowLevelCellEdit,
|
||||||
DBCLICK_TO_CELL_EDIT,
|
DBCLICK_TO_CELL_EDIT,
|
||||||
DELAY_FOR_DBCLICK,
|
DELAY_FOR_DBCLICK,
|
||||||
options
|
options
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-editor",
|
"name": "react-bootstrap-table2-editor",
|
||||||
"version": "1.0.1",
|
"version": "1.2.0",
|
||||||
"description": "it's the editor addon for react-bootstrap-table2",
|
"description": "it's the editor addon for react-bootstrap-table2",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export default (_, onStartEdit) =>
|
|||||||
onUpdate: PropTypes.func.isRequired,
|
onUpdate: PropTypes.func.isRequired,
|
||||||
onEscape: PropTypes.func.isRequired,
|
onEscape: PropTypes.func.isRequired,
|
||||||
timeToCloseMessage: PropTypes.number,
|
timeToCloseMessage: PropTypes.number,
|
||||||
|
autoSelectText: PropTypes.bool,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
style: PropTypes.object
|
style: PropTypes.object
|
||||||
}
|
}
|
||||||
@@ -31,6 +32,7 @@ export default (_, onStartEdit) =>
|
|||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
timeToCloseMessage: TIME_TO_CLOSE_MESSAGE,
|
timeToCloseMessage: TIME_TO_CLOSE_MESSAGE,
|
||||||
className: null,
|
className: null,
|
||||||
|
autoSelectText: false,
|
||||||
style: {}
|
style: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +123,7 @@ export default (_, onStartEdit) =>
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let editor;
|
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 { dataField } = column;
|
||||||
|
|
||||||
const value = _.get(row, dataField);
|
const value = _.get(row, dataField);
|
||||||
@@ -174,13 +176,13 @@ export default (_, onStartEdit) =>
|
|||||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.SELECT) {
|
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.SELECT) {
|
||||||
editor = <DropdownEditor { ...editorProps } />;
|
editor = <DropdownEditor { ...editorProps } />;
|
||||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.TEXTAREA) {
|
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.TEXTAREA) {
|
||||||
editor = <TextAreaEditor { ...editorProps } />;
|
editor = <TextAreaEditor { ...editorProps } autoSelectText={ autoSelectText } />;
|
||||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.CHECKBOX) {
|
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.CHECKBOX) {
|
||||||
editor = <CheckBoxEditor { ...editorProps } />;
|
editor = <CheckBoxEditor { ...editorProps } />;
|
||||||
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.DATE) {
|
} else if (isDefaultEditorDefined && column.editor.type === EDITTYPE.DATE) {
|
||||||
editor = <DateEditor { ...editorProps } />;
|
editor = <DateEditor { ...editorProps } />;
|
||||||
} else {
|
} else {
|
||||||
editor = <TextEditor { ...editorProps } />;
|
editor = <TextEditor { ...editorProps } autoSelectText={ autoSelectText } />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -30,9 +30,14 @@ export default (Component, selectRowEnabled) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
return props => (
|
function withConsumer(props) {
|
||||||
<Consumer>
|
return (
|
||||||
{ cellEdit => renderWithCellEdit(props, cellEdit) }
|
<Consumer>
|
||||||
</Consumer>
|
{ cellEdit => renderWithCellEdit(props, cellEdit) }
|
||||||
);
|
</Consumer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
withConsumer.displayName = 'WithCellEditingRowConsumer';
|
||||||
|
return withConsumer;
|
||||||
};
|
};
|
||||||
@@ -5,9 +5,10 @@ import PropTypes from 'prop-types';
|
|||||||
|
|
||||||
class TextEditor extends Component {
|
class TextEditor extends Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { defaultValue, didMount } = this.props;
|
const { defaultValue, didMount, autoSelectText } = this.props;
|
||||||
this.text.value = defaultValue;
|
this.text.value = defaultValue;
|
||||||
this.text.focus();
|
this.text.focus();
|
||||||
|
if (autoSelectText) this.text.select();
|
||||||
if (didMount) didMount();
|
if (didMount) didMount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ class TextEditor extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
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);
|
const editorClass = cs('form-control editor edit-text', className);
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
@@ -38,11 +39,13 @@ TextEditor.propTypes = {
|
|||||||
PropTypes.string,
|
PropTypes.string,
|
||||||
PropTypes.number
|
PropTypes.number
|
||||||
]),
|
]),
|
||||||
|
autoSelectText: PropTypes.bool,
|
||||||
didMount: PropTypes.func
|
didMount: PropTypes.func
|
||||||
};
|
};
|
||||||
TextEditor.defaultProps = {
|
TextEditor.defaultProps = {
|
||||||
className: null,
|
className: null,
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
|
autoSelectText: false,
|
||||||
didMount: undefined
|
didMount: undefined
|
||||||
};
|
};
|
||||||
export default TextEditor;
|
export default TextEditor;
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ class TextAreaEditor extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { defaultValue, didMount } = this.props;
|
const { defaultValue, didMount, autoSelectText } = this.props;
|
||||||
this.text.value = defaultValue;
|
this.text.value = defaultValue;
|
||||||
this.text.focus();
|
this.text.focus();
|
||||||
|
if (autoSelectText) this.text.select();
|
||||||
if (didMount) didMount();
|
if (didMount) didMount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ class TextAreaEditor extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
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);
|
const editorClass = cs('form-control editor edit-textarea', className);
|
||||||
return (
|
return (
|
||||||
<textarea
|
<textarea
|
||||||
@@ -52,11 +53,13 @@ TextAreaEditor.propTypes = {
|
|||||||
PropTypes.number
|
PropTypes.number
|
||||||
]),
|
]),
|
||||||
onKeyDown: PropTypes.func,
|
onKeyDown: PropTypes.func,
|
||||||
|
autoSelectText: PropTypes.bool,
|
||||||
didMount: PropTypes.func
|
didMount: PropTypes.func
|
||||||
};
|
};
|
||||||
TextAreaEditor.defaultProps = {
|
TextAreaEditor.defaultProps = {
|
||||||
className: '',
|
className: '',
|
||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
|
autoSelectText: false,
|
||||||
onKeyDown: undefined,
|
onKeyDown: undefined,
|
||||||
didMount: undefined
|
didMount: undefined
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,210 +0,0 @@
|
|||||||
import 'jsdom-global/register';
|
|
||||||
import React from 'react';
|
|
||||||
import { mount } from 'enzyme';
|
|
||||||
import _ from 'react-bootstrap-table-next/src/utils';
|
|
||||||
import op from 'react-bootstrap-table-next/src/store/operators';
|
|
||||||
|
|
||||||
import cellEditFactory from '../index';
|
|
||||||
import { CLICK_TO_CELL_EDIT, DBCLICK_TO_CELL_EDIT } from '../src/const';
|
|
||||||
import createCellEditContext from '../src/context';
|
|
||||||
import bindCellEditing from '../src/cell-binder';
|
|
||||||
|
|
||||||
describe('Cell Binder', () => {
|
|
||||||
let wrapper;
|
|
||||||
let cellEdit;
|
|
||||||
const data = [{
|
|
||||||
id: 1,
|
|
||||||
name: 'A'
|
|
||||||
}, {
|
|
||||||
id: 2,
|
|
||||||
name: 'B'
|
|
||||||
}];
|
|
||||||
let columns;
|
|
||||||
const rowIndex = 1;
|
|
||||||
const row = { id: 1, name: 'A' };
|
|
||||||
const keyField = 'id';
|
|
||||||
const columnIndex = 1;
|
|
||||||
|
|
||||||
const { Provider } = createCellEditContext(_, op, false, jest.fn());
|
|
||||||
const BaseComponent = () => null;
|
|
||||||
const WithCellEditComponent = bindCellEditing(
|
|
||||||
props => <BaseComponent { ...props } />,
|
|
||||||
keyField,
|
|
||||||
_
|
|
||||||
);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
columns = [{
|
|
||||||
dataField: 'id',
|
|
||||||
text: 'ID'
|
|
||||||
}, {
|
|
||||||
dataField: 'name',
|
|
||||||
text: 'Name'
|
|
||||||
}];
|
|
||||||
});
|
|
||||||
|
|
||||||
describe(`if cellEdit.mode is ${CLICK_TO_CELL_EDIT}`, () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
cellEdit = cellEditFactory({ mode: CLICK_TO_CELL_EDIT });
|
|
||||||
wrapper = mount(
|
|
||||||
<Provider data={ data } keyField={ keyField } cellEdit={ cellEdit }>
|
|
||||||
<WithCellEditComponent
|
|
||||||
row={ row }
|
|
||||||
column={ columns[1] }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columnIndex={ columnIndex }
|
|
||||||
/>
|
|
||||||
</Provider>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should inject correct props to target component', () => {
|
|
||||||
expect(wrapper.find(BaseComponent)).toHaveLength(1);
|
|
||||||
expect(wrapper.find(BaseComponent).prop('clickToEdit')).toBeTruthy();
|
|
||||||
expect(wrapper.find(BaseComponent).prop('dbclickToEdit')).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe(`if cellEdit.mode is ${DBCLICK_TO_CELL_EDIT}`, () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
cellEdit = cellEditFactory({ mode: DBCLICK_TO_CELL_EDIT });
|
|
||||||
wrapper = mount(
|
|
||||||
<Provider data={ data } keyField={ keyField } cellEdit={ cellEdit }>
|
|
||||||
<WithCellEditComponent
|
|
||||||
row={ row }
|
|
||||||
column={ columns[1] }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columnIndex={ columnIndex }
|
|
||||||
/>
|
|
||||||
</Provider>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should inject correct props to target component', () => {
|
|
||||||
expect(wrapper.find(BaseComponent)).toHaveLength(1);
|
|
||||||
expect(wrapper.find(BaseComponent).prop('clickToEdit')).toBeFalsy();
|
|
||||||
expect(wrapper.find(BaseComponent).prop('dbclickToEdit')).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('if column prop is a key column', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
cellEdit = cellEditFactory({ mode: CLICK_TO_CELL_EDIT });
|
|
||||||
wrapper = mount(
|
|
||||||
<Provider data={ data } keyField={ keyField } cellEdit={ cellEdit }>
|
|
||||||
<WithCellEditComponent
|
|
||||||
row={ row }
|
|
||||||
column={ columns[0] }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columnIndex={ columnIndex }
|
|
||||||
editable
|
|
||||||
/>
|
|
||||||
</Provider>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should inject negative editable prop to target component', () => {
|
|
||||||
expect(wrapper.find(BaseComponent)).toHaveLength(1);
|
|
||||||
expect(wrapper.find(BaseComponent).prop('editable')).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('if editable prop is true(Row Level)', () => {
|
|
||||||
describe('but column.editable prop is false', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
cellEdit = cellEditFactory({ mode: CLICK_TO_CELL_EDIT });
|
|
||||||
columns[1].editable = false;
|
|
||||||
wrapper = mount(
|
|
||||||
<Provider data={ data } keyField={ keyField } cellEdit={ cellEdit }>
|
|
||||||
<WithCellEditComponent
|
|
||||||
row={ row }
|
|
||||||
column={ columns[1] }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columnIndex={ columnIndex }
|
|
||||||
editable
|
|
||||||
/>
|
|
||||||
</Provider>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should inject negative editable prop to target component', () => {
|
|
||||||
expect(wrapper.find(BaseComponent)).toHaveLength(1);
|
|
||||||
expect(wrapper.find(BaseComponent).prop('editable')).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('and column.editable prop is true or not defined', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
cellEdit = cellEditFactory({ mode: CLICK_TO_CELL_EDIT });
|
|
||||||
wrapper = mount(
|
|
||||||
<Provider data={ data } keyField={ keyField } cellEdit={ cellEdit }>
|
|
||||||
<WithCellEditComponent
|
|
||||||
row={ row }
|
|
||||||
column={ columns[1] }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columnIndex={ columnIndex }
|
|
||||||
editable
|
|
||||||
/>
|
|
||||||
</Provider>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should inject positive editable prop to target component', () => {
|
|
||||||
expect(wrapper.find(BaseComponent)).toHaveLength(1);
|
|
||||||
expect(wrapper.find(BaseComponent).prop('editable')).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('if editable prop is false(Row Level)', () => {
|
|
||||||
describe('even if column.editable prop is true or not defined', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
cellEdit = cellEditFactory({ mode: CLICK_TO_CELL_EDIT });
|
|
||||||
columns[1].editable = true;
|
|
||||||
wrapper = mount(
|
|
||||||
<Provider data={ data } keyField={ keyField } cellEdit={ cellEdit }>
|
|
||||||
<WithCellEditComponent
|
|
||||||
row={ row }
|
|
||||||
column={ columns[1] }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columnIndex={ columnIndex }
|
|
||||||
editable={ false }
|
|
||||||
/>
|
|
||||||
</Provider>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should inject negative editable prop to target component', () => {
|
|
||||||
expect(wrapper.find(BaseComponent)).toHaveLength(1);
|
|
||||||
expect(wrapper.find(BaseComponent).prop('editable')).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('if column.editable prop is a function', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
cellEdit = cellEditFactory({ mode: CLICK_TO_CELL_EDIT });
|
|
||||||
columns[1].editable = jest.fn().mockReturnValue(false);
|
|
||||||
wrapper = mount(
|
|
||||||
<Provider data={ data } keyField={ keyField } cellEdit={ cellEdit }>
|
|
||||||
<WithCellEditComponent
|
|
||||||
row={ row }
|
|
||||||
column={ columns[1] }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columnIndex={ columnIndex }
|
|
||||||
editable
|
|
||||||
/>
|
|
||||||
</Provider>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call column.editable function correctly', () => {
|
|
||||||
expect(columns[1].editable).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should inject correct editable prop to target component', () => {
|
|
||||||
expect(wrapper.find(BaseComponent)).toHaveLength(1);
|
|
||||||
expect(wrapper.find(BaseComponent).prop('editable')).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -3,12 +3,12 @@ import React from 'react';
|
|||||||
import { mount, shallow } from 'enzyme';
|
import { mount, shallow } from 'enzyme';
|
||||||
import _ from 'react-bootstrap-table-next/src/utils';
|
import _ from 'react-bootstrap-table-next/src/utils';
|
||||||
|
|
||||||
import cellEditFactory from '../index';
|
import cellEditFactory from '..';
|
||||||
import { CLICK_TO_CELL_EDIT } from '../src/const';
|
import { CLICK_TO_CELL_EDIT } from '../src/const';
|
||||||
import createCellEditContext from '../src/context';
|
import createCellEditContext from '../src/context';
|
||||||
import bindEditingCell from '../src/editing-cell-binder';
|
import bindEditingCell from '../src/editing-cell-consumer';
|
||||||
|
|
||||||
describe('Cell Binder', () => {
|
describe('Editing Cell Consumer', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let cellEdit;
|
let cellEdit;
|
||||||
const data = [{
|
const data = [{
|
||||||
@@ -4,12 +4,12 @@ import { mount } from 'enzyme';
|
|||||||
import _ from 'react-bootstrap-table-next/src/utils';
|
import _ from 'react-bootstrap-table-next/src/utils';
|
||||||
import op from 'react-bootstrap-table-next/src/store/operators';
|
import op from 'react-bootstrap-table-next/src/store/operators';
|
||||||
|
|
||||||
import cellEditFactory from '../index';
|
import cellEditFactory from '..';
|
||||||
import { CLICK_TO_CELL_EDIT, DBCLICK_TO_CELL_EDIT, DELAY_FOR_DBCLICK } from '../src/const';
|
import { CLICK_TO_CELL_EDIT, DBCLICK_TO_CELL_EDIT, DELAY_FOR_DBCLICK } from '../src/const';
|
||||||
import createCellEditContext from '../src/context';
|
import createCellEditContext from '../src/context';
|
||||||
import bindCellEditing from '../src/row-binder';
|
import withRowLevelCellEdit from '../src/row-consumer';
|
||||||
|
|
||||||
describe('Row Binder', () => {
|
describe('Row Consumer', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let cellEdit;
|
let cellEdit;
|
||||||
const data = [{
|
const data = [{
|
||||||
@@ -28,7 +28,7 @@ describe('Row Binder', () => {
|
|||||||
|
|
||||||
describe('if cellEdit.nonEditableRows is undefined', () => {
|
describe('if cellEdit.nonEditableRows is undefined', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const WithCellEditComponent = bindCellEditing(
|
const WithCellEditComponent = withRowLevelCellEdit(
|
||||||
props => <BaseComponent { ...props } />,
|
props => <BaseComponent { ...props } />,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@@ -52,7 +52,7 @@ describe('Row Binder', () => {
|
|||||||
const nonEditableRows = jest.fn().mockReturnValue([value]);
|
const nonEditableRows = jest.fn().mockReturnValue([value]);
|
||||||
describe('if value prop is match in one of cellEdit.nonEditableRows', () => {
|
describe('if value prop is match in one of cellEdit.nonEditableRows', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const WithCellEditComponent = bindCellEditing(
|
const WithCellEditComponent = withRowLevelCellEdit(
|
||||||
props => <BaseComponent { ...props } />,
|
props => <BaseComponent { ...props } />,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@@ -72,7 +72,7 @@ describe('Row Binder', () => {
|
|||||||
|
|
||||||
describe('if value prop is not match in one of cellEdit.nonEditableRows', () => {
|
describe('if value prop is not match in one of cellEdit.nonEditableRows', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const WithCellEditComponent = bindCellEditing(
|
const WithCellEditComponent = withRowLevelCellEdit(
|
||||||
props => <BaseComponent { ...props } />,
|
props => <BaseComponent { ...props } />,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@@ -93,7 +93,7 @@ describe('Row Binder', () => {
|
|||||||
|
|
||||||
describe(`if selectRowEnabled argument is true and cellEdit.mode is ${DBCLICK_TO_CELL_EDIT}`, () => {
|
describe(`if selectRowEnabled argument is true and cellEdit.mode is ${DBCLICK_TO_CELL_EDIT}`, () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const WithCellEditComponent = bindCellEditing(
|
const WithCellEditComponent = withRowLevelCellEdit(
|
||||||
props => <BaseComponent { ...props } />,
|
props => <BaseComponent { ...props } />,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@@ -115,7 +115,7 @@ describe('Row Binder', () => {
|
|||||||
const ridx = 0;
|
const ridx = 0;
|
||||||
const cidx = 1;
|
const cidx = 1;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const WithCellEditComponent = bindCellEditing(
|
const WithCellEditComponent = withRowLevelCellEdit(
|
||||||
props => <BaseComponent { ...props } />,
|
props => <BaseComponent { ...props } />,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
182
packages/react-bootstrap-table2-example/examples/basic/exposed-function.js
vendored
Normal file
182
packages/react-bootstrap-table2-example/examples/basic/exposed-function.js
vendored
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
/* eslint no-return-assign: 0 */
|
||||||
|
/* eslint no-console: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
import paginationFactory from 'react-bootstrap-table2-paginator';
|
||||||
|
import filterFactory, { textFilter } from 'react-bootstrap-table2-filter';
|
||||||
|
import Code from 'components/common/code-block';
|
||||||
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
|
const products = productsGenerator(63);
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
sort: true
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
sort: true,
|
||||||
|
filter: textFilter()
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price',
|
||||||
|
sort: true,
|
||||||
|
filter: textFilter()
|
||||||
|
}];
|
||||||
|
|
||||||
|
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'
|
||||||
|
}];
|
||||||
|
|
||||||
|
class ExposedFunctionTable extends React.Component {
|
||||||
|
handleGetCurrentData = () => {
|
||||||
|
console.log(this.node.table.props.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetSelectedData = () => {
|
||||||
|
console.log(this.node.selectionContext.state.selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetExpandedData = () => {
|
||||||
|
console.log(this.node.rowExpandContext.state.expanded);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetCurrentPage = () => {
|
||||||
|
console.log(this.node.paginationContext.currPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetCurrentSizePerPage = () => {
|
||||||
|
console.log(this.node.paginationContext.currSizePerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetCurrentSortColumn = () => {
|
||||||
|
console.log(this.node.sortContext.state.sortColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetCurrentSortOrder = () => {
|
||||||
|
console.log(this.node.sortContext.state.sortOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetCurrentFilter = () => {
|
||||||
|
console.log(this.node.filterContext.currFilters);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const expandRow = {
|
||||||
|
renderer: row => (
|
||||||
|
<div>
|
||||||
|
<p>.....</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>
|
||||||
|
),
|
||||||
|
showExpandColumn: true
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentData }>Get Current Display Rows</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetSelectedData }>Get Current Selected Rows</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetExpandedData }>Get Current Expanded Rows</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentPage }>Get Current Page</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentSizePerPage }>Get Current Size Per Page</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentSortColumn }>Get Current Sort Column</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentSortOrder }>Get Current Sort Order</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentFilter }>Get Current Filter Information</button>
|
||||||
|
<BootstrapTable
|
||||||
|
ref={ n => this.node = n }
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
pagination={ paginationFactory() }
|
||||||
|
selectRow={ { mode: 'checkbox', clickToSelect: true } }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default class ExposedFunctionTable extends React.Component {
|
||||||
|
handleGetCurrentData = () => {
|
||||||
|
console.log(this.node.table.props.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetSelectedData = () => {
|
||||||
|
console.log(this.node.selectionContext.state.selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetExpandedData = () => {
|
||||||
|
console.log(this.node.rowExpandContext.state.expanded);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetCurrentPage = () => {
|
||||||
|
console.log(this.node.paginationContext.currPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetCurrentSizePerPage = () => {
|
||||||
|
console.log(this.node.paginationContext.currSizePerPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetCurrentSortColumn = () => {
|
||||||
|
console.log(this.node.sortContext.state.sortColumn);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetCurrentSortOrder = () => {
|
||||||
|
console.log(this.node.sortContext.state.sortOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleGetCurrentFilter = () => {
|
||||||
|
console.log(this.node.filterContext.currFilters);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
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>
|
||||||
|
),
|
||||||
|
showExpandColumn: true
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentData }>Get Current Display Rows</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetSelectedData }>Get Current Selected Rows</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetExpandedData }>Get Current Expanded Rows</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentPage }>Get Current Page</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentSizePerPage }>Get Current Size Per Page</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentSortColumn }>Get Current Sort Column</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentSortOrder }>Get Current Sort Order</button>
|
||||||
|
<button className="btn btn-default" onClick={ this.handleGetCurrentFilter }>Get Current Filter Information</button>
|
||||||
|
<BootstrapTable
|
||||||
|
ref={ n => this.node = n }
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
filter={ filterFactory() }
|
||||||
|
pagination={ paginationFactory() }
|
||||||
|
selectRow={ { mode: 'checkbox', clickToSelect: true } }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import BootstrapTable from 'react-bootstrap-table-next';
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
// import cellEditFactory from 'react-bootstrap-table2-editor';
|
|
||||||
import { productsGenerator } from 'utils/common';
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
const products = productsGenerator(2000);
|
const products = productsGenerator(3000);
|
||||||
|
|
||||||
const columns = [{
|
const columns = [{
|
||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
@@ -17,41 +16,25 @@ const columns = [{
|
|||||||
text: 'Product Price'
|
text: 'Product Price'
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// cellEdit={ cellEditFactory({
|
const expandRow = {
|
||||||
// mode: 'click'
|
showExpandColumn: true,
|
||||||
// }) }
|
renderer: row => (
|
||||||
|
<div>
|
||||||
// const expandRow = {
|
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
|
||||||
// renderer: row => (
|
<p>You can render anything here, also you can add additional data on every row object</p>
|
||||||
// <div>
|
<p>expandRow.renderer callback will pass the origin row object to you</p>
|
||||||
// <p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
|
</div>
|
||||||
// <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 selectRow = {
|
|
||||||
mode: 'checkbox',
|
|
||||||
clickToSelect: true,
|
|
||||||
bgColor: 'red'
|
|
||||||
// selected: [2],
|
|
||||||
// hideSelectColumn: true
|
|
||||||
// clickToEdit: true
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* eslint react/prefer-stateless-function: 0 */
|
export default () => (
|
||||||
export default class Table extends React.PureComponent {
|
<div>
|
||||||
render() {
|
<BootstrapTable
|
||||||
return (
|
keyField="id"
|
||||||
<div>
|
data={ products }
|
||||||
<BootstrapTable
|
columns={ columns }
|
||||||
keyField="id"
|
selectRow={ { mode: 'checkbox', clickToSelect: true } }
|
||||||
data={ products }
|
expandRow={ expandRow }
|
||||||
columns={ columns }
|
/>
|
||||||
selectRow={ selectRow }
|
</div>
|
||||||
/>
|
);
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
54
packages/react-bootstrap-table2-example/examples/basic/tabindex-column.js
vendored
Normal file
54
packages/react-bootstrap-table2-example/examples/basic/tabindex-column.js
vendored
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
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 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'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ { mode: 'checkbox' } }
|
||||||
|
tabIndexCell
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ { mode: 'checkbox' } }
|
||||||
|
tabIndexCell
|
||||||
|
/>
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
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>
|
||||||
|
);
|
||||||
76
packages/react-bootstrap-table2-example/examples/row-expand/expand-by-column-only.js
vendored
Normal file
76
packages/react-bootstrap-table2-example/examples/row-expand/expand-by-column-only.js
vendored
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
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 = {
|
||||||
|
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>
|
||||||
|
),
|
||||||
|
showExpandColumn: true,
|
||||||
|
expandByColumnOnly: 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 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>
|
||||||
|
),
|
||||||
|
showExpandColumn: true
|
||||||
|
};
|
||||||
|
|
||||||
|
<BootstrapTable
|
||||||
|
keyField='id'
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<h3>Only able to expand row via clicking expand column(indicator)</h3>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
/>
|
||||||
|
<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>
|
||||||
|
);
|
||||||
@@ -18,7 +18,9 @@ const columns = [{
|
|||||||
}];
|
}];
|
||||||
|
|
||||||
const selectRow = {
|
const selectRow = {
|
||||||
mode: 'checkbox'
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
clickToExpand: true
|
||||||
};
|
};
|
||||||
|
|
||||||
const expandRow = {
|
const expandRow = {
|
||||||
@@ -48,7 +50,8 @@ const columns = [{
|
|||||||
|
|
||||||
const selectRow = {
|
const selectRow = {
|
||||||
mode: 'checkbox',
|
mode: 'checkbox',
|
||||||
clickToSelect: true
|
clickToSelect: true,
|
||||||
|
clickToExpand: true
|
||||||
};
|
};
|
||||||
|
|
||||||
const expandRow = {
|
const expandRow = {
|
||||||
@@ -67,6 +70,7 @@ const expandRow = {
|
|||||||
data={ products }
|
data={ products }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
selectRow={ selectRow }
|
selectRow={ selectRow }
|
||||||
|
expandRow={ expandRow }
|
||||||
/>
|
/>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
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>
|
||||||
|
);
|
||||||
59
packages/react-bootstrap-table2-example/examples/sort/custom-sort-caret.js
vendored
Normal file
59
packages/react-bootstrap-table2-example/examples/sort/custom-sort-caret.js
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/* eslint no-unused-vars: 0 */
|
||||||
|
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',
|
||||||
|
sort: true
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
sort: true,
|
||||||
|
sortCaret: (order, column) => {
|
||||||
|
if (!order) return (<span> Desc/Asc</span>);
|
||||||
|
else if (order === 'asc') return (<span> Desc/<font color="red">Asc</font></span>);
|
||||||
|
else if (order === 'desc') return (<span> <font color="red">Desc</font>/Asc</span>);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const sourceCode = `\
|
||||||
|
import BootstrapTable from 'react-bootstrap-table-next';
|
||||||
|
|
||||||
|
const columns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'Product ID',
|
||||||
|
sort: true
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Product Name',
|
||||||
|
sort: true,
|
||||||
|
sortCaret: (order, column) => {
|
||||||
|
if (!order) return (<span> Desc/Asc</span>);
|
||||||
|
else if (order === 'asc') return (<span> Desc/<font color="red">Asc</font></span>);
|
||||||
|
else if (order === 'desc') return (<span> <font color="red">Desc</font>/Asc</span>);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Product Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
||||||
|
`;
|
||||||
|
|
||||||
|
export default () => (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
||||||
|
<Code>{ sourceCode }</Code>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Typed from 'typed.js';
|
import Typed from 'typed.js';
|
||||||
|
|
||||||
|
const PROJECT_NAME = 'react-bootstrap-table2';
|
||||||
|
|
||||||
export default class Welcome extends React.Component {
|
export default class Welcome extends React.Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// type.js config
|
// type.js config
|
||||||
@@ -21,14 +23,21 @@ export default class Welcome extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="welcome">
|
<div className="welcome">
|
||||||
<h1 className="welcome-title">react-bootstrap-table2</h1>
|
<div className="welcome-title">
|
||||||
|
<span className="welcome-title-logo">
|
||||||
|
<img src="images/logo-color-square.svg" alt={ `${PROJECT_NAME}-logo` } />
|
||||||
|
</span>
|
||||||
|
<h1>
|
||||||
|
{PROJECT_NAME}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
<span
|
<span
|
||||||
className="welcome-sub-title"
|
className="welcome-sub-title"
|
||||||
ref={ (el) => { this.el = el; } }
|
ref={ (el) => { this.el = el; } }
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<a href="https://github.com/react-bootstrap-table/react-bootstrap-table2" className="github-corner" aria-label="View source on Github">
|
<a href={ `https://github.com/react-bootstrap-table/${PROJECT_NAME}` } className="github-corner" aria-label="View source on Github">
|
||||||
<svg width="80" height="80" viewBox="0 0 250 250" style={ { fill: '#009688', color: '#fff', position: 'absolute', top: '0', border: '0', right: '0' } } aria-hidden="true">
|
<svg width="80" height="80" viewBox="0 0 250 250" style={ { fill: '#0058B7', color: '#fff', position: 'absolute', top: '0', border: '0', right: '0' } } aria-hidden="true">
|
||||||
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z" />
|
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z" />
|
||||||
<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style={ { transformOrigin: '130px 106px' } } className="octo-arm" />
|
<path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style={ { transformOrigin: '130px 106px' } } className="octo-arm" />
|
||||||
<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" className="octo-body" />
|
<path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" className="octo-body" />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-example",
|
"name": "react-bootstrap-table2-example",
|
||||||
"version": "1.0.4",
|
"version": "1.0.7",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
BIN
packages/react-bootstrap-table2-example/public/favicon.ico
Normal file
BIN
packages/react-bootstrap-table2-example/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
@@ -0,0 +1 @@
|
|||||||
|
<svg id="layer_1" data-name="layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 72 72"><defs><style>.cls-1{fill:#059ae6;}.cls-2{fill:#0058b7;}</style></defs><title>logo square</title><polygon class="cls-1" points="22.76 59 22.76 64.35 49.24 51.13 49.24 43.88 44.45 41.5 44.45 48.17 22.76 59"/><polygon class="cls-2" points="22.76 20.87 22.76 47.98 27.55 45.59 27.55 23.83 44.45 15.39 44.45 23.02 33.06 28.71 33.06 31.9 49.24 39.97 49.24 34.62 40.58 30.3 49.24 25.98 49.24 7.65 22.76 20.87"/></svg>
|
||||||
|
After Width: | Height: | Size: 503 B |
@@ -13,6 +13,8 @@ import NoDataTable from 'examples/basic/no-data-table';
|
|||||||
import CustomizedIdClassesTable from 'examples/basic/customized-id-classes';
|
import CustomizedIdClassesTable from 'examples/basic/customized-id-classes';
|
||||||
import CaptionTable from 'examples/basic/caption-table';
|
import CaptionTable from 'examples/basic/caption-table';
|
||||||
import LargeTable from 'examples/basic/large-table';
|
import LargeTable from 'examples/basic/large-table';
|
||||||
|
import ExposedAPITable from 'examples/basic/exposed-function';
|
||||||
|
import TabIndexCellTable from 'examples/basic/tabindex-column';
|
||||||
|
|
||||||
// bootstrap 4
|
// bootstrap 4
|
||||||
import Bootstrap4DefaultSortTable from 'examples/bootstrap4/sort';
|
import Bootstrap4DefaultSortTable from 'examples/bootstrap4/sort';
|
||||||
@@ -83,6 +85,7 @@ import DefaultSortTable from 'examples/sort/default-sort-table';
|
|||||||
import DefaultSortDirectionTable from 'examples/sort/default-sort-direction';
|
import DefaultSortDirectionTable from 'examples/sort/default-sort-direction';
|
||||||
import SortEvents from 'examples/sort/sort-events';
|
import SortEvents from 'examples/sort/sort-events';
|
||||||
import CustomSortTable from 'examples/sort/custom-sort-table';
|
import CustomSortTable from 'examples/sort/custom-sort-table';
|
||||||
|
import CustomSortCaretTable from 'examples/sort/custom-sort-caret';
|
||||||
import HeaderSortingClassesTable from 'examples/sort/header-sorting-classes';
|
import HeaderSortingClassesTable from 'examples/sort/header-sorting-classes';
|
||||||
import HeaderSortingStyleTable from 'examples/sort/header-sorting-style';
|
import HeaderSortingStyleTable from 'examples/sort/header-sorting-style';
|
||||||
|
|
||||||
@@ -97,6 +100,7 @@ import CellEditHooks from 'examples/cell-edit/cell-edit-hooks-table';
|
|||||||
import CellEditValidator from 'examples/cell-edit/cell-edit-validator-table';
|
import CellEditValidator from 'examples/cell-edit/cell-edit-validator-table';
|
||||||
import CellEditStyleTable from 'examples/cell-edit/cell-edit-style-table';
|
import CellEditStyleTable from 'examples/cell-edit/cell-edit-style-table';
|
||||||
import CellEditClassTable from 'examples/cell-edit/cell-edit-class-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 EditorStyleTable from 'examples/cell-edit/editor-style-table';
|
||||||
import EditorClassTable from 'examples/cell-edit/editor-class-table';
|
import EditorClassTable from 'examples/cell-edit/editor-class-table';
|
||||||
import DBClickEditWithSelection from 'examples/cell-edit/dbclick-to-edit-with-selection-table';
|
import DBClickEditWithSelection from 'examples/cell-edit/dbclick-to-edit-with-selection-table';
|
||||||
@@ -117,6 +121,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 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';
|
||||||
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
|
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
|
||||||
@@ -128,6 +133,8 @@ import BasicRowExpand from 'examples/row-expand';
|
|||||||
import RowExpandManagement from 'examples/row-expand/expand-management';
|
import RowExpandManagement from 'examples/row-expand/expand-management';
|
||||||
import NonExpandableRows from 'examples/row-expand/non-expandable-rows';
|
import NonExpandableRows from 'examples/row-expand/non-expandable-rows';
|
||||||
import ExpandColumn from 'examples/row-expand/expand-column';
|
import ExpandColumn from 'examples/row-expand/expand-column';
|
||||||
|
import OnlyExpandByColumn from 'examples/row-expand/expand-by-column-only.js';
|
||||||
|
import ExpandOnlyOne from 'examples/row-expand/expand-only-one';
|
||||||
import CustomExpandColumn from 'examples/row-expand/custom-expand-column';
|
import CustomExpandColumn from 'examples/row-expand/custom-expand-column';
|
||||||
import ExpandHooks from 'examples/row-expand/expand-hooks';
|
import ExpandHooks from 'examples/row-expand/expand-hooks';
|
||||||
|
|
||||||
@@ -138,6 +145,7 @@ import CustomPaginationTable from 'examples/pagination/custom-pagination';
|
|||||||
|
|
||||||
// search
|
// search
|
||||||
import SearchTable from 'examples/search';
|
import SearchTable from 'examples/search';
|
||||||
|
import DefaultSearch from 'examples/search/default-search';
|
||||||
import DefaultCustomSearch from 'examples/search/default-custom-search';
|
import DefaultCustomSearch from 'examples/search/default-custom-search';
|
||||||
import FullyCustomSearch from 'examples/search/fully-custom-search';
|
import FullyCustomSearch from 'examples/search/fully-custom-search';
|
||||||
import SearchFormattedData from 'examples/search/search-formatted';
|
import SearchFormattedData from 'examples/search/search-formatted';
|
||||||
@@ -187,7 +195,9 @@ storiesOf('Basic Table', module)
|
|||||||
.add('Indication For Empty Table', () => <NoDataTable />)
|
.add('Indication For Empty Table', () => <NoDataTable />)
|
||||||
.add('Customized id and class table', () => <CustomizedIdClassesTable />)
|
.add('Customized id and class table', () => <CustomizedIdClassesTable />)
|
||||||
.add('Table with caption', () => <CaptionTable />)
|
.add('Table with caption', () => <CaptionTable />)
|
||||||
.add('Large Table', () => <LargeTable />);
|
.add('Large Table', () => <LargeTable />)
|
||||||
|
.add('Exposed API', () => <ExposedAPITable />)
|
||||||
|
.add('Enable tabIndex on Cell', () => <TabIndexCellTable />);
|
||||||
|
|
||||||
storiesOf('Bootstrap 4', module)
|
storiesOf('Bootstrap 4', module)
|
||||||
.addDecorator(bootstrapStyle(BOOTSTRAP_VERSION.FOUR))
|
.addDecorator(bootstrapStyle(BOOTSTRAP_VERSION.FOUR))
|
||||||
@@ -265,6 +275,7 @@ storiesOf('Sort Table', module)
|
|||||||
.add('Default Sort Direction Table', () => <DefaultSortDirectionTable />)
|
.add('Default Sort Direction Table', () => <DefaultSortDirectionTable />)
|
||||||
.add('Sort Events', () => <SortEvents />)
|
.add('Sort Events', () => <SortEvents />)
|
||||||
.add('Custom Sort Fuction', () => <CustomSortTable />)
|
.add('Custom Sort Fuction', () => <CustomSortTable />)
|
||||||
|
.add('Custom Sort Caret', () => <CustomSortCaretTable />)
|
||||||
.add('Custom Classes on Sorting Header Column', () => <HeaderSortingClassesTable />)
|
.add('Custom Classes on Sorting Header Column', () => <HeaderSortingClassesTable />)
|
||||||
.add('Custom Style on Sorting Header Column', () => <HeaderSortingStyleTable />);
|
.add('Custom Style on Sorting Header Column', () => <HeaderSortingStyleTable />);
|
||||||
|
|
||||||
@@ -278,6 +289,7 @@ storiesOf('Cell Editing', module)
|
|||||||
.add('Cell Level Editable', () => <CellLevelEditable />)
|
.add('Cell Level Editable', () => <CellLevelEditable />)
|
||||||
.add('Rich Hook Functions', () => <CellEditHooks />)
|
.add('Rich Hook Functions', () => <CellEditHooks />)
|
||||||
.add('Validation', () => <CellEditValidator />)
|
.add('Validation', () => <CellEditValidator />)
|
||||||
|
.add('Auto Select Text Input', () => <AutoSelectTextInput />)
|
||||||
.add('Custom Cell Style', () => <CellEditStyleTable />)
|
.add('Custom Cell Style', () => <CellEditStyleTable />)
|
||||||
.add('Custom Cell Classes', () => <CellEditClassTable />)
|
.add('Custom Cell Classes', () => <CellEditClassTable />)
|
||||||
.add('Custom Editor Classes', () => <EditorClassTable />)
|
.add('Custom Editor Classes', () => <EditorClassTable />)
|
||||||
@@ -301,6 +313,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('Hide Select All', () => <HideSelectAllTable />)
|
||||||
.add('Custom Selection', () => <CustomSelectionTable />)
|
.add('Custom Selection', () => <CustomSelectionTable />)
|
||||||
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
.add('Selection Background Color', () => <SelectionBgColorTable />)
|
||||||
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
|
.add('Not Selectabled Rows', () => <NonSelectableRowsTable />)
|
||||||
@@ -313,6 +326,8 @@ storiesOf('Row Expand', module)
|
|||||||
.add('Expand Management', () => <RowExpandManagement />)
|
.add('Expand Management', () => <RowExpandManagement />)
|
||||||
.add('Non Expandabled Rows', () => <NonExpandableRows />)
|
.add('Non Expandabled Rows', () => <NonExpandableRows />)
|
||||||
.add('Expand Indicator', () => <ExpandColumn />)
|
.add('Expand Indicator', () => <ExpandColumn />)
|
||||||
|
.add('Only Expand by Indicator', () => <OnlyExpandByColumn />)
|
||||||
|
.add('Expand Only One Row at The Same Time', () => <ExpandOnlyOne />)
|
||||||
.add('Custom Expand Indicator', () => <CustomExpandColumn />)
|
.add('Custom Expand Indicator', () => <CustomExpandColumn />)
|
||||||
.add('Expand Hooks', () => <ExpandHooks />);
|
.add('Expand Hooks', () => <ExpandHooks />);
|
||||||
|
|
||||||
@@ -325,6 +340,7 @@ storiesOf('Pagination', module)
|
|||||||
storiesOf('Table Search', module)
|
storiesOf('Table Search', module)
|
||||||
.addDecorator(bootstrapStyle())
|
.addDecorator(bootstrapStyle())
|
||||||
.add('Basic Search Table', () => <SearchTable />)
|
.add('Basic Search Table', () => <SearchTable />)
|
||||||
|
.add('Default Search Table', () => <DefaultSearch />)
|
||||||
.add('Default Custom Search', () => <DefaultCustomSearch />)
|
.add('Default Custom Search', () => <DefaultCustomSearch />)
|
||||||
.add('Fully Custom Search', () => <FullyCustomSearch />)
|
.add('Fully Custom Search', () => <FullyCustomSearch />)
|
||||||
.add('Search Fromatted Value', () => <SearchFormattedData />)
|
.add('Search Fromatted Value', () => <SearchFormattedData />)
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
$logo-size: 96px;
|
||||||
|
|
||||||
.welcome {
|
.welcome {
|
||||||
margin-top: 70px;
|
margin-top: 70px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -5,7 +7,22 @@
|
|||||||
|
|
||||||
&-title {
|
&-title {
|
||||||
color: $grey-900;
|
color: $grey-900;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
display: inline-flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-content: center;
|
||||||
|
|
||||||
|
&-logo {
|
||||||
|
position: relative;
|
||||||
|
top: -8px;
|
||||||
|
right: -12px;
|
||||||
|
|
||||||
|
width: $logo-size;
|
||||||
|
height: $logo-size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&-sub-title {
|
&-sub-title {
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
color: $grey-500;
|
color: $grey-500;
|
||||||
|
|||||||
@@ -288,3 +288,4 @@ Following properties is valid in `FILTER_TYPES`:
|
|||||||
* SELECT
|
* SELECT
|
||||||
* NUMBER
|
* NUMBER
|
||||||
* DATE
|
* DATE
|
||||||
|
* MULTISELECT
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-filter",
|
"name": "react-bootstrap-table2-filter",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-paginator",
|
"name": "react-bootstrap-table2-paginator",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ export default (
|
|||||||
currPage = newPage;
|
currPage = newPage;
|
||||||
needNewState = true;
|
needNewState = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.currPage = nextProps.pagination.options.page;
|
||||||
|
this.currSizePerPage = nextProps.pagination.options.sizePerPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needNewState) {
|
if (needNewState) {
|
||||||
|
|||||||
@@ -160,6 +160,27 @@ describe('PaginationContext', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when remote pagination is enable', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = shallow(shallowContext({ ...defaultPagination }, true));
|
||||||
|
instance = wrapper.instance();
|
||||||
|
wrapper.render();
|
||||||
|
nextProps = {
|
||||||
|
data,
|
||||||
|
pagination: { ...defaultPagination, options: { page: 3, sizePerPage: 5 } }
|
||||||
|
};
|
||||||
|
instance.componentWillReceiveProps(nextProps);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should always set currPage from nextProps.pagination.options.page', () => {
|
||||||
|
expect(instance.currPage).toEqual(nextProps.pagination.options.page);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should always set currSizePerPage from nextProps.pagination.options.sizePerPage', () => {
|
||||||
|
expect(instance.currSizePerPage).toEqual(nextProps.pagination.options.sizePerPage);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when page is not align', () => {
|
describe('when page is not align', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(shallowContext({
|
wrapper = shallow(shallowContext({
|
||||||
|
|||||||
@@ -63,6 +63,22 @@ const { SearchBar } = Search;
|
|||||||
|
|
||||||
### Search Options
|
### 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]
|
#### 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.
|
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([
|
search: PropTypes.oneOfType([
|
||||||
PropTypes.bool,
|
PropTypes.bool,
|
||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
|
defaultSearch: PropTypes.string,
|
||||||
searchFormatted: PropTypes.bool
|
searchFormatted: PropTypes.bool
|
||||||
})
|
})
|
||||||
]),
|
]),
|
||||||
@@ -42,7 +43,7 @@ class ToolkitProvider extends statelessDrcorator(React.Component) {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
searchText: ''
|
searchText: typeof props.search === 'object' ? (props.search.defaultSearch || '') : ''
|
||||||
};
|
};
|
||||||
this._ = null;
|
this._ = null;
|
||||||
this.onSearch = this.onSearch.bind(this);
|
this.onSearch = this.onSearch.bind(this);
|
||||||
@@ -85,6 +86,7 @@ class ToolkitProvider extends statelessDrcorator(React.Component) {
|
|||||||
return (
|
return (
|
||||||
<ToolkitContext.Provider value={ {
|
<ToolkitContext.Provider value={ {
|
||||||
searchProps: {
|
searchProps: {
|
||||||
|
searchText: this.state.searchText,
|
||||||
onSearch: this.onSearch
|
onSearch: this.onSearch
|
||||||
},
|
},
|
||||||
csvProps: {
|
csvProps: {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-toolkit",
|
"name": "react-bootstrap-table2-toolkit",
|
||||||
"version": "1.0.3",
|
"version": "1.1.1",
|
||||||
"description": "The toolkit for react-bootstrap-table2",
|
"description": "The toolkit for react-bootstrap-table2",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export const save = (
|
|||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
FileSaver.saveAs(
|
FileSaver.saveAs(
|
||||||
new Blob(['\ufeff', content], { type: 'text/plain;charset=utf-8' }),
|
new Blob([content], { type: 'text/plain;charset=utf-8' }),
|
||||||
fileName,
|
fileName,
|
||||||
noAutoBOM
|
noAutoBOM
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ const SearchBar = ({
|
|||||||
style={ style }
|
style={ style }
|
||||||
onKeyUp={ () => debounceCallback() }
|
onKeyUp={ () => debounceCallback() }
|
||||||
className={ `form-control ${className}` }
|
className={ `form-control ${className}` }
|
||||||
|
defaultValue={ searchText }
|
||||||
placeholder={ placeholder || SearchBar.defaultProps.placeholder }
|
placeholder={ placeholder || SearchBar.defaultProps.placeholder }
|
||||||
{ ...rest }
|
{ ...rest }
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -39,8 +39,10 @@ export default (options = {
|
|||||||
const { data, columns } = this.props;
|
const { data, columns } = this.props;
|
||||||
let { searchText } = this.props;
|
let { searchText } = this.props;
|
||||||
|
|
||||||
if (isRemoteSearch() && this.performRemoteSearch) {
|
if (isRemoteSearch()) {
|
||||||
handleRemoteSearchChange(searchText);
|
if (this.performRemoteSearch) {
|
||||||
|
handleRemoteSearchChange(searchText);
|
||||||
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table-next",
|
"name": "react-bootstrap-table-next",
|
||||||
"version": "1.1.4",
|
"version": "1.3.0",
|
||||||
"description": "Next generation of react-bootstrap-table",
|
"description": "Next generation of react-bootstrap-table",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
28
packages/react-bootstrap-table2/src/body.js
vendored
28
packages/react-bootstrap-table2/src/body.js
vendored
@@ -5,12 +5,12 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import _ from './utils';
|
import _ from './utils';
|
||||||
import Row from './simple-row';
|
import SimpleRow from './row/simple-row';
|
||||||
import RowAggregator from './row-aggregator';
|
import RowAggregator from './row/aggregate-row';
|
||||||
import RowSection from './row-section';
|
import RowSection from './row/row-section';
|
||||||
import Const from './const';
|
import Const from './const';
|
||||||
import bindSelection from './row-selection/row-binder';
|
import withRowSelection from './row-selection/row-consumer';
|
||||||
import bindExpansion from './row-expand/row-binder';
|
import withRowExpansion from './row-expand/row-consumer';
|
||||||
|
|
||||||
class Body extends React.Component {
|
class Body extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -18,13 +18,13 @@ class Body extends React.Component {
|
|||||||
if (props.cellEdit.createContext) {
|
if (props.cellEdit.createContext) {
|
||||||
this.EditingCell = props.cellEdit.createEditingCell(_, props.cellEdit.options.onStartEdit);
|
this.EditingCell = props.cellEdit.createEditingCell(_, props.cellEdit.options.onStartEdit);
|
||||||
}
|
}
|
||||||
this.RowComponent = bindSelection(RowAggregator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
columns,
|
columns,
|
||||||
data,
|
data,
|
||||||
|
tabIndexCell,
|
||||||
keyField,
|
keyField,
|
||||||
isEmpty,
|
isEmpty,
|
||||||
noDataIndication,
|
noDataIndication,
|
||||||
@@ -46,21 +46,21 @@ class Body extends React.Component {
|
|||||||
}
|
}
|
||||||
content = <RowSection content={ indication } colSpan={ visibleColumnSize } />;
|
content = <RowSection content={ indication } colSpan={ visibleColumnSize } />;
|
||||||
} else {
|
} else {
|
||||||
let RowComponent = Row;
|
let RowComponent = SimpleRow;
|
||||||
const selectRowEnabled = selectRow.mode !== Const.ROW_SELECT_DISABLED;
|
const selectRowEnabled = selectRow.mode !== Const.ROW_SELECT_DISABLED;
|
||||||
const expandRowEnabled = !!expandRow.renderer;
|
const expandRowEnabled = !!expandRow.renderer;
|
||||||
|
|
||||||
const additionalRowProps = {};
|
const additionalRowProps = {};
|
||||||
if (expandRowEnabled) {
|
if (expandRowEnabled) {
|
||||||
RowComponent = bindExpansion(RowAggregator, visibleColumnSize);
|
RowComponent = withRowExpansion(RowAggregator, visibleColumnSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (selectRowEnabled) {
|
if (selectRowEnabled) {
|
||||||
// RowComponent = bindSelection(expandRowEnabled ? RowComponent : RowAggregator);
|
RowComponent = withRowSelection(expandRowEnabled ? RowComponent : RowAggregator);
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (cellEdit.createContext) {
|
if (cellEdit.createContext) {
|
||||||
RowComponent = cellEdit.bindRowLevelCellEdit(RowComponent, selectRowEnabled, keyField, _);
|
RowComponent = cellEdit.withRowLevelCellEdit(RowComponent, selectRowEnabled, keyField, _);
|
||||||
additionalRowProps.EditingCellComponent = this.EditingCell;
|
additionalRowProps.EditingCellComponent = this.EditingCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,11 +74,13 @@ class Body extends React.Component {
|
|||||||
const baseRowProps = {
|
const baseRowProps = {
|
||||||
key,
|
key,
|
||||||
row,
|
row,
|
||||||
|
tabIndexCell,
|
||||||
columns,
|
columns,
|
||||||
keyField,
|
keyField,
|
||||||
cellEdit,
|
cellEdit,
|
||||||
value: key,
|
value: key,
|
||||||
rowIndex: index,
|
rowIndex: index,
|
||||||
|
visibleColumnSize,
|
||||||
attrs: rowEvents || {},
|
attrs: rowEvents || {},
|
||||||
...additionalRowProps
|
...additionalRowProps
|
||||||
};
|
};
|
||||||
@@ -86,7 +88,7 @@ class Body extends React.Component {
|
|||||||
baseRowProps.style = _.isFunction(rowStyle) ? rowStyle(row, index) : rowStyle;
|
baseRowProps.style = _.isFunction(rowStyle) ? rowStyle(row, index) : rowStyle;
|
||||||
baseRowProps.className = (_.isFunction(rowClasses) ? rowClasses(row, index) : rowClasses);
|
baseRowProps.className = (_.isFunction(rowClasses) ? rowClasses(row, index) : rowClasses);
|
||||||
|
|
||||||
return <this.RowComponent { ...baseRowProps } />;
|
return <RowComponent { ...baseRowProps } />;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
data,
|
data,
|
||||||
columns,
|
columns,
|
||||||
keyField,
|
keyField,
|
||||||
|
tabIndexCell,
|
||||||
id,
|
id,
|
||||||
classes,
|
classes,
|
||||||
striped,
|
striped,
|
||||||
@@ -89,6 +90,7 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
<Body
|
<Body
|
||||||
data={ data }
|
data={ data }
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
|
tabIndexCell={ tabIndexCell }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
isEmpty={ this.isEmpty() }
|
isEmpty={ this.isEmpty() }
|
||||||
visibleColumnSize={ this.visibleColumnSize() }
|
visibleColumnSize={ this.visibleColumnSize() }
|
||||||
@@ -118,6 +120,7 @@ BootstrapTable.propTypes = {
|
|||||||
striped: PropTypes.bool,
|
striped: PropTypes.bool,
|
||||||
bordered: PropTypes.bool,
|
bordered: PropTypes.bool,
|
||||||
hover: PropTypes.bool,
|
hover: PropTypes.bool,
|
||||||
|
tabIndexCell: PropTypes.bool,
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
classes: PropTypes.string,
|
classes: PropTypes.string,
|
||||||
wrapperClasses: PropTypes.string,
|
wrapperClasses: PropTypes.string,
|
||||||
@@ -136,7 +139,9 @@ BootstrapTable.propTypes = {
|
|||||||
Const.ROW_SELECT_DISABLED
|
Const.ROW_SELECT_DISABLED
|
||||||
]).isRequired,
|
]).isRequired,
|
||||||
clickToSelect: PropTypes.bool,
|
clickToSelect: PropTypes.bool,
|
||||||
|
clickToExpand: PropTypes.bool,
|
||||||
clickToEdit: PropTypes.bool,
|
clickToEdit: PropTypes.bool,
|
||||||
|
hideSelectAll: PropTypes.bool,
|
||||||
onSelect: PropTypes.func,
|
onSelect: PropTypes.func,
|
||||||
onSelectAll: PropTypes.func,
|
onSelectAll: PropTypes.func,
|
||||||
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||||
@@ -154,6 +159,8 @@ BootstrapTable.propTypes = {
|
|||||||
onExpandAll: PropTypes.func,
|
onExpandAll: PropTypes.func,
|
||||||
nonExpandable: PropTypes.array,
|
nonExpandable: PropTypes.array,
|
||||||
showExpandColumn: PropTypes.bool,
|
showExpandColumn: PropTypes.bool,
|
||||||
|
onlyOneExpanding: PropTypes.bool,
|
||||||
|
expandByColumnOnly: PropTypes.bool,
|
||||||
expandColumnRenderer: PropTypes.func,
|
expandColumnRenderer: PropTypes.func,
|
||||||
expandHeaderColumnRenderer: PropTypes.func
|
expandHeaderColumnRenderer: PropTypes.func
|
||||||
}),
|
}),
|
||||||
|
|||||||
8
packages/react-bootstrap-table2/src/cell.js
vendored
8
packages/react-bootstrap-table2/src/cell.js
vendored
@@ -34,7 +34,8 @@ class Cell extends Component {
|
|||||||
!_.isEqual(this.props.style, nextProps.style) ||
|
!_.isEqual(this.props.style, nextProps.style) ||
|
||||||
!_.isEqual(this.props.column.formatExtraData, nextProps.column.formatExtraData) ||
|
!_.isEqual(this.props.column.formatExtraData, nextProps.column.formatExtraData) ||
|
||||||
!_.isEqual(this.props.column.events, nextProps.column.events) ||
|
!_.isEqual(this.props.column.events, nextProps.column.events) ||
|
||||||
!_.isEqual(this.props.column.attrs, nextProps.column.attrs);
|
!_.isEqual(this.props.column.attrs, nextProps.column.attrs) ||
|
||||||
|
this.props.tabIndex !== nextProps.tabIndex;
|
||||||
return shouldUpdate;
|
return shouldUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,10 +74,7 @@ class Cell extends Component {
|
|||||||
formatExtraData
|
formatExtraData
|
||||||
} = column;
|
} = column;
|
||||||
const attrs = { ...rest };
|
const attrs = { ...rest };
|
||||||
let content = this.props.children;
|
let content = column.isDummyField ? null : _.get(row, dataField);
|
||||||
if (!content) {
|
|
||||||
content = column.isDummyField ? null : _.get(row, dataField);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (formatter) {
|
if (formatter) {
|
||||||
content = column.formatter(content, row, rowIndex, formatExtraData);
|
content = column.formatter(content, row, rowIndex, formatExtraData);
|
||||||
|
|||||||
@@ -54,6 +54,16 @@ const withContext = Base =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(nextProps) {
|
||||||
|
if (!nextProps.pagination && this.props.pagination) {
|
||||||
|
this.PaginationContext = null;
|
||||||
|
}
|
||||||
|
if (nextProps.pagination && !this.props.pagination) {
|
||||||
|
this.PaginationContext = nextProps.pagination.createContext(
|
||||||
|
this.isRemotePagination, this.handleRemotePageChange);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderBase() {
|
renderBase() {
|
||||||
return (
|
return (
|
||||||
rootProps,
|
rootProps,
|
||||||
@@ -63,6 +73,7 @@ const withContext = Base =>
|
|||||||
paginationProps,
|
paginationProps,
|
||||||
) => (
|
) => (
|
||||||
<Base
|
<Base
|
||||||
|
ref={ n => this.table = n }
|
||||||
{ ...this.props }
|
{ ...this.props }
|
||||||
{ ...sortProps }
|
{ ...sortProps }
|
||||||
{ ...filterProps }
|
{ ...filterProps }
|
||||||
@@ -83,6 +94,7 @@ const withContext = Base =>
|
|||||||
) => (
|
) => (
|
||||||
<this.SelectionContext.Provider
|
<this.SelectionContext.Provider
|
||||||
{ ...baseProps }
|
{ ...baseProps }
|
||||||
|
ref={ n => this.selectionContext = n }
|
||||||
selectRow={ this.props.selectRow }
|
selectRow={ this.props.selectRow }
|
||||||
data={ rootProps.getData(filterProps, searchProps, sortProps, paginationProps) }
|
data={ rootProps.getData(filterProps, searchProps, sortProps, paginationProps) }
|
||||||
>
|
>
|
||||||
@@ -109,6 +121,7 @@ const withContext = Base =>
|
|||||||
) => (
|
) => (
|
||||||
<this.RowExpandContext.Provider
|
<this.RowExpandContext.Provider
|
||||||
{ ...baseProps }
|
{ ...baseProps }
|
||||||
|
ref={ n => this.rowExpandContext = n }
|
||||||
expandRow={ this.props.expandRow }
|
expandRow={ this.props.expandRow }
|
||||||
data={ rootProps.getData(filterProps, searchProps, sortProps, paginationProps) }
|
data={ rootProps.getData(filterProps, searchProps, sortProps, paginationProps) }
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -23,12 +23,13 @@ class RowExpandProvider extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleRowExpand = (rowKey, expanded, rowIndex, e) => {
|
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];
|
let currExpanded = [...this.state.expanded];
|
||||||
|
|
||||||
if (expanded) {
|
if (expanded) {
|
||||||
currExpanded.push(rowKey);
|
if (onlyOneExpanding) currExpanded = [rowKey];
|
||||||
|
else currExpanded.push(rowKey);
|
||||||
} else {
|
} else {
|
||||||
currExpanded = currExpanded.filter(value => value !== rowKey);
|
currExpanded = currExpanded.filter(value => value !== rowKey);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class SelectionProvider extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state = { selected: (this.props.selectRow && this.props.selectRow.selected) || [] };
|
state = { selected: this.props.selectRow.selected || [] };
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.selectRow) {
|
if (nextProps.selectRow) {
|
||||||
@@ -79,7 +79,15 @@ class SelectionProvider extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (onSelectAll) {
|
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 }));
|
this.setState(() => ({ selected: currSelected }));
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ const HeaderCell = (props) => {
|
|||||||
const {
|
const {
|
||||||
text,
|
text,
|
||||||
sort,
|
sort,
|
||||||
|
sortCaret,
|
||||||
filter,
|
filter,
|
||||||
filterRenderer,
|
filterRenderer,
|
||||||
headerTitle,
|
headerTitle,
|
||||||
@@ -49,6 +50,7 @@ const HeaderCell = (props) => {
|
|||||||
|
|
||||||
if (headerStyle) {
|
if (headerStyle) {
|
||||||
cellStyle = _.isFunction(headerStyle) ? headerStyle(column, index) : headerStyle;
|
cellStyle = _.isFunction(headerStyle) ? headerStyle(column, index) : headerStyle;
|
||||||
|
cellStyle = cellStyle ? { ...cellStyle } : cellStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headerTitle) {
|
if (headerTitle) {
|
||||||
@@ -68,7 +70,7 @@ const HeaderCell = (props) => {
|
|||||||
cellAttrs.className = cs(cellAttrs.className, 'sortable');
|
cellAttrs.className = cs(cellAttrs.className, 'sortable');
|
||||||
|
|
||||||
if (sorting) {
|
if (sorting) {
|
||||||
sortSymbol = <SortCaret order={ sortOrder } />;
|
sortSymbol = sortCaret ? sortCaret(sortOrder, column) : <SortCaret order={ sortOrder } />;
|
||||||
|
|
||||||
// append customized classes or style if table was sorting based on the current column.
|
// append customized classes or style if table was sorting based on the current column.
|
||||||
cellClasses = cs(
|
cellClasses = cs(
|
||||||
@@ -85,7 +87,7 @@ const HeaderCell = (props) => {
|
|||||||
: headerSortingStyle
|
: headerSortingStyle
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
sortSymbol = <SortSymbol />;
|
sortSymbol = sortCaret ? sortCaret(undefined, column) : <SortSymbol />;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +152,7 @@ HeaderCell.propTypes = {
|
|||||||
onSort: PropTypes.func,
|
onSort: PropTypes.func,
|
||||||
sorting: PropTypes.bool,
|
sorting: PropTypes.bool,
|
||||||
sortOrder: PropTypes.oneOf([Const.SORT_ASC, Const.SORT_DESC]),
|
sortOrder: PropTypes.oneOf([Const.SORT_ASC, Const.SORT_DESC]),
|
||||||
|
sortCaret: PropTypes.func,
|
||||||
isLastSorting: PropTypes.bool,
|
isLastSorting: PropTypes.bool,
|
||||||
onFilter: PropTypes.func,
|
onFilter: PropTypes.func,
|
||||||
onExternalFilter: PropTypes.func
|
onExternalFilter: PropTypes.func
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import PropTypes from 'prop-types';
|
|||||||
import HeaderCell from './header-cell';
|
import HeaderCell from './header-cell';
|
||||||
import SelectionHeaderCell from './row-selection/selection-header-cell';
|
import SelectionHeaderCell from './row-selection/selection-header-cell';
|
||||||
import ExpandHeaderCell from './row-expand/expand-header-cell';
|
import ExpandHeaderCell from './row-expand/expand-header-cell';
|
||||||
import bindSelection from './row-selection/selection-header-cell-binder';
|
import withHeaderSelection from './row-selection/selection-header-cell-consumer';
|
||||||
import bindExpansion from './row-expand/expand-header-cell-binder';
|
import withHeaderExpansion from './row-expand/expand-header-cell-consumer';
|
||||||
|
|
||||||
const Header = (props) => {
|
const Header = (props) => {
|
||||||
const {
|
const {
|
||||||
@@ -26,11 +26,11 @@ const Header = (props) => {
|
|||||||
let ExpansionHeaderCellComp = () => null;
|
let ExpansionHeaderCellComp = () => null;
|
||||||
|
|
||||||
if (expandRow.showExpandColumn) {
|
if (expandRow.showExpandColumn) {
|
||||||
ExpansionHeaderCellComp = bindExpansion(ExpandHeaderCell);
|
ExpansionHeaderCellComp = withHeaderExpansion(ExpandHeaderCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectRow) {
|
if (selectRow) {
|
||||||
SelectionHeaderCellComp = bindSelection(SelectionHeaderCell);
|
SelectionHeaderCellComp = withHeaderSelection(SelectionHeaderCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
/* eslint react/prop-types: 0 */
|
|
||||||
/* eslint react/no-array-index-key: 0 */
|
|
||||||
import React, { Component } from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
|
|
||||||
// import eventDelegater from './row-event-delegater';
|
|
||||||
import RowContent from './row-pure-content';
|
|
||||||
// import shouldRowUpdater from './row-should-updater';
|
|
||||||
|
|
||||||
/* eslint react/prefer-stateless-function: 0 */
|
|
||||||
class RowAggregatorContent extends Component {
|
|
||||||
render() {
|
|
||||||
const {
|
|
||||||
className,
|
|
||||||
style,
|
|
||||||
attrs,
|
|
||||||
shouldUpdateRowContent,
|
|
||||||
...rest
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<tr style={ style } className={ className } { ...attrs }>
|
|
||||||
{ this.props.children }
|
|
||||||
<RowContent shouldUpdate={ shouldUpdateRowContent } { ...rest } />
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RowAggregatorContent.propTypes = {
|
|
||||||
row: PropTypes.object.isRequired,
|
|
||||||
rowIndex: PropTypes.number.isRequired,
|
|
||||||
columns: PropTypes.array.isRequired,
|
|
||||||
style: PropTypes.object,
|
|
||||||
className: PropTypes.string,
|
|
||||||
attrs: PropTypes.object,
|
|
||||||
shouldUpdateRowContent: PropTypes.bool
|
|
||||||
};
|
|
||||||
|
|
||||||
RowAggregatorContent.defaultProps = {
|
|
||||||
editable: true,
|
|
||||||
style: {},
|
|
||||||
className: null,
|
|
||||||
attrs: {},
|
|
||||||
shouldUpdateRowContent: true
|
|
||||||
};
|
|
||||||
|
|
||||||
export default RowAggregatorContent;
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
/* eslint react/prop-types: 0 */
|
|
||||||
/* eslint react/no-array-index-key: 0 */
|
|
||||||
import React from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import _ from './utils';
|
|
||||||
import RowContent from './row-pure-content';
|
|
||||||
// import RowAggregatorContent from './row-aggregator-content';
|
|
||||||
import shouldRowUpdater from './row-should-updater';
|
|
||||||
import ExpandCell from './row-expand/expand-cell';
|
|
||||||
import SelectionCell from './row-selection/selection-cell';
|
|
||||||
// import Cell from './cell';
|
|
||||||
import eventDelegater from './row-event-delegater';
|
|
||||||
|
|
||||||
export default class RowAggregator extends shouldRowUpdater(eventDelegater(React.Component)) {
|
|
||||||
static propTypes = {
|
|
||||||
attrs: PropTypes.object,
|
|
||||||
style: PropTypes.object
|
|
||||||
}
|
|
||||||
static defaultProps = {
|
|
||||||
attrs: {},
|
|
||||||
style: {}
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.clickNum = 0;
|
|
||||||
this.shouldUpdateRowContent = false;
|
|
||||||
this.createClickEventHandler = this.createClickEventHandler.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps) {
|
|
||||||
if (
|
|
||||||
this.props.selected !== nextProps.selected ||
|
|
||||||
this.props.expanded !== nextProps.expanded ||
|
|
||||||
this.props.selectable !== nextProps.selectable ||
|
|
||||||
this.shouldUpdateByWhenEditing(nextProps) ||
|
|
||||||
this.shouldUpdatedBySelfProps(nextProps)
|
|
||||||
) {
|
|
||||||
this.shouldUpdateRowContent = this.shouldUpdatedByNormalProps(nextProps);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
this.shouldUpdateRowContent = this.shouldUpdatedByNormalProps(nextProps);
|
|
||||||
|
|
||||||
return this.shouldUpdateRowContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
createClickEventHandler(cb) {
|
|
||||||
return (e) => {
|
|
||||||
const {
|
|
||||||
row,
|
|
||||||
selected,
|
|
||||||
keyField,
|
|
||||||
selectable,
|
|
||||||
expandable,
|
|
||||||
rowIndex,
|
|
||||||
expanded,
|
|
||||||
expandRow,
|
|
||||||
selectRow,
|
|
||||||
DELAY_FOR_DBCLICK
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
const clickFn = () => {
|
|
||||||
if (cb) {
|
|
||||||
cb(e, row, rowIndex);
|
|
||||||
}
|
|
||||||
const key = _.get(row, keyField);
|
|
||||||
if (expandRow && expandable) {
|
|
||||||
expandRow.onRowExpand(key, !expanded, rowIndex, e);
|
|
||||||
}
|
|
||||||
if (selectRow.clickToSelect && selectable) {
|
|
||||||
selectRow.onRowSelect(key, !selected, rowIndex, e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (DELAY_FOR_DBCLICK) {
|
|
||||||
this.clickNum += 1;
|
|
||||||
_.debounce(() => {
|
|
||||||
if (this.clickNum === 1) {
|
|
||||||
clickFn();
|
|
||||||
}
|
|
||||||
this.clickNum = 0;
|
|
||||||
}, DELAY_FOR_DBCLICK)();
|
|
||||||
} else {
|
|
||||||
clickFn();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const {
|
|
||||||
row,
|
|
||||||
columns,
|
|
||||||
keyField,
|
|
||||||
rowIndex,
|
|
||||||
style,
|
|
||||||
className,
|
|
||||||
attrs,
|
|
||||||
selectRow,
|
|
||||||
expandRow,
|
|
||||||
expanded,
|
|
||||||
selected,
|
|
||||||
selectable,
|
|
||||||
...rest
|
|
||||||
} = this.props;
|
|
||||||
const key = _.get(row, keyField);
|
|
||||||
const { hideSelectColumn, clickToSelect } = selectRow;
|
|
||||||
const { showExpandColumn } = expandRow;
|
|
||||||
|
|
||||||
const newAttrs = this.delegate({ ...attrs });
|
|
||||||
if (clickToSelect || !!expandRow.renderer) {
|
|
||||||
newAttrs.onClick = this.createClickEventHandler(newAttrs.onClick);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<tr
|
|
||||||
style={ style }
|
|
||||||
className={ className }
|
|
||||||
{ ...newAttrs }
|
|
||||||
>
|
|
||||||
<td>123</td>
|
|
||||||
<td>12121212</td>
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
// const content0 = _.get(row, columns[1].dataField);
|
|
||||||
// const content1 = _.get(row, columns[1].dataField);
|
|
||||||
// const content2 = _.get(row, columns[2].dataField);
|
|
||||||
// return (
|
|
||||||
// <tr
|
|
||||||
// style={ style }
|
|
||||||
// className={ className }
|
|
||||||
// onClick={ e => selectRow.onRowSelect(key, !selected, rowIndex, e) }
|
|
||||||
// >
|
|
||||||
// <td>1</td>
|
|
||||||
// <td>2</td>
|
|
||||||
// <td>3</td>
|
|
||||||
// <td>4</td>
|
|
||||||
// </tr>
|
|
||||||
// );
|
|
||||||
|
|
||||||
// const newCols = [{ fake: true }, ...columns];
|
|
||||||
|
|
||||||
// return (
|
|
||||||
// <tr
|
|
||||||
// style={ style }
|
|
||||||
// className={ className }
|
|
||||||
// { ...newAttrs }
|
|
||||||
// >
|
|
||||||
// {
|
|
||||||
// newCols.map((column, i) => {
|
|
||||||
// if (column.fake) {
|
|
||||||
// return (
|
|
||||||
// <Cell
|
|
||||||
// key={ `${key}_${i}_sel}` }
|
|
||||||
// column={ {} }
|
|
||||||
// row={ {} }
|
|
||||||
// rowIndex={ rowIndex }
|
|
||||||
// columnIndex={ i }
|
|
||||||
// >
|
|
||||||
// <input type="checkbox" />
|
|
||||||
// </Cell>
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// const content = _.get(row, column.dataField);
|
|
||||||
// return (
|
|
||||||
// <Cell
|
|
||||||
// key={ `${key}_${content}}` }
|
|
||||||
// row={ row }
|
|
||||||
// rowIndex={ rowIndex }
|
|
||||||
// column={ column }
|
|
||||||
// columnIndex={ i }
|
|
||||||
// />
|
|
||||||
// );
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// </tr>
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,8 @@ const events = [
|
|||||||
'onClick',
|
'onClick',
|
||||||
'onDoubleClick',
|
'onDoubleClick',
|
||||||
'onMouseEnter',
|
'onMouseEnter',
|
||||||
'onMouseLeave'
|
'onMouseLeave',
|
||||||
|
'onContextMenu'
|
||||||
];
|
];
|
||||||
|
|
||||||
export default ExtendBase =>
|
export default ExtendBase =>
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ export default class ExpandCell extends Component {
|
|||||||
expanded: PropTypes.bool.isRequired,
|
expanded: PropTypes.bool.isRequired,
|
||||||
onRowExpand: PropTypes.func.isRequired,
|
onRowExpand: PropTypes.func.isRequired,
|
||||||
expandColumnRenderer: PropTypes.func,
|
expandColumnRenderer: PropTypes.func,
|
||||||
rowIndex: PropTypes.number
|
rowIndex: PropTypes.number,
|
||||||
|
tabIndex: PropTypes.number
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -20,17 +21,29 @@ export default class ExpandCell extends Component {
|
|||||||
this.handleClick = this.handleClick.bind(this);
|
this.handleClick = this.handleClick.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldComponentUpdate(nextProps) {
|
||||||
|
const shouldUpdate =
|
||||||
|
this.props.rowIndex !== nextProps.rowIndex ||
|
||||||
|
this.props.expanded !== nextProps.expanded ||
|
||||||
|
this.props.rowKey !== nextProps.rowKey ||
|
||||||
|
this.props.tabIndex !== nextProps.tabIndex;
|
||||||
|
|
||||||
|
return shouldUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
handleClick(e) {
|
handleClick(e) {
|
||||||
const { rowKey, expanded, onRowExpand, rowIndex } = this.props;
|
const { rowKey, expanded, onRowExpand, rowIndex } = this.props;
|
||||||
|
|
||||||
onRowExpand(rowKey, expanded, rowIndex, e);
|
onRowExpand(rowKey, !expanded, rowIndex, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { expanded, expandColumnRenderer } = this.props;
|
const { expanded, expandColumnRenderer, tabIndex } = this.props;
|
||||||
|
const attrs = {};
|
||||||
|
if (tabIndex !== -1) attrs.tabIndex = tabIndex;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<td onClick={ this.handleClick }>
|
<td onClick={ this.handleClick } { ...attrs }>
|
||||||
{
|
{
|
||||||
expandColumnRenderer ? expandColumnRenderer({
|
expandColumnRenderer ? expandColumnRenderer({
|
||||||
expanded
|
expanded
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ export default (Component) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
function withSelectionConsumer(props) {
|
|
||||||
|
function withConsumer(props) {
|
||||||
return (
|
return (
|
||||||
<SelectionContext.Consumer>
|
<SelectionContext.Consumer>
|
||||||
{ selectRow => renderWithSelection(props, selectRow) }
|
{ selectRow => renderWithSelection(props, selectRow) }
|
||||||
@@ -57,6 +58,6 @@ export default (Component) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
withSelectionConsumer.displayName = 'WithSelectionConsumer';
|
withConsumer.displayName = 'WithSelectionRowConsumer';
|
||||||
return withSelectionConsumer;
|
return withConsumer;
|
||||||
};
|
};
|
||||||
@@ -15,21 +15,23 @@ export default class SelectionCell extends Component {
|
|||||||
onRowSelect: PropTypes.func,
|
onRowSelect: PropTypes.func,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
rowIndex: PropTypes.number,
|
rowIndex: PropTypes.number,
|
||||||
|
tabIndex: PropTypes.number,
|
||||||
clickToSelect: PropTypes.bool,
|
clickToSelect: PropTypes.bool,
|
||||||
selectionRenderer: PropTypes.func
|
selectionRenderer: PropTypes.func
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor() {
|
||||||
super(props);
|
super();
|
||||||
this.handleClick = this.handleClick.bind(this);
|
this.handleClick = this.handleClick.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps) {
|
shouldComponentUpdate(nextProps) {
|
||||||
const shouldUpdate =
|
const shouldUpdate =
|
||||||
this.props.selected !== nextProps.selected ||
|
|
||||||
this.props.rowKey !== nextProps.rowKey ||
|
|
||||||
this.props.rowIndex !== nextProps.rowIndex ||
|
this.props.rowIndex !== nextProps.rowIndex ||
|
||||||
this.props.disabled !== nextProps.disabled;
|
this.props.selected !== nextProps.selected ||
|
||||||
|
this.props.disabled !== nextProps.disabled ||
|
||||||
|
this.props.rowKey !== nextProps.rowKey ||
|
||||||
|
this.props.tabIndex !== nextProps.tabIndex;
|
||||||
|
|
||||||
return shouldUpdate;
|
return shouldUpdate;
|
||||||
}
|
}
|
||||||
@@ -60,14 +62,18 @@ export default class SelectionCell extends Component {
|
|||||||
mode: inputType,
|
mode: inputType,
|
||||||
selected,
|
selected,
|
||||||
disabled,
|
disabled,
|
||||||
|
tabIndex,
|
||||||
selectionRenderer
|
selectionRenderer
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
const attrs = {};
|
||||||
|
if (tabIndex !== -1) attrs.tabIndex = tabIndex;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BootstrapContext.Consumer>
|
<BootstrapContext.Consumer>
|
||||||
{
|
{
|
||||||
({ bootstrap4 }) => (
|
({ bootstrap4 }) => (
|
||||||
<td onClick={ this.handleClick }>
|
<td onClick={ this.handleClick } { ...attrs }>
|
||||||
{
|
{
|
||||||
selectionRenderer ? selectionRenderer({
|
selectionRenderer ? selectionRenderer({
|
||||||
mode: inputType,
|
mode: inputType,
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export default class SelectionHeaderCell extends Component {
|
|||||||
mode: PropTypes.string.isRequired,
|
mode: PropTypes.string.isRequired,
|
||||||
checkedStatus: PropTypes.string,
|
checkedStatus: PropTypes.string,
|
||||||
onAllRowsSelect: PropTypes.func,
|
onAllRowsSelect: PropTypes.func,
|
||||||
|
hideSelectAll: PropTypes.bool,
|
||||||
selectionHeaderRenderer: PropTypes.func
|
selectionHeaderRenderer: PropTypes.func
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +64,10 @@ 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 } = this.props;
|
const { mode, checkedStatus, selectionHeaderRenderer, hideSelectAll } = this.props;
|
||||||
|
if (hideSelectAll) {
|
||||||
|
return <th data-row-selection />;
|
||||||
|
}
|
||||||
|
|
||||||
const checked = checkedStatus === CHECKBOX_STATUS_CHECKED;
|
const checked = checkedStatus === CHECKBOX_STATUS_CHECKED;
|
||||||
|
|
||||||
|
|||||||
117
packages/react-bootstrap-table2/src/row/aggregate-row.js
vendored
Normal file
117
packages/react-bootstrap-table2/src/row/aggregate-row.js
vendored
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
/* eslint no-plusplus: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import _ from '../utils';
|
||||||
|
import ExpandCell from '../row-expand/expand-cell';
|
||||||
|
import SelectionCell from '../row-selection/selection-cell';
|
||||||
|
import shouldUpdater from './should-updater';
|
||||||
|
import eventDelegater from './event-delegater';
|
||||||
|
import RowPureContent from './row-pure-content';
|
||||||
|
|
||||||
|
export default class RowAggregator extends shouldUpdater(eventDelegater(React.Component)) {
|
||||||
|
static propTypes = {
|
||||||
|
attrs: PropTypes.object,
|
||||||
|
style: PropTypes.object
|
||||||
|
}
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
attrs: {},
|
||||||
|
style: {}
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.clickNum = 0;
|
||||||
|
this.shouldUpdateRowContent = false;
|
||||||
|
this.createClickEventHandler = this.createClickEventHandler.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldComponentUpdate(nextProps) {
|
||||||
|
if (
|
||||||
|
this.props.selected !== nextProps.selected ||
|
||||||
|
this.props.expanded !== nextProps.expanded ||
|
||||||
|
this.props.selectable !== nextProps.selectable ||
|
||||||
|
this.shouldUpdatedBySelfProps(nextProps)
|
||||||
|
) {
|
||||||
|
this.shouldUpdateRowContent = this.shouldUpdateChild(nextProps);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this.shouldUpdateRowContent = this.shouldUpdateChild(nextProps);
|
||||||
|
|
||||||
|
return this.shouldUpdateRowContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
row,
|
||||||
|
columns,
|
||||||
|
keyField,
|
||||||
|
rowIndex,
|
||||||
|
style,
|
||||||
|
className,
|
||||||
|
attrs,
|
||||||
|
selectRow,
|
||||||
|
expandRow,
|
||||||
|
expanded,
|
||||||
|
selected,
|
||||||
|
selectable,
|
||||||
|
visibleColumnSize,
|
||||||
|
tabIndexCell,
|
||||||
|
...rest
|
||||||
|
} = this.props;
|
||||||
|
const key = _.get(row, keyField);
|
||||||
|
const { hideSelectColumn, clickToSelect } = selectRow;
|
||||||
|
const { showExpandColumn } = expandRow;
|
||||||
|
|
||||||
|
const newAttrs = this.delegate({ ...attrs });
|
||||||
|
if (clickToSelect || !!expandRow.renderer) {
|
||||||
|
newAttrs.onClick = this.createClickEventHandler(newAttrs.onClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
let tabIndexStart = (rowIndex * visibleColumnSize) + 1;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<tr
|
||||||
|
style={ style }
|
||||||
|
className={ className }
|
||||||
|
{ ...newAttrs }
|
||||||
|
>
|
||||||
|
{
|
||||||
|
showExpandColumn ? (
|
||||||
|
<ExpandCell
|
||||||
|
{ ...expandRow }
|
||||||
|
rowKey={ key }
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
expanded={ expanded }
|
||||||
|
tabIndex={ tabIndexCell ? tabIndexStart++ : -1 }
|
||||||
|
/>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
|
{
|
||||||
|
!hideSelectColumn
|
||||||
|
? (
|
||||||
|
<SelectionCell
|
||||||
|
{ ...selectRow }
|
||||||
|
rowKey={ key }
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
selected={ selected }
|
||||||
|
disabled={ !selectable }
|
||||||
|
tabIndex={ tabIndexCell ? tabIndexStart++ : -1 }
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
<RowPureContent
|
||||||
|
row={ row }
|
||||||
|
columns={ columns }
|
||||||
|
keyField={ keyField }
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
shouldUpdate={ this.shouldUpdateRowContent }
|
||||||
|
tabIndexStart={ tabIndexCell ? tabIndexStart : -1 }
|
||||||
|
{ ...rest }
|
||||||
|
/>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
83
packages/react-bootstrap-table2/src/row/event-delegater.js
vendored
Normal file
83
packages/react-bootstrap-table2/src/row/event-delegater.js
vendored
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import _ from '../utils';
|
||||||
|
import Const from '../const';
|
||||||
|
|
||||||
|
const events = [
|
||||||
|
'onClick',
|
||||||
|
'onDoubleClick',
|
||||||
|
'onMouseEnter',
|
||||||
|
'onMouseLeave',
|
||||||
|
'onContextMenu'
|
||||||
|
];
|
||||||
|
|
||||||
|
export default ExtendBase =>
|
||||||
|
class RowEventDelegater extends ExtendBase {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.clickNum = 0;
|
||||||
|
this.createDefaultEventHandler = this.createDefaultEventHandler.bind(this);
|
||||||
|
this.createClickEventHandler = this.createClickEventHandler.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
createClickEventHandler(cb) {
|
||||||
|
return (e) => {
|
||||||
|
const {
|
||||||
|
row,
|
||||||
|
selected,
|
||||||
|
keyField,
|
||||||
|
selectable,
|
||||||
|
expandable,
|
||||||
|
rowIndex,
|
||||||
|
expanded,
|
||||||
|
expandRow,
|
||||||
|
selectRow,
|
||||||
|
DELAY_FOR_DBCLICK
|
||||||
|
} = this.props;
|
||||||
|
const clickFn = () => {
|
||||||
|
if (cb) {
|
||||||
|
cb(e, row, rowIndex);
|
||||||
|
}
|
||||||
|
const key = _.get(row, keyField);
|
||||||
|
if (expandRow && expandable && !expandRow.expandByColumnOnly) {
|
||||||
|
if (
|
||||||
|
(selectRow.mode !== Const.ROW_SELECT_DISABLED && selectRow.clickToExpand) ||
|
||||||
|
selectRow.mode === Const.ROW_SELECT_DISABLED
|
||||||
|
) {
|
||||||
|
expandRow.onRowExpand(key, !expanded, rowIndex, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (selectRow.clickToSelect && selectable) {
|
||||||
|
selectRow.onRowSelect(key, !selected, rowIndex, e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (DELAY_FOR_DBCLICK) {
|
||||||
|
this.clickNum += 1;
|
||||||
|
_.debounce(() => {
|
||||||
|
if (this.clickNum === 1) {
|
||||||
|
clickFn();
|
||||||
|
}
|
||||||
|
this.clickNum = 0;
|
||||||
|
}, DELAY_FOR_DBCLICK)();
|
||||||
|
} else {
|
||||||
|
clickFn();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
createDefaultEventHandler(cb) {
|
||||||
|
return (e) => {
|
||||||
|
const { row, rowIndex } = this.props;
|
||||||
|
cb(e, row, rowIndex);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
delegate(attrs = {}) {
|
||||||
|
const newAttrs = { ...attrs };
|
||||||
|
Object.keys(attrs).forEach((attr) => {
|
||||||
|
if (events.includes(attr)) {
|
||||||
|
newAttrs[attr] = this.createDefaultEventHandler(attrs[attr]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return newAttrs;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,19 +1,15 @@
|
|||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
/* eslint react/no-array-index-key: 0 */
|
/* eslint react/no-array-index-key: 0 */
|
||||||
|
/* eslint no-plusplus: 0 */
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import _ from './utils';
|
import _ from '../utils';
|
||||||
import Cell from './cell';
|
import Cell from '../cell';
|
||||||
|
|
||||||
export default class RowContent extends React.Component {
|
export default class RowPureContent extends React.Component {
|
||||||
// shouldComponentUpdate(nextProps) {
|
|
||||||
// return this.shouldUpdatedByNormalProps(nextProps);
|
|
||||||
// }
|
|
||||||
shouldComponentUpdate(nextProps) {
|
shouldComponentUpdate(nextProps) {
|
||||||
if (typeof this.props.shouldUpdate !== 'undefined') {
|
if (typeof nextProps.shouldUpdate !== 'undefined') {
|
||||||
if (nextProps.shouldUpdate === this.props.shouldUpdate) {
|
return nextProps.shouldUpdate;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -30,9 +26,12 @@ export default class RowContent extends React.Component {
|
|||||||
onStart,
|
onStart,
|
||||||
clickToEdit,
|
clickToEdit,
|
||||||
dbclickToEdit,
|
dbclickToEdit,
|
||||||
EditingCellComponent
|
EditingCellComponent,
|
||||||
|
tabIndexStart
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
let tabIndex = tabIndexStart;
|
||||||
|
|
||||||
return columns.map((column, index) => {
|
return columns.map((column, index) => {
|
||||||
if (!column.hidden) {
|
if (!column.hidden) {
|
||||||
const { dataField } = column;
|
const { dataField } = column;
|
||||||
@@ -92,6 +91,10 @@ export default class RowContent extends React.Component {
|
|||||||
editableCell = column.editable(content, row, rowIndex, index);
|
editableCell = column.editable(content, row, rowIndex, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tabIndexStart !== -1) {
|
||||||
|
cellAttrs.tabIndex = tabIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Cell
|
<Cell
|
||||||
key={ `${content}-${index}` }
|
key={ `${content}-${index}` }
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
/* eslint react/prop-types: 0 */
|
/* eslint react/prop-types: 0 */
|
||||||
import _ from './utils';
|
import _ from '../utils';
|
||||||
|
|
||||||
export default ExtendBase =>
|
export default ExtendBase =>
|
||||||
class RowShouldUpdater extends ExtendBase {
|
class RowShouldUpdater extends ExtendBase {
|
||||||
shouldUpdateByWhenEditing(nextProps) {
|
shouldUpdateByCellEditing(nextProps) {
|
||||||
|
if (!(this.props.clickToEdit || this.props.dbclickToEdit)) return false;
|
||||||
return (
|
return (
|
||||||
nextProps.editingRowIdx === nextProps.rowIndex ||
|
nextProps.editingRowIdx === nextProps.rowIndex ||
|
||||||
(this.props.editingRowIdx === nextProps.rowIndex &&
|
(this.props.editingRowIdx === nextProps.rowIndex &&
|
||||||
@@ -23,9 +24,14 @@ export default ExtendBase =>
|
|||||||
const shouldUpdate =
|
const shouldUpdate =
|
||||||
this.props.rowIndex !== nextProps.rowIndex ||
|
this.props.rowIndex !== nextProps.rowIndex ||
|
||||||
this.props.editable !== nextProps.editable ||
|
this.props.editable !== nextProps.editable ||
|
||||||
this.props.columns.length !== nextProps.columns.length ||
|
!_.isEqual(this.props.row, nextProps.row) ||
|
||||||
!_.isEqual(this.props.row, nextProps.row);
|
this.props.columns.length !== nextProps.columns.length;
|
||||||
|
|
||||||
return shouldUpdate;
|
return shouldUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldUpdateChild(nextProps) {
|
||||||
|
return this.shouldUpdateByCellEditing(nextProps) ||
|
||||||
|
this.shouldUpdatedByNormalProps(nextProps);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@@ -3,18 +3,19 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import eventDelegater from './row-event-delegater';
|
import RowPureContent from './row-pure-content';
|
||||||
import RowContent from './row-pure-content';
|
import eventDelegater from './event-delegater';
|
||||||
import shouldRowUpdater from './row-should-updater';
|
import shouldUpdater from './should-updater';
|
||||||
|
|
||||||
class Row extends shouldRowUpdater(eventDelegater(Component)) {
|
class SimpleRow extends shouldUpdater(eventDelegater(Component)) {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.shouldUpdateRowContent = false;
|
this.shouldUpdateRowContent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps) {
|
shouldComponentUpdate(nextProps) {
|
||||||
this.shouldUpdateRowContent = this.shouldUpdatedByNormalProps(nextProps);
|
this.shouldUpdateRowContent = false;
|
||||||
|
this.shouldUpdateRowContent = this.shouldUpdateChild(nextProps);
|
||||||
if (this.shouldUpdateRowContent) return true;
|
if (this.shouldUpdateRowContent) return true;
|
||||||
|
|
||||||
return this.shouldUpdatedBySelfProps(nextProps);
|
return this.shouldUpdatedBySelfProps(nextProps);
|
||||||
@@ -25,19 +26,26 @@ class Row extends shouldRowUpdater(eventDelegater(Component)) {
|
|||||||
className,
|
className,
|
||||||
style,
|
style,
|
||||||
attrs,
|
attrs,
|
||||||
|
visibleColumnSize,
|
||||||
|
tabIndexCell,
|
||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const trAttrs = this.delegate(attrs);
|
const trAttrs = this.delegate(attrs);
|
||||||
|
const tabIndexStart = (this.props.rowIndex * visibleColumnSize) + 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr style={ style } className={ className } { ...trAttrs }>
|
<tr style={ style } className={ className } { ...trAttrs }>
|
||||||
<RowContent shouldUpdate={ this.shouldUpdateRowContent } { ...rest } />
|
<RowPureContent
|
||||||
|
shouldUpdate={ this.shouldUpdateRowContent }
|
||||||
|
tabIndexStart={ tabIndexCell ? tabIndexStart : -1 }
|
||||||
|
{ ...rest }
|
||||||
|
/>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Row.propTypes = {
|
SimpleRow.propTypes = {
|
||||||
row: PropTypes.object.isRequired,
|
row: PropTypes.object.isRequired,
|
||||||
rowIndex: PropTypes.number.isRequired,
|
rowIndex: PropTypes.number.isRequired,
|
||||||
columns: PropTypes.array.isRequired,
|
columns: PropTypes.array.isRequired,
|
||||||
@@ -46,11 +54,11 @@ Row.propTypes = {
|
|||||||
attrs: PropTypes.object
|
attrs: PropTypes.object
|
||||||
};
|
};
|
||||||
|
|
||||||
Row.defaultProps = {
|
SimpleRow.defaultProps = {
|
||||||
editable: true,
|
editable: true,
|
||||||
style: {},
|
style: {},
|
||||||
className: null,
|
className: null,
|
||||||
attrs: {}
|
attrs: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Row;
|
export default SimpleRow;
|
||||||
@@ -6,7 +6,7 @@ export const getSelectionSummary = (
|
|||||||
keyField,
|
keyField,
|
||||||
selected = []
|
selected = []
|
||||||
) => {
|
) => {
|
||||||
let allRowsSelected = true;
|
let allRowsSelected = data.length > 0;
|
||||||
let allRowsNotSelected = true;
|
let allRowsNotSelected = true;
|
||||||
|
|
||||||
const rowKeys = data.map(d => d[keyField]);
|
const rowKeys = data.map(d => d[keyField]);
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import sinon from 'sinon';
|
|||||||
import { shallow, mount } from 'enzyme';
|
import { shallow, mount } from 'enzyme';
|
||||||
|
|
||||||
import Body from '../src/body';
|
import Body from '../src/body';
|
||||||
import Row from '../src/row';
|
import Row from '../src/row/simple-row';
|
||||||
import RowAggregator from '../src/row-aggregator';
|
import RowAggregator from '../src/row/aggregate-row';
|
||||||
import Const from '../src/const';
|
import Const from '../src/const';
|
||||||
import RowSection from '../src/row-section';
|
import RowSection from '../src/row/row-section';
|
||||||
import SelectionContext from '../src/contexts/selection-context';
|
import SelectionContext from '../src/contexts/selection-context';
|
||||||
import ExpansionContext from '../src/contexts/row-expand-context';
|
import ExpansionContext from '../src/contexts/row-expand-context';
|
||||||
import mockBodyResolvedProps from './test-helpers/mock/body-resolved-props';
|
import mockBodyResolvedProps from './test-helpers/mock/body-resolved-props';
|
||||||
@@ -255,14 +255,13 @@ describe('Body', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when cellEdit.createContext props is defined', () => {
|
describe('when cellEdit.createContext props is defined', () => {
|
||||||
const CellComponent = () => null;
|
|
||||||
const EditingCellComponent = () => null;
|
const EditingCellComponent = () => null;
|
||||||
const RowComponent = props => <Row { ...props } />;
|
const RowComponent = props => <Row { ...props } />;
|
||||||
const cellEdit = {
|
const cellEdit = {
|
||||||
|
options: { onStartEdit: jest.fn() },
|
||||||
createContext: jest.fn(),
|
createContext: jest.fn(),
|
||||||
bindCellLevelCellEdit: jest.fn().mockReturnValue(CellComponent),
|
|
||||||
createEditingCell: jest.fn().mockReturnValue(EditingCellComponent),
|
createEditingCell: jest.fn().mockReturnValue(EditingCellComponent),
|
||||||
bindRowLevelCellEdit: jest.fn().mockReturnValue(RowComponent)
|
withRowLevelCellEdit: jest.fn().mockReturnValue(RowComponent)
|
||||||
};
|
};
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
@@ -278,12 +277,10 @@ describe('Body', () => {
|
|||||||
|
|
||||||
it('should render Row Component correctly', () => {
|
it('should render Row Component correctly', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(1);
|
||||||
expect(cellEdit.bindCellLevelCellEdit).toHaveBeenCalledTimes(1);
|
|
||||||
expect(cellEdit.createEditingCell).toHaveBeenCalledTimes(1);
|
expect(cellEdit.createEditingCell).toHaveBeenCalledTimes(1);
|
||||||
expect(cellEdit.bindRowLevelCellEdit).toHaveBeenCalledTimes(1);
|
expect(cellEdit.withRowLevelCellEdit).toHaveBeenCalledTimes(1);
|
||||||
expect(wrapper.find(RowComponent)).toHaveLength(2);
|
expect(wrapper.find(RowComponent)).toHaveLength(2);
|
||||||
const aRowElement = wrapper.find(RowComponent).get(0);
|
const aRowElement = wrapper.find(RowComponent).get(0);
|
||||||
expect(aRowElement.props.CellComponent).toBeDefined();
|
|
||||||
expect(aRowElement.props.EditingCellComponent).toBeDefined();
|
expect(aRowElement.props.EditingCellComponent).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -198,6 +198,26 @@ describe('Cell', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when props.tabIndex is change', () => {
|
||||||
|
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, tabIndex: 2 };
|
||||||
|
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
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 };
|
||||||
|
|||||||
@@ -112,9 +112,9 @@ describe('Context', () => {
|
|||||||
Provider: CellEditContext.Provider,
|
Provider: CellEditContext.Provider,
|
||||||
Consumer: CellEditContext.Consumer
|
Consumer: CellEditContext.Consumer
|
||||||
}),
|
}),
|
||||||
bindCellLevelCellEdit: jest.fn().mockReturnValue(() => null),
|
options: {},
|
||||||
createEditingCell: jest.fn().mockReturnValue(() => null),
|
createEditingCell: jest.fn().mockReturnValue(() => null),
|
||||||
bindRowLevelCellEdit: jest.fn().mockReturnValue(() => null)
|
withRowLevelCellEdit: jest.fn().mockReturnValue(() => null)
|
||||||
};
|
};
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
|
|||||||
@@ -223,6 +223,25 @@ describe('DataContext', () => {
|
|||||||
it('should set state.selected correctly', () => {
|
it('should set state.selected correctly', () => {
|
||||||
expect(wrapper.state('selected')).toEqual(data.map(d => d[keyField]));
|
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', () => {
|
describe('when isUnSelect argument is true', () => {
|
||||||
@@ -237,24 +256,25 @@ describe('DataContext', () => {
|
|||||||
it('should set state.selected correctly', () => {
|
it('should set state.selected correctly', () => {
|
||||||
expect(wrapper.state('selected')).toEqual([]);
|
expect(wrapper.state('selected')).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('when selectRow.onSelectAll is defined', () => {
|
describe('when selectRow.onSelectAll is defined', () => {
|
||||||
const onSelectAll = jest.fn();
|
const onSelectAll = jest.fn();
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(shallowContext({
|
wrapper = shallow(shallowContext({
|
||||||
...defaultSelectRow,
|
...defaultSelectRow,
|
||||||
onSelectAll
|
selected: data.map(d => d[keyField]),
|
||||||
}));
|
onSelectAll
|
||||||
wrapper.instance().handleAllRowsSelect(e, false);
|
}));
|
||||||
});
|
wrapper.instance().handleAllRowsSelect(e, true);
|
||||||
|
});
|
||||||
|
|
||||||
it('should call selectRow.onSelectAll correctly', () => {
|
it('should call selectRow.onSelectAll correctly', () => {
|
||||||
expect(onSelectAll).toHaveBeenCalledWith(
|
expect(onSelectAll).toHaveBeenCalledWith(
|
||||||
true,
|
false,
|
||||||
dataOperator.getSelectedRows(data, keyField, wrapper.state('selected')),
|
dataOperator.getSelectedRows(data, keyField, data.map(d => d[keyField])),
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -403,6 +403,24 @@ describe('HeaderCell', () => {
|
|||||||
it('header should render SortSymbol as default', () => {
|
it('header should render SortSymbol as default', () => {
|
||||||
expect(wrapper.find(SortSymbol).length).toBe(1);
|
expect(wrapper.find(SortSymbol).length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when sortCaret is defined ', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
column = { ...column, sortCaret: jest.fn() };
|
||||||
|
wrapper = shallow(
|
||||||
|
<HeaderCell column={ column } index={ index } onSort={ onSortCallBack } />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('header should not render SortSymbol', () => {
|
||||||
|
expect(wrapper.find(SortSymbol).length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call column.sortCaret correctly', () => {
|
||||||
|
expect(column.sortCaret).toHaveBeenCalledTimes(1);
|
||||||
|
expect(column.sortCaret).toHaveBeenCalledWith(undefined, column);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('and sorting prop is true', () => {
|
describe('and sorting prop is true', () => {
|
||||||
@@ -420,6 +438,30 @@ describe('HeaderCell', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when sortCaret is defined ', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
column = { ...column, sortCaret: jest.fn() };
|
||||||
|
wrapper = shallow(
|
||||||
|
<HeaderCell
|
||||||
|
column={ column }
|
||||||
|
index={ index }
|
||||||
|
onSort={ onSortCallBack }
|
||||||
|
sortOrder={ Const.SORT_ASC }
|
||||||
|
sorting
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('header should not render SortSymbol', () => {
|
||||||
|
expect(wrapper.find(SortSymbol).length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call column.sortCaret correctly', () => {
|
||||||
|
expect(column.sortCaret).toHaveBeenCalledTimes(1);
|
||||||
|
expect(column.sortCaret).toHaveBeenCalledWith(Const.SORT_ASC, column);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when headerSortingClasses is defined ', () => {
|
describe('when headerSortingClasses is defined ', () => {
|
||||||
const classes = 'foo';
|
const classes = 'foo';
|
||||||
const order = Const.SORT_DESC;
|
const order = Const.SORT_DESC;
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import React from 'react';
|
|||||||
import { mount } from 'enzyme';
|
import { mount } from 'enzyme';
|
||||||
|
|
||||||
import SelectionContext from '../../src/contexts/selection-context';
|
import SelectionContext from '../../src/contexts/selection-context';
|
||||||
import bindSelection from '../../src/row-selection/row-binder';
|
import withSelectionConsumer from '../../src/row-selection/row-consumer';
|
||||||
|
|
||||||
describe('Selection Row Binder', () => {
|
describe('withSelectionConsumer', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
let selectRow;
|
let selectRow;
|
||||||
const BaseComponent = () => null;
|
const BaseComponent = () => null;
|
||||||
const WithSelectionComponent = bindSelection(props => <BaseComponent { ...props } />);
|
const WithSelectionComponent = withSelectionConsumer(props => <BaseComponent { ...props } />);
|
||||||
|
|
||||||
const data = [{
|
const data = [{
|
||||||
id: 1,
|
id: 1,
|
||||||
@@ -14,24 +14,106 @@ describe('<SelectionCell />', () => {
|
|||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
describe('shouldComponentUpdate', () => {
|
describe('shouldComponentUpdate', () => {
|
||||||
const selected = true;
|
let props;
|
||||||
|
let nextProps;
|
||||||
|
|
||||||
describe('when selected prop has not been changed', () => {
|
describe('when selected prop has been changed', () => {
|
||||||
it('should not update component', () => {
|
beforeEach(() => {
|
||||||
const nextProps = { selected };
|
props = {
|
||||||
|
selected: false,
|
||||||
|
mode,
|
||||||
|
rowIndex,
|
||||||
|
disabled: false,
|
||||||
|
rowKey: 1
|
||||||
|
};
|
||||||
|
wrapper = shallow(
|
||||||
|
<SelectionCell { ...props } />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
wrapper = shallow(<SelectionCell rowKey={ 1 } mode={ mode } selected={ selected } />);
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, selected: true };
|
||||||
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(false);
|
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when selected prop has been changed', () => {
|
describe('when rowIndex prop has been changed', () => {
|
||||||
it('should update component', () => {
|
beforeEach(() => {
|
||||||
const nextProps = { selected: !selected };
|
props = {
|
||||||
|
selected: false,
|
||||||
|
mode,
|
||||||
|
rowIndex,
|
||||||
|
disabled: false,
|
||||||
|
rowKey: 1
|
||||||
|
};
|
||||||
|
wrapper = shallow(
|
||||||
|
<SelectionCell { ...props } />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
wrapper = shallow(<SelectionCell rowKey={ 1 } mode={ mode } selected={ selected } />);
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, rowIndex: 2 };
|
||||||
|
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when tabIndex prop has been changed', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
selected: false,
|
||||||
|
mode,
|
||||||
|
rowIndex,
|
||||||
|
disabled: false,
|
||||||
|
tabIndex: 0,
|
||||||
|
rowKey: 1
|
||||||
|
};
|
||||||
|
wrapper = shallow(
|
||||||
|
<SelectionCell { ...props } />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, tabIndex: 2 };
|
||||||
|
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when disabled prop has been changed', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
selected: false,
|
||||||
|
mode,
|
||||||
|
rowIndex,
|
||||||
|
disabled: false,
|
||||||
|
rowKey: 1
|
||||||
|
};
|
||||||
|
wrapper = shallow(
|
||||||
|
<SelectionCell { ...props } />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, disabled: true };
|
||||||
|
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when rowKey prop has been changed', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
selected: false,
|
||||||
|
mode,
|
||||||
|
rowIndex,
|
||||||
|
disabled: false,
|
||||||
|
rowKey: 1
|
||||||
|
};
|
||||||
|
wrapper = shallow(
|
||||||
|
<SelectionCell { ...props } />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, rowKey: '1' };
|
||||||
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -104,6 +104,22 @@ describe('<SelectionHeaderCell />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('render', () => {
|
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', () => {
|
describe('when props.mode is radio', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const checkedStatus = Const.CHECKBOX_STATUS_CHECKED;
|
const checkedStatus = Const.CHECKBOX_STATUS_CHECKED;
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
import 'jsdom-global/register';
|
import 'jsdom-global/register';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mount } from 'enzyme';
|
import { mount } from 'enzyme';
|
||||||
import mockBodyResolvedProps from './test-helpers/mock/body-resolved-props';
|
import mockBodyResolvedProps from '../test-helpers/mock/body-resolved-props';
|
||||||
import SelectionContext from '../src/contexts/selection-context';
|
import SelectionContext from '../../src/contexts/selection-context';
|
||||||
import ExpansionContext from '../src/contexts/row-expand-context';
|
import ExpansionContext from '../../src/contexts/row-expand-context';
|
||||||
import bindSelection from '../src/row-selection/row-binder';
|
import bindSelection from '../../src/row-selection/row-consumer';
|
||||||
import bindExpansion from '../src/row-expand/row-binder';
|
import bindExpansion from '../../src/row-expand/row-consumer';
|
||||||
import ExpandCell from '../src/row-expand/expand-cell';
|
import ExpandCell from '../../src/row-expand/expand-cell';
|
||||||
import SelectionCell from '../src/row-selection/selection-cell';
|
import SelectionCell from '../../src/row-selection/selection-cell';
|
||||||
import RowAggregator from '../src/row-aggregator';
|
import RowAggregator from '../../src/row/aggregate-row';
|
||||||
import Row from '../src/row';
|
|
||||||
|
|
||||||
describe('Row Aggregator', () => {
|
describe('Row Aggregator', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
@@ -108,9 +107,9 @@ describe('Row Aggregator', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should add onClick prop to Row Component', () => {
|
it('should add onClick prop to Row Component', () => {
|
||||||
const rowComp = wrapper.find(Row);
|
const tr = wrapper.find('tr');
|
||||||
expect(rowComp).toHaveLength(1);
|
expect(tr).toHaveLength(1);
|
||||||
expect(rowComp.props().attrs.onClick).toBeDefined();
|
expect(tr.props().onClick).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -216,7 +215,7 @@ describe('Row Aggregator', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('if props.expandRow.renderer is defined', () => {
|
describe('if props.expandRow is not defined', () => {
|
||||||
describe('but expandable props is false', () => {
|
describe('but expandable props is false', () => {
|
||||||
const expandRow = { renderer: jest.fn(), nonExpandable: [row[keyField]] };
|
const expandRow = { renderer: jest.fn(), nonExpandable: [row[keyField]] };
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -236,7 +235,7 @@ describe('Row Aggregator', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('if props.expandRow.renderer is defined', () => {
|
describe('if props.expandRow is defined', () => {
|
||||||
const expandRow = { renderer: jest.fn() };
|
const expandRow = { renderer: jest.fn() };
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = mount(
|
wrapper = mount(
|
||||||
@@ -253,7 +252,7 @@ describe('Row Aggregator', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('if props.attrs.onClick and props.expandRow.renderer both are defined', () => {
|
describe('if props.attrs.onClick and props.expandRow both are defined', () => {
|
||||||
const attrs = { onClick: jest.fn() };
|
const attrs = { onClick: jest.fn() };
|
||||||
const expandRow = { renderer: jest.fn() };
|
const expandRow = { renderer: jest.fn() };
|
||||||
|
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import sinon from 'sinon';
|
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import Cell from '../src/cell';
|
import Cell from '../../src/cell';
|
||||||
import Row from '../src/row';
|
import RowPureContent from '../../src/row/row-pure-content';
|
||||||
import mockBodyResolvedProps from './test-helpers/mock/body-resolved-props';
|
import mockBodyResolvedProps from '../test-helpers/mock/body-resolved-props';
|
||||||
|
|
||||||
let defaultColumns = [{
|
let defaultColumns = [{
|
||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
@@ -20,7 +19,7 @@ let defaultColumns = [{
|
|||||||
const keyField = 'id';
|
const keyField = 'id';
|
||||||
const rowIndex = 1;
|
const rowIndex = 1;
|
||||||
|
|
||||||
describe('Row', () => {
|
describe('RowPureContent', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
const row = {
|
const row = {
|
||||||
@@ -42,11 +41,55 @@ describe('Row', () => {
|
|||||||
}];
|
}];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('shouldComponentUpdate', () => {
|
||||||
|
let props;
|
||||||
|
let nextProps;
|
||||||
|
|
||||||
|
describe('if nextProps.shouldUpdate is different with this.props.shouldUpdate', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
keyField,
|
||||||
|
columns: defaultColumns,
|
||||||
|
rowIndex: 1,
|
||||||
|
row,
|
||||||
|
shouldUpdate: false
|
||||||
|
};
|
||||||
|
wrapper = shallow(
|
||||||
|
<RowPureContent { ...props } />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, shouldUpdate: true };
|
||||||
|
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('if nextProps.shouldUpdate is same with this.props.shouldUpdate', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
keyField,
|
||||||
|
columns: defaultColumns,
|
||||||
|
rowIndex: 1,
|
||||||
|
row,
|
||||||
|
shouldUpdate: false
|
||||||
|
};
|
||||||
|
wrapper = shallow(
|
||||||
|
<RowPureContent { ...props } />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false', () => {
|
||||||
|
nextProps = { ...props };
|
||||||
|
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('simplest row', () => {
|
describe('simplest row', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ defaultColumns }
|
columns={ defaultColumns }
|
||||||
@@ -56,66 +99,49 @@ describe('Row', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render successfully', () => {
|
it('should render successfully', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find('tr').length).toBe(1);
|
|
||||||
expect(wrapper.find(Cell).length).toBe(Object.keys(row).length);
|
expect(wrapper.find(Cell).length).toBe(Object.keys(row).length);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when style prop is defined', () => {
|
describe('when tabIndexStart prop is -1', () => {
|
||||||
const customStyle = { backgroundColor: 'red' };
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
tabIndexStart={ -1 }
|
||||||
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ defaultColumns }
|
columns={ defaultColumns }
|
||||||
row={ row }
|
row={ row }
|
||||||
style={ customStyle }
|
/>
|
||||||
/>);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render component with style successfully', () => {
|
it('should not render tabIndex prop on Cell', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
wrapper.find(Cell).forEach((cell) => {
|
||||||
expect(wrapper.prop('style')).toEqual(customStyle);
|
expect(cell.prop('tabIndex')).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when className prop is defined', () => {
|
describe('when tabIndexStart prop is not -1', () => {
|
||||||
const className = 'test-class';
|
const tabIndexStart = 4;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
tabIndexStart={ tabIndexStart }
|
||||||
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ defaultColumns }
|
columns={ defaultColumns }
|
||||||
row={ row }
|
row={ row }
|
||||||
className={ className }
|
/>
|
||||||
/>);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render component with className successfully', () => {
|
it('should render correct tabIndex prop on Cell', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
wrapper.find(Cell).forEach((cell, i) => {
|
||||||
expect(wrapper.hasClass(className)).toBe(true);
|
expect(cell.prop('tabIndex')).toEqual(tabIndexStart + i);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('when CellComponent prop is defined', () => {
|
|
||||||
const CellComponent = () => null;
|
|
||||||
beforeEach(() => {
|
|
||||||
wrapper = shallow(
|
|
||||||
<Row
|
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columns={ defaultColumns }
|
|
||||||
row={ row }
|
|
||||||
CellComponent={ CellComponent }
|
|
||||||
/>);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render CellComponent successfully', () => {
|
|
||||||
expect(wrapper.length).toBe(1);
|
|
||||||
expect(wrapper.find(CellComponent)).toHaveLength(defaultColumns.length);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -125,8 +151,8 @@ describe('Row', () => {
|
|||||||
const EditingCellComponent = () => null;
|
const EditingCellComponent = () => null;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ defaultColumns }
|
columns={ defaultColumns }
|
||||||
row={ row }
|
row={ row }
|
||||||
@@ -138,7 +164,7 @@ describe('Row', () => {
|
|||||||
|
|
||||||
it('should render EditingCell component correctly', () => {
|
it('should render EditingCell component correctly', () => {
|
||||||
const EditingCell = wrapper.find(EditingCellComponent);
|
const EditingCell = wrapper.find(EditingCellComponent);
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(EditingCell).toHaveLength(1);
|
expect(EditingCell).toHaveLength(1);
|
||||||
expect(EditingCell.prop('row')).toEqual(row);
|
expect(EditingCell.prop('row')).toEqual(row);
|
||||||
expect(EditingCell.prop('rowIndex')).toEqual(editingRowIdx);
|
expect(EditingCell.prop('rowIndex')).toEqual(editingRowIdx);
|
||||||
@@ -147,27 +173,6 @@ describe('Row', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when attrs prop is defined', () => {
|
|
||||||
const customClickCallBack = sinon.stub();
|
|
||||||
const attrs = { 'data-index': 1, onClick: customClickCallBack };
|
|
||||||
beforeEach(() => {
|
|
||||||
wrapper = shallow(
|
|
||||||
<Row
|
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columns={ defaultColumns }
|
|
||||||
row={ row }
|
|
||||||
attrs={ attrs }
|
|
||||||
/>);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should render component with correct attributes', () => {
|
|
||||||
expect(wrapper.length).toBe(1);
|
|
||||||
expect(wrapper.prop('data-index')).toBe(attrs['data-index']);
|
|
||||||
expect(wrapper.prop('onClick')).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when column.hidden is true', () => {
|
describe('when column.hidden is true', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const newColumns = [{
|
const newColumns = [{
|
||||||
@@ -182,8 +187,8 @@ describe('Row', () => {
|
|||||||
text: 'Price'
|
text: 'Price'
|
||||||
}];
|
}];
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ newColumns }
|
columns={ newColumns }
|
||||||
row={ row }
|
row={ row }
|
||||||
@@ -207,8 +212,7 @@ describe('Row', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
columns[columnIndex].style = { backgroundColor: 'red' };
|
columns[columnIndex].style = { backgroundColor: 'red' };
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -218,7 +222,7 @@ describe('Row', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render Cell correctly', () => {
|
it('should render Cell correctly', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.style).toEqual(columns[columnIndex].style);
|
expect(wrapper.find(Cell).get(columnIndex).props.style).toEqual(columns[columnIndex].style);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -228,11 +232,10 @@ describe('Row', () => {
|
|||||||
let styleCallBack;
|
let styleCallBack;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
styleCallBack = sinon.stub().returns(returnStyle);
|
styleCallBack = jest.fn().mockReturnValue(returnStyle);
|
||||||
columns[columnIndex].style = styleCallBack;
|
columns[columnIndex].style = styleCallBack;
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -241,18 +244,17 @@ describe('Row', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => { styleCallBack.reset(); });
|
afterEach(() => { styleCallBack.mockClear(); });
|
||||||
|
|
||||||
it('should render Cell correctly', () => {
|
it('should render Cell correctly', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.style).toEqual(returnStyle);
|
expect(wrapper.find(Cell).get(columnIndex).props.style).toEqual(returnStyle);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call custom style function correctly', () => {
|
it('should call custom style function correctly', () => {
|
||||||
expect(styleCallBack.callCount).toBe(1);
|
expect(styleCallBack).toHaveBeenCalledTimes(1);
|
||||||
expect(
|
expect(styleCallBack).toHaveBeenCalledWith(
|
||||||
styleCallBack.calledWith(row[columns[columnIndex].dataField], row, rowIndex, columnIndex)
|
row[columns[columnIndex].dataField], row, rowIndex, columnIndex);
|
||||||
).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -269,8 +271,7 @@ describe('Row', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
columns[columnIndex].classes = 'td-test-class';
|
columns[columnIndex].classes = 'td-test-class';
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -280,7 +281,7 @@ describe('Row', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render Cell correctly', () => {
|
it('should render Cell correctly', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.className)
|
expect(wrapper.find(Cell).get(columnIndex).props.className)
|
||||||
.toEqual(columns[columnIndex].classes);
|
.toEqual(columns[columnIndex].classes);
|
||||||
});
|
});
|
||||||
@@ -291,11 +292,10 @@ describe('Row', () => {
|
|||||||
let classesCallBack;
|
let classesCallBack;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
classesCallBack = sinon.stub().returns(returnClasses);
|
classesCallBack = jest.fn().mockReturnValue(returnClasses);
|
||||||
columns[columnIndex].classes = classesCallBack;
|
columns[columnIndex].classes = classesCallBack;
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -304,19 +304,17 @@ describe('Row', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => { classesCallBack.reset(); });
|
afterEach(() => { classesCallBack.mockClear(); });
|
||||||
|
|
||||||
it('should render Cell correctly', () => {
|
it('should render Cell correctly', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.className).toEqual(returnClasses);
|
expect(wrapper.find(Cell).get(columnIndex).props.className).toEqual(returnClasses);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call custom classes function correctly', () => {
|
it('should call custom classes function correctly', () => {
|
||||||
expect(classesCallBack.callCount).toBe(1);
|
expect(classesCallBack).toHaveBeenCalledTimes(1);
|
||||||
expect(
|
expect(classesCallBack).toHaveBeenCalledWith(
|
||||||
classesCallBack.calledWith(
|
row[columns[columnIndex].dataField], row, rowIndex, columnIndex);
|
||||||
row[columns[columnIndex].dataField], row, rowIndex, columnIndex)
|
|
||||||
).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -333,8 +331,7 @@ describe('Row', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
columns[columnIndex].title = true;
|
columns[columnIndex].title = true;
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -344,7 +341,7 @@ describe('Row', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render Cell correctly', () => {
|
it('should render Cell correctly', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.title)
|
expect(wrapper.find(Cell).get(columnIndex).props.title)
|
||||||
.toEqual(row[columns[columnIndex].dataField]);
|
.toEqual(row[columns[columnIndex].dataField]);
|
||||||
});
|
});
|
||||||
@@ -355,11 +352,10 @@ describe('Row', () => {
|
|||||||
let titleCallBack;
|
let titleCallBack;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
titleCallBack = sinon.stub().returns(returnTitle);
|
titleCallBack = jest.fn().mockReturnValue(returnTitle);
|
||||||
columns[columnIndex].title = titleCallBack;
|
columns[columnIndex].title = titleCallBack;
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -368,19 +364,17 @@ describe('Row', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => { titleCallBack.reset(); });
|
afterEach(() => { titleCallBack.mockClear(); });
|
||||||
|
|
||||||
it('should render Cell correctly', () => {
|
it('should render Cell correctly', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.title).toEqual(returnTitle);
|
expect(wrapper.find(Cell).get(columnIndex).props.title).toEqual(returnTitle);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call custom title function correctly', () => {
|
it('should call custom title function correctly', () => {
|
||||||
expect(titleCallBack.callCount).toBe(1);
|
expect(titleCallBack).toHaveBeenCalledTimes(1);
|
||||||
expect(
|
expect(titleCallBack).toHaveBeenCalledWith(
|
||||||
titleCallBack.calledWith(
|
row[columns[columnIndex].dataField], row, rowIndex, columnIndex);
|
||||||
row[columns[columnIndex].dataField], row, rowIndex, columnIndex)
|
|
||||||
).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -392,12 +386,11 @@ describe('Row', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
columns = [...defaultColumns];
|
columns = [...defaultColumns];
|
||||||
columns[columnIndex].events = {
|
columns[columnIndex].events = {
|
||||||
onClick: sinon.stub()
|
onClick: jest.fn()
|
||||||
};
|
};
|
||||||
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -407,7 +400,7 @@ describe('Row', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should attachs DOM event successfully', () => {
|
it('should attachs DOM event successfully', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.onClick).toBeDefined();
|
expect(wrapper.find(Cell).get(columnIndex).props.onClick).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -424,8 +417,7 @@ describe('Row', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
columns[columnIndex].align = 'right';
|
columns[columnIndex].align = 'right';
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -435,7 +427,7 @@ describe('Row', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render Cell correctly', () => {
|
it('should render Cell correctly', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.style.textAlign)
|
expect(wrapper.find(Cell).get(columnIndex).props.style.textAlign)
|
||||||
.toEqual(columns[columnIndex].align);
|
.toEqual(columns[columnIndex].align);
|
||||||
});
|
});
|
||||||
@@ -446,10 +438,10 @@ describe('Row', () => {
|
|||||||
let alignCallBack;
|
let alignCallBack;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
alignCallBack = sinon.stub().returns(returnAlign);
|
alignCallBack = jest.fn().mockReturnValue(returnAlign);
|
||||||
columns[columnIndex].align = alignCallBack;
|
columns[columnIndex].align = alignCallBack;
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
{ ...mockBodyResolvedProps }
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
@@ -459,18 +451,17 @@ describe('Row', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => { alignCallBack.reset(); });
|
afterEach(() => { alignCallBack.mockClear(); });
|
||||||
|
|
||||||
it('should render Cell correctly', () => {
|
it('should render Cell correctly', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.style.textAlign).toEqual(returnAlign);
|
expect(wrapper.find(Cell).get(columnIndex).props.style.textAlign).toEqual(returnAlign);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call custom align function correctly', () => {
|
it('should call custom align function correctly', () => {
|
||||||
expect(alignCallBack.callCount).toBe(1);
|
expect(alignCallBack).toHaveBeenCalledTimes(1);
|
||||||
expect(
|
expect(alignCallBack).toHaveBeenCalledWith(
|
||||||
alignCallBack.calledWith(row[columns[columnIndex].dataField], row, rowIndex, columnIndex)
|
row[columns[columnIndex].dataField], row, rowIndex, columnIndex);
|
||||||
).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -497,8 +488,7 @@ describe('Row', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -506,7 +496,7 @@ describe('Row', () => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props['data-test'])
|
expect(wrapper.find(Cell).get(columnIndex).props['data-test'])
|
||||||
.toEqual(columns[columnIndex].attrs['data-test']);
|
.toEqual(columns[columnIndex].attrs['data-test']);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.title)
|
expect(wrapper.find(Cell).get(columnIndex).props.title)
|
||||||
@@ -523,8 +513,7 @@ describe('Row', () => {
|
|||||||
columns[columnIndex].attrs = { title: 'title' };
|
columns[columnIndex].attrs = { title: 'title' };
|
||||||
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -543,8 +532,7 @@ describe('Row', () => {
|
|||||||
columns[columnIndex].attrs = { className: 'attrs-class' };
|
columns[columnIndex].attrs = { className: 'attrs-class' };
|
||||||
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -563,8 +551,7 @@ describe('Row', () => {
|
|||||||
columns[columnIndex].attrs = { style: { backgroundColor: 'attrs-style-test' } };
|
columns[columnIndex].attrs = { style: { backgroundColor: 'attrs-style-test' } };
|
||||||
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -583,8 +570,7 @@ describe('Row', () => {
|
|||||||
columns[columnIndex].attrs = { style: { textAlign: 'right' } };
|
columns[columnIndex].attrs = { style: { textAlign: 'right' } };
|
||||||
|
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -606,11 +592,10 @@ describe('Row', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
attrsCallBack = sinon.stub().returns(customAttrs);
|
attrsCallBack = jest.fn().mockReturnValue(customAttrs);
|
||||||
columns[columnIndex].attrs = attrsCallBack;
|
columns[columnIndex].attrs = attrsCallBack;
|
||||||
wrapper = shallow(
|
wrapper = shallow(
|
||||||
<Row
|
<RowPureContent
|
||||||
{ ...mockBodyResolvedProps }
|
|
||||||
keyField={ keyField }
|
keyField={ keyField }
|
||||||
rowIndex={ rowIndex }
|
rowIndex={ rowIndex }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -619,8 +604,10 @@ describe('Row', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterEach(() => { attrsCallBack.mockClear(); });
|
||||||
|
|
||||||
it('should render style.attrs correctly', () => {
|
it('should render style.attrs correctly', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(defaultColumns.length);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props['data-test'])
|
expect(wrapper.find(Cell).get(columnIndex).props['data-test'])
|
||||||
.toEqual(customAttrs['data-test']);
|
.toEqual(customAttrs['data-test']);
|
||||||
expect(wrapper.find(Cell).get(columnIndex).props.title)
|
expect(wrapper.find(Cell).get(columnIndex).props.title)
|
||||||
@@ -628,10 +615,9 @@ describe('Row', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should call custom attrs function correctly', () => {
|
it('should call custom attrs function correctly', () => {
|
||||||
expect(attrsCallBack.callCount).toBe(1);
|
expect(attrsCallBack).toHaveBeenCalledTimes(1);
|
||||||
expect(
|
expect(attrsCallBack).toHaveBeenCalledWith(
|
||||||
attrsCallBack.calledWith(row[columns[columnIndex].dataField], row, rowIndex, columnIndex)
|
row[columns[columnIndex].dataField], row, rowIndex, columnIndex);
|
||||||
).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
import RowSection from '../src/row-section';
|
import RowSection from '../../src/row/row-section';
|
||||||
|
|
||||||
describe('Row', () => {
|
describe('Row', () => {
|
||||||
const colSpan = 3;
|
const colSpan = 3;
|
||||||
164
packages/react-bootstrap-table2/test/row/should-updater.test.js
Normal file
164
packages/react-bootstrap-table2/test/row/should-updater.test.js
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
|
import shouldUpdater from '../../src/row/should-updater';
|
||||||
|
|
||||||
|
describe('Row shouldUpdater', () => {
|
||||||
|
let wrapper;
|
||||||
|
let props;
|
||||||
|
let nextProps;
|
||||||
|
|
||||||
|
class DummyComponent extends shouldUpdater(React.Component) {
|
||||||
|
render() { return null; }
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('shouldUpdateByCellEditing', () => {
|
||||||
|
describe('when nextProps.clickToEdit and nexrProps.dbclickToEdit both are negative', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
editingRowIdx: null,
|
||||||
|
rowIndex: 0
|
||||||
|
};
|
||||||
|
wrapper = shallow(<DummyComponent { ...props } />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should always return false', () => {
|
||||||
|
nextProps = { ...props, editingRowIdx: 0 };
|
||||||
|
expect(wrapper.instance().shouldUpdateByCellEditing(nextProps)).toBeFalsy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('when nextProps.editingRowIdx eq props.rowIndex and it\' not null', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
clickToEdit: true,
|
||||||
|
editingRowIdx: null,
|
||||||
|
rowIndex: 0
|
||||||
|
};
|
||||||
|
wrapper = shallow(<DummyComponent { ...props } />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, editingRowIdx: 0 };
|
||||||
|
expect(wrapper.instance().shouldUpdateByCellEditing(nextProps)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when props.editingRowIdx eq props.rowIndex but nextProps.editingRowIdx is null', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
clickToEdit: true,
|
||||||
|
editingRowIdx: 0,
|
||||||
|
rowIndex: 0
|
||||||
|
};
|
||||||
|
wrapper = shallow(<DummyComponent { ...props } />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, editingRowIdx: null };
|
||||||
|
expect(wrapper.instance().shouldUpdateByCellEditing(nextProps)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('shouldUpdatedBySelfProps', () => {
|
||||||
|
describe('when nextProps.className is not eq props.className', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
className: ''
|
||||||
|
};
|
||||||
|
wrapper = shallow(<DummyComponent { ...props } />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, className: 'test' };
|
||||||
|
expect(wrapper.instance().shouldUpdatedBySelfProps(nextProps)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when nextProps.style is not eq props.style', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
style: null
|
||||||
|
};
|
||||||
|
wrapper = shallow(<DummyComponent { ...props } />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, style: { color: 'red' } };
|
||||||
|
expect(wrapper.instance().shouldUpdatedBySelfProps(nextProps)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when nextProps.attrs is not eq props.attrs', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
attrs: null
|
||||||
|
};
|
||||||
|
wrapper = shallow(<DummyComponent { ...props } />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, attrs: { onClick: jest.fn() } };
|
||||||
|
expect(wrapper.instance().shouldUpdatedBySelfProps(nextProps)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('shouldUpdatedByNormalProps', () => {
|
||||||
|
describe('when nextProps.rowIndex is not eq props.rowIndex', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
rowIndex: 0
|
||||||
|
};
|
||||||
|
wrapper = shallow(<DummyComponent { ...props } />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, rowIndex: 1 };
|
||||||
|
expect(wrapper.instance().shouldUpdatedByNormalProps(nextProps)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when nextProps.editable is not eq props.editable', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
editable: false
|
||||||
|
};
|
||||||
|
wrapper = shallow(<DummyComponent { ...props } />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, editable: true };
|
||||||
|
expect(wrapper.instance().shouldUpdatedByNormalProps(nextProps)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when nextProps.columns.length is not eq props.columns.length', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
columns: [{ dataField: 'price', text: 'Price' }]
|
||||||
|
};
|
||||||
|
wrapper = shallow(<DummyComponent { ...props } />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, columns: [...props.columns, { dataField: 'name', text: 'Name' }] };
|
||||||
|
expect(wrapper.instance().shouldUpdatedByNormalProps(nextProps)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when nextProps.row is not eq props.row', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
row: { id: 1, name: 'test' }
|
||||||
|
};
|
||||||
|
wrapper = shallow(<DummyComponent { ...props } />);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, row: { id: 1, name: 'test', price: 123 } };
|
||||||
|
expect(wrapper.instance().shouldUpdatedByNormalProps(nextProps)).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
216
packages/react-bootstrap-table2/test/row/simple-row.test.js
Normal file
216
packages/react-bootstrap-table2/test/row/simple-row.test.js
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import sinon from 'sinon';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
|
||||||
|
import RowPureContent from '../../src/row/row-pure-content';
|
||||||
|
import SimpleRow from '../../src/row/simple-row';
|
||||||
|
|
||||||
|
let defaultColumns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Price'
|
||||||
|
}];
|
||||||
|
|
||||||
|
const keyField = 'id';
|
||||||
|
const rowIndex = 1;
|
||||||
|
|
||||||
|
describe('SimpleRow', () => {
|
||||||
|
let wrapper;
|
||||||
|
|
||||||
|
const row = {
|
||||||
|
id: 1,
|
||||||
|
name: 'A',
|
||||||
|
price: 1000
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
defaultColumns = [{
|
||||||
|
dataField: 'id',
|
||||||
|
text: 'ID'
|
||||||
|
}, {
|
||||||
|
dataField: 'name',
|
||||||
|
text: 'Name'
|
||||||
|
}, {
|
||||||
|
dataField: 'price',
|
||||||
|
text: 'Price'
|
||||||
|
}];
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('simplest row', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = shallow(
|
||||||
|
<SimpleRow
|
||||||
|
keyField={ keyField }
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
columns={ defaultColumns }
|
||||||
|
row={ row }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render successfully', () => {
|
||||||
|
expect(wrapper.length).toBe(1);
|
||||||
|
expect(wrapper.find(RowPureContent)).toHaveLength(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when tabIndexCell prop is enable', () => {
|
||||||
|
const visibleColumnSize = 3;
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = shallow(
|
||||||
|
<SimpleRow
|
||||||
|
keyField={ keyField }
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
columns={ defaultColumns }
|
||||||
|
row={ row }
|
||||||
|
tabIndexCell
|
||||||
|
visibleColumnSize={ visibleColumnSize }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render correct tabIndexStart', () => {
|
||||||
|
expect(wrapper.length).toBe(1);
|
||||||
|
expect(wrapper.find(RowPureContent)).toHaveLength(1);
|
||||||
|
expect(wrapper.find(RowPureContent).prop('tabIndexStart')).toBe((rowIndex * visibleColumnSize) + 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when tabIndexCell prop is disable', () => {
|
||||||
|
const visibleColumnSize = 3;
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = shallow(
|
||||||
|
<SimpleRow
|
||||||
|
keyField={ keyField }
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
columns={ defaultColumns }
|
||||||
|
row={ row }
|
||||||
|
visibleColumnSize={ visibleColumnSize }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should always render tabIndexStart as -1', () => {
|
||||||
|
expect(wrapper.length).toBe(1);
|
||||||
|
expect(wrapper.find(RowPureContent)).toHaveLength(1);
|
||||||
|
expect(wrapper.find(RowPureContent).prop('tabIndexStart')).toBe(-1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('shouldComponentUpdate', () => {
|
||||||
|
let props;
|
||||||
|
let nextProps;
|
||||||
|
describe('if shouldUpdatedByNormalProps return true', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
keyField,
|
||||||
|
columns: defaultColumns,
|
||||||
|
rowIndex: 1,
|
||||||
|
row,
|
||||||
|
editable: true
|
||||||
|
};
|
||||||
|
wrapper = shallow(
|
||||||
|
<SimpleRow { ...props } />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true', () => {
|
||||||
|
nextProps = { ...props, rowIndex: 2 };
|
||||||
|
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set this.shouldUpdateRowContent as true', () => {
|
||||||
|
nextProps = { ...props, rowIndex: 2 };
|
||||||
|
wrapper.instance().shouldComponentUpdate(nextProps);
|
||||||
|
expect(wrapper.instance().shouldUpdateRowContent).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('if shouldUpdatedByNormalProps return false', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
props = {
|
||||||
|
keyField,
|
||||||
|
columns: defaultColumns,
|
||||||
|
rowIndex: 1,
|
||||||
|
row,
|
||||||
|
editable: true
|
||||||
|
};
|
||||||
|
wrapper = shallow(
|
||||||
|
<SimpleRow { ...props } />
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return value which depends on the result of shouldUpdatedBySelfProps', () => {
|
||||||
|
nextProps = { ...props, className: 'test' };
|
||||||
|
expect(wrapper.instance().shouldComponentUpdate(nextProps)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should always set this.shouldUpdateRowContent as false', () => {
|
||||||
|
nextProps = { ...props, className: 'test' };
|
||||||
|
wrapper.instance().shouldComponentUpdate(nextProps);
|
||||||
|
expect(wrapper.instance().shouldUpdateRowContent).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when style prop is defined', () => {
|
||||||
|
const customStyle = { backgroundColor: 'red' };
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = shallow(
|
||||||
|
<SimpleRow
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
columns={ defaultColumns }
|
||||||
|
row={ row }
|
||||||
|
style={ customStyle }
|
||||||
|
/>);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render component with style successfully', () => {
|
||||||
|
expect(wrapper.length).toBe(1);
|
||||||
|
expect(wrapper.prop('style')).toEqual(customStyle);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when className prop is defined', () => {
|
||||||
|
const className = 'test-class';
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = shallow(
|
||||||
|
<SimpleRow
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
columns={ defaultColumns }
|
||||||
|
row={ row }
|
||||||
|
className={ className }
|
||||||
|
/>);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render component with className successfully', () => {
|
||||||
|
expect(wrapper.length).toBe(1);
|
||||||
|
expect(wrapper.hasClass(className)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when attrs prop is defined', () => {
|
||||||
|
const customClickCallBack = sinon.stub();
|
||||||
|
const attrs = { 'data-index': 1, onClick: customClickCallBack };
|
||||||
|
beforeEach(() => {
|
||||||
|
wrapper = shallow(
|
||||||
|
<SimpleRow
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
columns={ defaultColumns }
|
||||||
|
row={ row }
|
||||||
|
attrs={ attrs }
|
||||||
|
/>);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should render component with correct attributes', () => {
|
||||||
|
expect(wrapper.length).toBe(1);
|
||||||
|
expect(wrapper.prop('data-index')).toBe(attrs['data-index']);
|
||||||
|
expect(wrapper.prop('onClick')).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
12
yarn.lock
12
yarn.lock
@@ -6958,9 +6958,9 @@ rc@^1.1.7:
|
|||||||
minimist "^1.2.0"
|
minimist "^1.2.0"
|
||||||
strip-json-comments "~2.0.1"
|
strip-json-comments "~2.0.1"
|
||||||
|
|
||||||
react-dom@16.3.2:
|
react-dom@16.4.0:
|
||||||
version "16.3.2"
|
version "16.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.3.2.tgz#cb90f107e09536d683d84ed5d4888e9640e0e4df"
|
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.4.0.tgz#099f067dd5827ce36a29eaf9a6cdc7cbf6216b1e"
|
||||||
dependencies:
|
dependencies:
|
||||||
fbjs "^0.8.16"
|
fbjs "^0.8.16"
|
||||||
loose-envify "^1.1.0"
|
loose-envify "^1.1.0"
|
||||||
@@ -6996,9 +6996,9 @@ react-test-renderer@~16.3.0-0:
|
|||||||
prop-types "^15.6.0"
|
prop-types "^15.6.0"
|
||||||
react-is "^16.3.2"
|
react-is "^16.3.2"
|
||||||
|
|
||||||
react@16.3.2:
|
react@16.4.0:
|
||||||
version "16.3.2"
|
version "16.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/react/-/react-16.3.2.tgz#fdc8420398533a1e58872f59091b272ce2f91ea9"
|
resolved "https://registry.yarnpkg.com/react/-/react-16.4.0.tgz#402c2db83335336fba1962c08b98c6272617d585"
|
||||||
dependencies:
|
dependencies:
|
||||||
fbjs "^0.8.16"
|
fbjs "^0.8.16"
|
||||||
loose-envify "^1.1.0"
|
loose-envify "^1.1.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user