mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-29 21:50:07 +00:00
Compare commits
12 Commits
react-boot
...
react-boot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d37a31103 | ||
|
|
f4f6649b91 | ||
|
|
8ecdbf611b | ||
|
|
4a340c714b | ||
|
|
4daa5ef4d7 | ||
|
|
acb9c9f61e | ||
|
|
6d13a86512 | ||
|
|
b5d536b8f4 | ||
|
|
e667317fbe | ||
|
|
d4ffc11f7e | ||
|
|
3c6aaacbce | ||
|
|
defcd04b52 |
@@ -11,6 +11,8 @@
|
|||||||
* [classes)](#classes)
|
* [classes)](#classes)
|
||||||
* [bgColor](#bgColor)
|
* [bgColor](#bgColor)
|
||||||
* [nonSelectable)](#nonSelectable)
|
* [nonSelectable)](#nonSelectable)
|
||||||
|
* [nonSelectableStyle](#nonSelectableStyle)
|
||||||
|
* [nonSelectableClasses](#nonSelectableClasses)
|
||||||
* [clickToSelect)](#clickToSelect)
|
* [clickToSelect)](#clickToSelect)
|
||||||
* [clickToExpand)](#clickToExpand)
|
* [clickToExpand)](#clickToExpand)
|
||||||
* [clickToEdit](#clickToEdit)
|
* [clickToEdit](#clickToEdit)
|
||||||
@@ -139,6 +141,54 @@ const selectRow = {
|
|||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <a name='nonSelectableStyle'>selectRow.nonSelectableStyle - [Object | Function]</a>
|
||||||
|
This prop allow you to customize the non selectable rows. `selectRow.nonSelectableStyle` accepts an style object
|
||||||
|
and a callback function for more flexible customization.
|
||||||
|
|
||||||
|
### Style Object
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
nonSelectable: [1, 3 ,5],
|
||||||
|
nonSelectableStyle: { backgroundColor: 'gray' }
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Callback Function
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
nonSelectable: [1, 3 ,5],
|
||||||
|
nonSelectableStyle: (row, rowIndex) => { return ...; }
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### <a name='nonSelectableClasses'>selectRow.nonSelectableClasses - [String | Function]</a>
|
||||||
|
This prop allow you to set a custom class for the non selectable rows, or use a callback function for more
|
||||||
|
flexible customization
|
||||||
|
|
||||||
|
### String
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
nonSelectable: [1, 3 ,5],
|
||||||
|
nonSelectableClasses: 'my-class'
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
### Callback Function
|
||||||
|
|
||||||
|
```js
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
nonSelectable: [1, 3 ,5],
|
||||||
|
nonSelectableClasses: (row, rowIndex) => { return ...; }
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
### <a name='clickToSelect'>selectRow.clickToSelect - [Bool]</a>
|
### <a name='clickToSelect'>selectRow.clickToSelect - [Bool]</a>
|
||||||
Allow user to select row by clicking on the row.
|
Allow user to select row by clicking on the row.
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,23 @@ const columns = [{
|
|||||||
/>
|
/>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true
|
||||||
|
};
|
||||||
|
|
||||||
|
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,
|
||||||
|
expandColumnPosition: 'right'
|
||||||
|
};
|
||||||
|
|
||||||
export default () => (
|
export default () => (
|
||||||
<div>
|
<div>
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
@@ -79,6 +96,8 @@ export default () => (
|
|||||||
columns={ columns }
|
columns={ columns }
|
||||||
filter={ filterFactory() }
|
filter={ filterFactory() }
|
||||||
filterPosition="top"
|
filterPosition="top"
|
||||||
|
expandRow={ expandRow }
|
||||||
|
selectRow={ selectRow }
|
||||||
/>
|
/>
|
||||||
<Code>{ sourceCode1 }</Code>
|
<Code>{ sourceCode1 }</Code>
|
||||||
<BootstrapTable
|
<BootstrapTable
|
||||||
@@ -87,6 +106,8 @@ export default () => (
|
|||||||
columns={ columns }
|
columns={ columns }
|
||||||
filter={ filterFactory() }
|
filter={ filterFactory() }
|
||||||
filterPosition="bottom"
|
filterPosition="bottom"
|
||||||
|
expandRow={ expandRow }
|
||||||
|
selectRow={ selectRow }
|
||||||
/>
|
/>
|
||||||
<Code>{ sourceCode2 }</Code>
|
<Code>{ sourceCode2 }</Code>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-class.js
vendored
Normal file
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-class.js
vendored
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
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,
|
||||||
|
nonSelectable: [0, 2, 4],
|
||||||
|
nonSelectableClasses: 'row-index-bigger-than-2101'
|
||||||
|
};
|
||||||
|
|
||||||
|
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,
|
||||||
|
nonSelectable: [0, 2, 4],
|
||||||
|
nonSelectableClasses: 'row-index-bigger-than-2101'
|
||||||
|
};
|
||||||
|
|
||||||
|
<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>
|
||||||
|
);
|
||||||
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-style.js
vendored
Normal file
61
packages/react-bootstrap-table2-example/examples/row-selection/non-selectable-rows-style.js
vendored
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
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,
|
||||||
|
nonSelectable: [0, 2, 4],
|
||||||
|
nonSelectableStyle: { backgroundColor: 'gray' }
|
||||||
|
};
|
||||||
|
|
||||||
|
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,
|
||||||
|
nonSelectable: [0, 2, 4],
|
||||||
|
nonSelectableStyle: { backgroundColor: 'gray' }
|
||||||
|
};
|
||||||
|
|
||||||
|
<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>
|
||||||
|
);
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table2-example",
|
"name": "react-bootstrap-table2-example",
|
||||||
"version": "1.0.33",
|
"version": "1.0.35",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -152,6 +152,8 @@ import HeaderStyleTable from 'examples/row-selection/header-style';
|
|||||||
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
|
import HideSelectAllTable from 'examples/row-selection/hide-select-all';
|
||||||
import CustomSelectionTable from 'examples/row-selection/custom-selection';
|
import CustomSelectionTable from 'examples/row-selection/custom-selection';
|
||||||
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
|
import NonSelectableRowsTable from 'examples/row-selection/non-selectable-rows';
|
||||||
|
import NonSelectableRowsStyleTable from 'examples/row-selection/non-selectable-rows-style';
|
||||||
|
import NonSelectableRowsClassTable from 'examples/row-selection/non-selectable-rows-class';
|
||||||
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
|
import SelectionBgColorTable from 'examples/row-selection/selection-bgcolor';
|
||||||
import SelectionHooks from 'examples/row-selection/selection-hooks';
|
import SelectionHooks from 'examples/row-selection/selection-hooks';
|
||||||
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
|
import HideSelectionColumnTable from 'examples/row-selection/hide-selection-column';
|
||||||
@@ -410,6 +412,8 @@ storiesOf('Row Selection', module)
|
|||||||
.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 />)
|
||||||
|
.add('Not Selectabled Rows Style', () => <NonSelectableRowsStyleTable />)
|
||||||
|
.add('Not Selectabled Rows Class', () => <NonSelectableRowsClassTable />)
|
||||||
.add('Selection Hooks', () => <SelectionHooks />)
|
.add('Selection Hooks', () => <SelectionHooks />)
|
||||||
.add('Hide Selection Column', () => <HideSelectionColumnTable />)
|
.add('Hide Selection Column', () => <HideSelectionColumnTable />)
|
||||||
.add('Custom Selection Column Style', () => <SelectionColumnStyleTable />)
|
.add('Custom Selection Column Style', () => <SelectionColumnStyleTable />)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-bootstrap-table-next",
|
"name": "react-bootstrap-table-next",
|
||||||
"version": "3.3.0",
|
"version": "3.3.2",
|
||||||
"description": "Next generation of react-bootstrap-table",
|
"description": "Next generation of react-bootstrap-table",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ class BootstrapTable extends PropsBaseResolver(Component) {
|
|||||||
currFilters={ this.props.currFilters }
|
currFilters={ this.props.currFilters }
|
||||||
filterPosition={ this.props.filterPosition }
|
filterPosition={ this.props.filterPosition }
|
||||||
onExternalFilter={ this.props.onExternalFilter }
|
onExternalFilter={ this.props.onExternalFilter }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
expandRow={ expandRow }
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Body
|
<Body
|
||||||
@@ -182,6 +184,8 @@ BootstrapTable.propTypes = {
|
|||||||
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
style: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
||||||
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
classes: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
nonSelectable: PropTypes.array,
|
nonSelectable: PropTypes.array,
|
||||||
|
nonSelectableStyle: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
|
nonSelectableClasses: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
bgColor: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||||
hideSelectColumn: PropTypes.bool,
|
hideSelectColumn: PropTypes.bool,
|
||||||
selectionRenderer: PropTypes.func,
|
selectionRenderer: PropTypes.func,
|
||||||
|
|||||||
20
packages/react-bootstrap-table2/src/filters.js
vendored
20
packages/react-bootstrap-table2/src/filters.js
vendored
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
|
|||||||
|
|
||||||
import FiltersCell from './filters-cell';
|
import FiltersCell from './filters-cell';
|
||||||
import Const from './const';
|
import Const from './const';
|
||||||
|
import RowTemplate from './row/row-template';
|
||||||
|
|
||||||
const Filters = (props) => {
|
const Filters = (props) => {
|
||||||
const {
|
const {
|
||||||
@@ -12,15 +13,19 @@ const Filters = (props) => {
|
|||||||
currFilters,
|
currFilters,
|
||||||
filterPosition,
|
filterPosition,
|
||||||
onExternalFilter,
|
onExternalFilter,
|
||||||
className
|
className,
|
||||||
|
selectRow,
|
||||||
|
expandRow
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
function renderContent() {
|
||||||
const filterColumns = [];
|
const filterColumns = [];
|
||||||
let showFiltersRow = false;
|
let showFiltersRow = false;
|
||||||
|
|
||||||
columns.forEach((column, i) => {
|
columns.forEach((column, i) => {
|
||||||
filterColumns.push(<FiltersCell
|
filterColumns.push(<FiltersCell
|
||||||
index={ i }
|
index={ i }
|
||||||
|
key={ column.dataField }
|
||||||
column={ column }
|
column={ column }
|
||||||
currFilters={ currFilters }
|
currFilters={ currFilters }
|
||||||
onExternalFilter={ onExternalFilter }
|
onExternalFilter={ onExternalFilter }
|
||||||
@@ -33,6 +38,8 @@ const Filters = (props) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return filterColumns;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tbody
|
<tbody
|
||||||
@@ -44,7 +51,12 @@ const Filters = (props) => {
|
|||||||
: 'table-footer-group'
|
: 'table-footer-group'
|
||||||
} }
|
} }
|
||||||
>
|
>
|
||||||
<tr>{filterColumns}</tr>
|
<RowTemplate
|
||||||
|
renderContent={ renderContent }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
cellEl="td"
|
||||||
|
/>
|
||||||
</tbody>
|
</tbody>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -59,7 +71,9 @@ Filters.propTypes = {
|
|||||||
]),
|
]),
|
||||||
currFilters: PropTypes.object,
|
currFilters: PropTypes.object,
|
||||||
onExternalFilter: PropTypes.func,
|
onExternalFilter: PropTypes.func,
|
||||||
className: PropTypes.string
|
className: PropTypes.string,
|
||||||
|
selectRow: PropTypes.object,
|
||||||
|
expandRow: PropTypes.object
|
||||||
};
|
};
|
||||||
|
|
||||||
Filters.defaultProps = {
|
Filters.defaultProps = {
|
||||||
|
|||||||
36
packages/react-bootstrap-table2/src/footer.js
vendored
36
packages/react-bootstrap-table2/src/footer.js
vendored
@@ -2,20 +2,15 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import Const from './const';
|
import RowTemplate from './row/row-template';
|
||||||
import FooterCell from './footer-cell';
|
import FooterCell from './footer-cell';
|
||||||
import _ from './utils';
|
import _ from './utils';
|
||||||
|
|
||||||
const Footer = (props) => {
|
const Footer = (props) => {
|
||||||
const { data, className, columns, selectRow, expandRow } = props;
|
const { data, className, columns, selectRow, expandRow } = props;
|
||||||
const SelectionFooterCellComp = () => <th />;
|
|
||||||
const ExpansionFooterCellComp = () => <th />;
|
|
||||||
|
|
||||||
const isRenderFunctionColumnInLeft = (
|
function renderContent() {
|
||||||
position = Const.INDICATOR_POSITION_LEFT
|
return columns.map((column, i) => {
|
||||||
) => position === Const.INDICATOR_POSITION_LEFT;
|
|
||||||
|
|
||||||
const childrens = columns.map((column, i) => {
|
|
||||||
if (column.footer === undefined || column.footer === null) {
|
if (column.footer === undefined || column.footer === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -31,28 +26,17 @@ const Footer = (props) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (selectRow && selectRow.hideSelectColumn !== true) {
|
|
||||||
if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
|
|
||||||
childrens.unshift(<SelectionFooterCellComp key="selection" />);
|
|
||||||
} else {
|
|
||||||
childrens.push(<SelectionFooterCellComp key="selection" />);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (expandRow.showExpandColumn) {
|
|
||||||
if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
|
|
||||||
childrens.unshift(<ExpansionFooterCellComp key="expansion" />);
|
|
||||||
} else {
|
|
||||||
childrens.push(<ExpansionFooterCellComp key="expansion" />);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr className={ className }>
|
<RowTemplate
|
||||||
{ childrens }
|
renderContent={ renderContent }
|
||||||
</tr>
|
selectRow={ selectRow }
|
||||||
|
expandRow={ expandRow }
|
||||||
|
className={ className }
|
||||||
|
cellEl="th"
|
||||||
|
/>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
export default ExtendBase =>
|
export default ExtendBase =>
|
||||||
class ColumnResolver extends ExtendBase {
|
class ColumnResolver extends ExtendBase {
|
||||||
visibleColumnSize(includeSelectColumn = true) {
|
visibleColumnSize(includeSelectColumn = true) {
|
||||||
let columnLen = this.props.columns.filter(c => !c.hidden).length;
|
let columnLen;
|
||||||
|
if (this.props.columnToggle && this.props.columnToggle.toggles) {
|
||||||
|
const columns = this.props.columnToggle.toggles;
|
||||||
|
columnLen = Object.keys(columns).filter(name => columns[name]).length;
|
||||||
|
} else {
|
||||||
|
columnLen = this.props.columns.filter(c => !c.hidden).length;
|
||||||
|
}
|
||||||
if (!includeSelectColumn) return columnLen;
|
if (!includeSelectColumn) return columnLen;
|
||||||
if (this.props.selectRow && !this.props.selectRow.hideSelectColumn) {
|
if (this.props.selectRow && !this.props.selectRow.hideSelectColumn) {
|
||||||
columnLen += 1;
|
columnLen += 1;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export default class ExpandCell extends Component {
|
|||||||
if (tabIndex !== -1) attrs.tabIndex = tabIndex;
|
if (tabIndex !== -1) attrs.tabIndex = tabIndex;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<td onClick={ this.handleClick } { ...attrs }>
|
<td className="expand-cell" onClick={ this.handleClick } { ...attrs }>
|
||||||
{
|
{
|
||||||
expandColumnRenderer ? expandColumnRenderer({
|
expandColumnRenderer ? expandColumnRenderer({
|
||||||
expandable,
|
expandable,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export default class ExpansionHeaderCell extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<th data-row-selection { ...attrs }>
|
<th className="expand-cell-header" data-row-selection { ...attrs }>
|
||||||
{
|
{
|
||||||
expandHeaderColumnRenderer ?
|
expandHeaderColumnRenderer ?
|
||||||
expandHeaderColumnRenderer({ isAnyExpands }) :
|
expandHeaderColumnRenderer({ isAnyExpands }) :
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export default (Component) => {
|
|||||||
const key = props.value;
|
const key = props.value;
|
||||||
const selected = _.contains(selectRow.selected, key);
|
const selected = _.contains(selectRow.selected, key);
|
||||||
const selectable = !selectRow.nonSelectable || !_.contains(selectRow.nonSelectable, key);
|
const selectable = !selectRow.nonSelectable || !_.contains(selectRow.nonSelectable, key);
|
||||||
|
const notSelectable = _.contains(selectRow.nonSelectable, key);
|
||||||
|
|
||||||
let {
|
let {
|
||||||
style,
|
style,
|
||||||
@@ -38,6 +39,22 @@ export default (Component) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (notSelectable) {
|
||||||
|
const notSelectableStyle = _.isFunction(selectRow.nonSelectableStyle)
|
||||||
|
? selectRow.nonSelectableStyle(props.row, props.rowIndex)
|
||||||
|
: selectRow.nonSelectableStyle;
|
||||||
|
|
||||||
|
const notSelectableClasses = _.isFunction(selectRow.nonSelectableClasses)
|
||||||
|
? selectRow.nonSelectableClasses(props.row, props.rowIndex)
|
||||||
|
: selectRow.nonSelectableClasses;
|
||||||
|
|
||||||
|
style = {
|
||||||
|
...style,
|
||||||
|
...notSelectableStyle
|
||||||
|
};
|
||||||
|
className = cs(className, notSelectableClasses) || undefined;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Component
|
<Component
|
||||||
{ ...props }
|
{ ...props }
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export default class SelectionCell extends Component {
|
|||||||
<BootstrapContext.Consumer>
|
<BootstrapContext.Consumer>
|
||||||
{
|
{
|
||||||
({ bootstrap4 }) => (
|
({ bootstrap4 }) => (
|
||||||
<td onClick={ this.handleClick } { ...attrs }>
|
<td className="selection-cell" onClick={ this.handleClick } { ...attrs }>
|
||||||
{
|
{
|
||||||
selectionRenderer ? selectionRenderer({
|
selectionRenderer ? selectionRenderer({
|
||||||
mode: inputType,
|
mode: inputType,
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ export default class SelectionHeaderCell extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<th data-row-selection { ...attrs }>{ content }</th>
|
<th className="selection-cell-header" data-row-selection { ...attrs }>{ content }</th>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
48
packages/react-bootstrap-table2/src/row/row-template.js
vendored
Normal file
48
packages/react-bootstrap-table2/src/row/row-template.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/* eslint react/require-default-props: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
import Const from '../const';
|
||||||
|
|
||||||
|
const RowTemplate = (props) => {
|
||||||
|
const {
|
||||||
|
renderContent,
|
||||||
|
selectRow,
|
||||||
|
expandRow,
|
||||||
|
cellEl,
|
||||||
|
...rest
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const isRenderFunctionColumnInLeft = (
|
||||||
|
position = Const.INDICATOR_POSITION_LEFT
|
||||||
|
) => position === Const.INDICATOR_POSITION_LEFT;
|
||||||
|
|
||||||
|
const childrens = renderContent() || [];
|
||||||
|
|
||||||
|
if (selectRow && selectRow.hideSelectColumn !== true) {
|
||||||
|
if (isRenderFunctionColumnInLeft(selectRow.selectColumnPosition)) {
|
||||||
|
childrens.unshift(React.createElement(cellEl, { key: 'selection' }));
|
||||||
|
} else {
|
||||||
|
childrens.push(React.createElement(cellEl, { key: 'selection' }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expandRow.showExpandColumn) {
|
||||||
|
if (isRenderFunctionColumnInLeft(expandRow.expandColumnPosition)) {
|
||||||
|
childrens.unshift(React.createElement(cellEl, { key: 'expansion' }));
|
||||||
|
} else {
|
||||||
|
childrens.push(React.createElement(cellEl, { key: 'expansion' }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return <tr { ...rest }>{ childrens }</tr>;
|
||||||
|
};
|
||||||
|
|
||||||
|
RowTemplate.propTypes = {
|
||||||
|
renderContent: PropTypes.func.isRequired,
|
||||||
|
cellEl: PropTypes.string.isRequired,
|
||||||
|
selectRow: PropTypes.object,
|
||||||
|
expandRow: PropTypes.object
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RowTemplate;
|
||||||
@@ -48,7 +48,7 @@ describe('Footer', () => {
|
|||||||
|
|
||||||
describe('simplest footer', () => {
|
describe('simplest footer', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallow(
|
wrapper = render(
|
||||||
<Footer
|
<Footer
|
||||||
data={ data }
|
data={ data }
|
||||||
columns={ columns }
|
columns={ columns }
|
||||||
@@ -61,7 +61,7 @@ describe('Footer', () => {
|
|||||||
it('should render successfully', () => {
|
it('should render successfully', () => {
|
||||||
expect(wrapper.length).toBe(1);
|
expect(wrapper.length).toBe(1);
|
||||||
expect(wrapper.find('tr').length).toBe(1);
|
expect(wrapper.find('tr').length).toBe(1);
|
||||||
expect(wrapper.find(FooterCell).length).toBe(columns.length);
|
expect(wrapper.find('th').length).toBe(columns.length);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ describe('Footer', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when selecrRow prop is enable', () => {
|
describe('when selectRow prop is enable', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = render(
|
wrapper = render(
|
||||||
<Footer
|
<Footer
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
exports[`<SelectionCell /> render should render component correctly 1`] = `
|
exports[`<SelectionCell /> render should render component correctly 1`] = `
|
||||||
<td
|
<td
|
||||||
|
className="selection-cell"
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
|
|||||||
Reference in New Issue
Block a user