mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
temp fix
This commit is contained in:
parent
41212fdc55
commit
e1986e3e38
@ -1,10 +1,10 @@
|
|||||||
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 cellEditFactory from 'react-bootstrap-table2-editor';
|
||||||
import { productsGenerator } from 'utils/common';
|
import { productsGenerator } from 'utils/common';
|
||||||
|
|
||||||
const products = productsGenerator(5);
|
const products = productsGenerator(2000);
|
||||||
|
|
||||||
const columns = [{
|
const columns = [{
|
||||||
dataField: 'id',
|
dataField: 'id',
|
||||||
@ -17,15 +17,41 @@ const columns = [{
|
|||||||
text: 'Product Price'
|
text: 'Product Price'
|
||||||
}];
|
}];
|
||||||
|
|
||||||
export default () => (
|
// cellEdit={ cellEditFactory({
|
||||||
<div>
|
// mode: 'click'
|
||||||
<BootstrapTable
|
// }) }
|
||||||
keyField="id"
|
|
||||||
data={ products }
|
// const expandRow = {
|
||||||
columns={ columns }
|
// renderer: row => (
|
||||||
cellEdit={ cellEditFactory({
|
// <div>
|
||||||
mode: 'click'
|
// <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>
|
// </div>
|
||||||
);
|
// )
|
||||||
|
// };
|
||||||
|
|
||||||
|
const selectRow = {
|
||||||
|
mode: 'checkbox',
|
||||||
|
clickToSelect: true,
|
||||||
|
bgColor: 'red'
|
||||||
|
// selected: [2],
|
||||||
|
// hideSelectColumn: true
|
||||||
|
// clickToEdit: true
|
||||||
|
};
|
||||||
|
|
||||||
|
/* eslint react/prefer-stateless-function: 0 */
|
||||||
|
export default class Table extends React.PureComponent {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<BootstrapTable
|
||||||
|
keyField="id"
|
||||||
|
data={ products }
|
||||||
|
columns={ columns }
|
||||||
|
selectRow={ selectRow }
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
11
packages/react-bootstrap-table2/src/body.js
vendored
11
packages/react-bootstrap-table2/src/body.js
vendored
@ -5,7 +5,7 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
import _ from './utils';
|
import _ from './utils';
|
||||||
import Row from './row';
|
import Row from './simple-row';
|
||||||
import RowAggregator from './row-aggregator';
|
import RowAggregator from './row-aggregator';
|
||||||
import RowSection from './row-section';
|
import RowSection from './row-section';
|
||||||
import Const from './const';
|
import Const from './const';
|
||||||
@ -18,6 +18,7 @@ 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() {
|
||||||
@ -54,9 +55,9 @@ class Body extends React.Component {
|
|||||||
RowComponent = bindExpansion(RowAggregator, visibleColumnSize);
|
RowComponent = bindExpansion(RowAggregator, visibleColumnSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectRowEnabled) {
|
// if (selectRowEnabled) {
|
||||||
RowComponent = bindSelection(expandRowEnabled ? RowComponent : RowAggregator);
|
// RowComponent = bindSelection(expandRowEnabled ? RowComponent : RowAggregator);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (cellEdit.createContext) {
|
if (cellEdit.createContext) {
|
||||||
RowComponent = cellEdit.bindRowLevelCellEdit(RowComponent, selectRowEnabled, keyField, _);
|
RowComponent = cellEdit.bindRowLevelCellEdit(RowComponent, selectRowEnabled, keyField, _);
|
||||||
@ -85,7 +86,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 <RowComponent { ...baseRowProps } />;
|
return <this.RowComponent { ...baseRowProps } />;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
packages/react-bootstrap-table2/src/cell.js
vendored
5
packages/react-bootstrap-table2/src/cell.js
vendored
@ -73,7 +73,10 @@ class Cell extends Component {
|
|||||||
formatExtraData
|
formatExtraData
|
||||||
} = column;
|
} = column;
|
||||||
const attrs = { ...rest };
|
const attrs = { ...rest };
|
||||||
let content = column.isDummyField ? null : _.get(row, dataField);
|
let content = this.props.children;
|
||||||
|
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);
|
||||||
|
|||||||
48
packages/react-bootstrap-table2/src/row-aggregator-content.js
vendored
Normal file
48
packages/react-bootstrap-table2/src/row-aggregator-content.js
vendored
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/* 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;
|
||||||
@ -3,34 +3,45 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import _ from './utils';
|
import _ from './utils';
|
||||||
import Row from './row';
|
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 ExpandCell from './row-expand/expand-cell';
|
||||||
import SelectionCell from './row-selection/selection-cell';
|
import SelectionCell from './row-selection/selection-cell';
|
||||||
import shouldRowUpdater from './row-should-updater';
|
// import Cell from './cell';
|
||||||
|
import eventDelegater from './row-event-delegater';
|
||||||
|
|
||||||
export default class RowAggregator extends shouldRowUpdater(React.Component) {
|
export default class RowAggregator extends shouldRowUpdater(eventDelegater(React.Component)) {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
attrs: PropTypes.object
|
attrs: PropTypes.object,
|
||||||
|
style: PropTypes.object
|
||||||
}
|
}
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
attrs: {}
|
attrs: {},
|
||||||
|
style: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.clickNum = 0;
|
this.clickNum = 0;
|
||||||
|
this.shouldUpdateRowContent = false;
|
||||||
this.createClickEventHandler = this.createClickEventHandler.bind(this);
|
this.createClickEventHandler = this.createClickEventHandler.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps) {
|
shouldComponentUpdate(nextProps) {
|
||||||
const shouldUpdate =
|
if (
|
||||||
this.props.selected !== nextProps.selected ||
|
this.props.selected !== nextProps.selected ||
|
||||||
this.props.expanded !== nextProps.expanded ||
|
this.props.expanded !== nextProps.expanded ||
|
||||||
this.props.selectable !== nextProps.selectable ||
|
this.props.selectable !== nextProps.selectable ||
|
||||||
this.shouldUpdateByWhenEditing(nextProps) ||
|
this.shouldUpdateByWhenEditing(nextProps) ||
|
||||||
this.shouldUpdatedByNormalProps(nextProps);
|
this.shouldUpdatedBySelfProps(nextProps)
|
||||||
|
) {
|
||||||
|
this.shouldUpdateRowContent = this.shouldUpdatedByNormalProps(nextProps);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
this.shouldUpdateRowContent = this.shouldUpdatedByNormalProps(nextProps);
|
||||||
|
|
||||||
return shouldUpdate;
|
return this.shouldUpdateRowContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
createClickEventHandler(cb) {
|
createClickEventHandler(cb) {
|
||||||
@ -91,53 +102,77 @@ export default class RowAggregator extends shouldRowUpdater(React.Component) {
|
|||||||
selectable,
|
selectable,
|
||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const key = _.get(row, keyField);
|
const key = _.get(row, keyField);
|
||||||
const { hideSelectColumn, clickToSelect } = selectRow;
|
const { hideSelectColumn, clickToSelect } = selectRow;
|
||||||
const { showExpandColumn } = expandRow;
|
const { showExpandColumn } = expandRow;
|
||||||
|
|
||||||
const newAttrs = { ...attrs };
|
const newAttrs = this.delegate({ ...attrs });
|
||||||
if (clickToSelect || !!expandRow.renderer) {
|
if (clickToSelect || !!expandRow.renderer) {
|
||||||
newAttrs.onClick = this.createClickEventHandler(attrs.onClick);
|
newAttrs.onClick = this.createClickEventHandler(newAttrs.onClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row
|
<tr
|
||||||
shouldUpdate
|
|
||||||
key={ key }
|
|
||||||
row={ row }
|
|
||||||
keyField={ keyField }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columns={ columns }
|
|
||||||
style={ style }
|
style={ style }
|
||||||
className={ className }
|
className={ className }
|
||||||
attrs={ newAttrs }
|
{ ...newAttrs }
|
||||||
{ ...rest }
|
|
||||||
>
|
>
|
||||||
{
|
<td>123</td>
|
||||||
showExpandColumn ? (
|
<td>12121212</td>
|
||||||
<ExpandCell
|
</tr>
|
||||||
{ ...expandRow }
|
|
||||||
rowKey={ key }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
expanded={ expanded }
|
|
||||||
/>
|
|
||||||
) : null
|
|
||||||
}
|
|
||||||
{
|
|
||||||
!hideSelectColumn
|
|
||||||
? (
|
|
||||||
<SelectionCell
|
|
||||||
{ ...selectRow }
|
|
||||||
rowKey={ key }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
selected={ selected }
|
|
||||||
disabled={ !selectable }
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
</Row>
|
|
||||||
);
|
);
|
||||||
|
// 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>
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
113
packages/react-bootstrap-table2/src/row-pure-content.js
vendored
Normal file
113
packages/react-bootstrap-table2/src/row-pure-content.js
vendored
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/* eslint react/prop-types: 0 */
|
||||||
|
/* eslint react/no-array-index-key: 0 */
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import _ from './utils';
|
||||||
|
import Cell from './cell';
|
||||||
|
|
||||||
|
export default class RowContent extends React.Component {
|
||||||
|
// shouldComponentUpdate(nextProps) {
|
||||||
|
// return this.shouldUpdatedByNormalProps(nextProps);
|
||||||
|
// }
|
||||||
|
shouldComponentUpdate(nextProps) {
|
||||||
|
if (typeof this.props.shouldUpdate !== 'undefined') {
|
||||||
|
if (nextProps.shouldUpdate === this.props.shouldUpdate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
row,
|
||||||
|
keyField,
|
||||||
|
columns,
|
||||||
|
rowIndex,
|
||||||
|
editable,
|
||||||
|
editingRowIdx,
|
||||||
|
editingColIdx,
|
||||||
|
onStart,
|
||||||
|
clickToEdit,
|
||||||
|
dbclickToEdit,
|
||||||
|
EditingCellComponent
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
return columns.map((column, index) => {
|
||||||
|
if (!column.hidden) {
|
||||||
|
const { dataField } = column;
|
||||||
|
const content = _.get(row, dataField);
|
||||||
|
if (rowIndex === editingRowIdx && index === editingColIdx) {
|
||||||
|
return (
|
||||||
|
<EditingCellComponent
|
||||||
|
key={ `${content}-${index}-editing` }
|
||||||
|
row={ row }
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
column={ column }
|
||||||
|
columnIndex={ index }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// render cell
|
||||||
|
let cellTitle;
|
||||||
|
let cellStyle = {};
|
||||||
|
const cellAttrs = {
|
||||||
|
..._.isFunction(column.attrs)
|
||||||
|
? column.attrs(content, row, rowIndex, index)
|
||||||
|
: column.attrs,
|
||||||
|
...column.events
|
||||||
|
};
|
||||||
|
|
||||||
|
const cellClasses = _.isFunction(column.classes)
|
||||||
|
? column.classes(content, row, rowIndex, index)
|
||||||
|
: column.classes;
|
||||||
|
|
||||||
|
if (column.style) {
|
||||||
|
cellStyle = _.isFunction(column.style)
|
||||||
|
? column.style(content, row, rowIndex, index)
|
||||||
|
: column.style;
|
||||||
|
cellStyle = Object.assign({}, cellStyle) || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.title) {
|
||||||
|
cellTitle = _.isFunction(column.title)
|
||||||
|
? column.title(content, row, rowIndex, index)
|
||||||
|
: content;
|
||||||
|
cellAttrs.title = cellTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (column.align) {
|
||||||
|
cellStyle.textAlign =
|
||||||
|
_.isFunction(column.align)
|
||||||
|
? column.align(content, row, rowIndex, index)
|
||||||
|
: column.align;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cellClasses) cellAttrs.className = cellClasses;
|
||||||
|
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
|
||||||
|
|
||||||
|
let editableCell = _.isDefined(column.editable) ? column.editable : true;
|
||||||
|
if (column.dataField === keyField || !editable) editableCell = false;
|
||||||
|
if (_.isFunction(column.editable)) {
|
||||||
|
editableCell = column.editable(content, row, rowIndex, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Cell
|
||||||
|
key={ `${content}-${index}` }
|
||||||
|
row={ row }
|
||||||
|
editable={ editableCell }
|
||||||
|
rowIndex={ rowIndex }
|
||||||
|
columnIndex={ index }
|
||||||
|
column={ column }
|
||||||
|
onStart={ onStart }
|
||||||
|
clickToEdit={ clickToEdit }
|
||||||
|
dbclickToEdit={ dbclickToEdit }
|
||||||
|
{ ...cellAttrs }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -43,15 +43,20 @@ export default (Component) => {
|
|||||||
{ ...props }
|
{ ...props }
|
||||||
style={ style }
|
style={ style }
|
||||||
className={ className }
|
className={ className }
|
||||||
selectRow={ { ...selectRow } }
|
selectRow={ selectRow }
|
||||||
selected={ selected }
|
selected={ selected }
|
||||||
selectable={ selectable }
|
selectable={ selectable }
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
return props => (
|
function withSelectionConsumer(props) {
|
||||||
<SelectionContext.Consumer>
|
return (
|
||||||
{ selectRow => renderWithSelection(props, selectRow) }
|
<SelectionContext.Consumer>
|
||||||
</SelectionContext.Consumer>
|
{ selectRow => renderWithSelection(props, selectRow) }
|
||||||
);
|
</SelectionContext.Consumer>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
withSelectionConsumer.displayName = 'WithSelectionConsumer';
|
||||||
|
return withSelectionConsumer;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -19,17 +19,17 @@ export default class SelectionCell extends Component {
|
|||||||
selectionRenderer: PropTypes.func
|
selectionRenderer: PropTypes.func
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor(props) {
|
||||||
super();
|
super(props);
|
||||||
this.handleClick = this.handleClick.bind(this);
|
this.handleClick = this.handleClick.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps) {
|
shouldComponentUpdate(nextProps) {
|
||||||
const shouldUpdate =
|
const shouldUpdate =
|
||||||
this.props.rowIndex !== nextProps.rowIndex ||
|
|
||||||
this.props.selected !== nextProps.selected ||
|
this.props.selected !== nextProps.selected ||
|
||||||
this.props.disabled !== nextProps.disabled ||
|
this.props.rowKey !== nextProps.rowKey ||
|
||||||
this.props.rowKey !== nextProps.rowKey;
|
this.props.rowIndex !== nextProps.rowIndex ||
|
||||||
|
this.props.disabled !== nextProps.disabled;
|
||||||
|
|
||||||
return shouldUpdate;
|
return shouldUpdate;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,14 +11,20 @@ export default ExtendBase =>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldUpdatedBySelfProps(nextProps) {
|
||||||
|
return (
|
||||||
|
this.props.className !== nextProps.className ||
|
||||||
|
!_.isEqual(this.props.style, nextProps.style) ||
|
||||||
|
!_.isEqual(this.props.attrs, nextProps.attrs)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
shouldUpdatedByNormalProps(nextProps) {
|
shouldUpdatedByNormalProps(nextProps) {
|
||||||
const shouldUpdate =
|
const shouldUpdate =
|
||||||
this.props.rowIndex !== nextProps.rowIndex ||
|
this.props.rowIndex !== nextProps.rowIndex ||
|
||||||
this.props.className !== nextProps.className ||
|
|
||||||
this.props.editable !== nextProps.editable ||
|
this.props.editable !== nextProps.editable ||
|
||||||
this.props.columns.length !== nextProps.columns.length ||
|
this.props.columns.length !== nextProps.columns.length ||
|
||||||
!_.isEqual(this.props.row, nextProps.row) ||
|
!_.isEqual(this.props.row, nextProps.row);
|
||||||
!_.isEqual(this.props.style, nextProps.style);
|
|
||||||
|
|
||||||
return shouldUpdate;
|
return shouldUpdate;
|
||||||
}
|
}
|
||||||
|
|||||||
146
packages/react-bootstrap-table2/src/row.js
vendored
146
packages/react-bootstrap-table2/src/row.js
vendored
@ -1,146 +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 _ from './utils';
|
|
||||||
import Cell from './cell';
|
|
||||||
import eventDelegater from './row-event-delegater';
|
|
||||||
import shouldRowUpdater from './row-should-updater';
|
|
||||||
|
|
||||||
class Row extends shouldRowUpdater(eventDelegater(Component)) {
|
|
||||||
shouldComponentUpdate(nextProps) {
|
|
||||||
console.log('lol');
|
|
||||||
const shouldUpdate =
|
|
||||||
nextProps.shouldUpdate ||
|
|
||||||
this.shouldUpdateByWhenEditing(nextProps) ||
|
|
||||||
this.shouldUpdatedByNormalProps(nextProps);
|
|
||||||
|
|
||||||
return shouldUpdate;
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const {
|
|
||||||
row,
|
|
||||||
keyField,
|
|
||||||
columns,
|
|
||||||
rowIndex,
|
|
||||||
className,
|
|
||||||
style,
|
|
||||||
attrs,
|
|
||||||
editable,
|
|
||||||
editingRowIdx,
|
|
||||||
editingColIdx,
|
|
||||||
onStart,
|
|
||||||
clickToEdit,
|
|
||||||
dbclickToEdit
|
|
||||||
} = this.props;
|
|
||||||
const trAttrs = this.delegate(attrs);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<tr style={ style } className={ className } { ...trAttrs }>
|
|
||||||
{ this.props.children }
|
|
||||||
{
|
|
||||||
columns.map((column, index) => {
|
|
||||||
if (!column.hidden) {
|
|
||||||
const { dataField } = column;
|
|
||||||
const content = _.get(row, dataField);
|
|
||||||
if (rowIndex === editingRowIdx && index === editingColIdx) {
|
|
||||||
const EditingCell = this.props.EditingCellComponent;
|
|
||||||
return (
|
|
||||||
<EditingCell
|
|
||||||
key={ `${content}-${index}-editing` }
|
|
||||||
row={ row }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
column={ column }
|
|
||||||
columnIndex={ index }
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// render cell
|
|
||||||
let cellTitle;
|
|
||||||
let cellStyle = {};
|
|
||||||
const cellAttrs = {
|
|
||||||
..._.isFunction(column.attrs)
|
|
||||||
? column.attrs(content, row, rowIndex, index)
|
|
||||||
: column.attrs,
|
|
||||||
...column.events
|
|
||||||
};
|
|
||||||
|
|
||||||
const cellClasses = _.isFunction(column.classes)
|
|
||||||
? column.classes(content, row, rowIndex, index)
|
|
||||||
: column.classes;
|
|
||||||
|
|
||||||
if (column.style) {
|
|
||||||
cellStyle = _.isFunction(column.style)
|
|
||||||
? column.style(content, row, rowIndex, index)
|
|
||||||
: column.style;
|
|
||||||
cellStyle = Object.assign({}, cellStyle) || {};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (column.title) {
|
|
||||||
cellTitle = _.isFunction(column.title)
|
|
||||||
? column.title(content, row, rowIndex, index)
|
|
||||||
: content;
|
|
||||||
cellAttrs.title = cellTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (column.align) {
|
|
||||||
cellStyle.textAlign =
|
|
||||||
_.isFunction(column.align)
|
|
||||||
? column.align(content, row, rowIndex, index)
|
|
||||||
: column.align;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cellClasses) cellAttrs.className = cellClasses;
|
|
||||||
if (!_.isEmptyObject(cellStyle)) cellAttrs.style = cellStyle;
|
|
||||||
|
|
||||||
let editableCell = _.isDefined(column.editable) ? column.editable : true;
|
|
||||||
if (column.dataField === keyField || !editable) editableCell = false;
|
|
||||||
if (_.isFunction(column.editable)) {
|
|
||||||
editableCell = column.editable(content, row, rowIndex, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Cell
|
|
||||||
key={ `${content}-${index}` }
|
|
||||||
row={ row }
|
|
||||||
editable={ editableCell }
|
|
||||||
rowIndex={ rowIndex }
|
|
||||||
columnIndex={ index }
|
|
||||||
column={ column }
|
|
||||||
onStart={ onStart }
|
|
||||||
clickToEdit={ clickToEdit }
|
|
||||||
dbclickToEdit={ dbclickToEdit }
|
|
||||||
{ ...cellAttrs }
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row.propTypes = {
|
|
||||||
row: PropTypes.object.isRequired,
|
|
||||||
rowIndex: PropTypes.number.isRequired,
|
|
||||||
columns: PropTypes.array.isRequired,
|
|
||||||
style: PropTypes.object,
|
|
||||||
className: PropTypes.string,
|
|
||||||
attrs: PropTypes.object,
|
|
||||||
shouldUpdate: PropTypes.bool
|
|
||||||
};
|
|
||||||
|
|
||||||
Row.defaultProps = {
|
|
||||||
editable: true,
|
|
||||||
style: {},
|
|
||||||
className: null,
|
|
||||||
attrs: {},
|
|
||||||
shouldUpdate: false
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Row;
|
|
||||||
56
packages/react-bootstrap-table2/src/simple-row.js
vendored
Normal file
56
packages/react-bootstrap-table2/src/simple-row.js
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/* 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';
|
||||||
|
|
||||||
|
class Row extends shouldRowUpdater(eventDelegater(Component)) {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.shouldUpdateRowContent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldComponentUpdate(nextProps) {
|
||||||
|
this.shouldUpdateRowContent = this.shouldUpdatedByNormalProps(nextProps);
|
||||||
|
if (this.shouldUpdateRowContent) return true;
|
||||||
|
|
||||||
|
return this.shouldUpdatedBySelfProps(nextProps);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const {
|
||||||
|
className,
|
||||||
|
style,
|
||||||
|
attrs,
|
||||||
|
...rest
|
||||||
|
} = this.props;
|
||||||
|
const trAttrs = this.delegate(attrs);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<tr style={ style } className={ className } { ...trAttrs }>
|
||||||
|
<RowContent shouldUpdate={ this.shouldUpdateRowContent } { ...rest } />
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Row.propTypes = {
|
||||||
|
row: PropTypes.object.isRequired,
|
||||||
|
rowIndex: PropTypes.number.isRequired,
|
||||||
|
columns: PropTypes.array.isRequired,
|
||||||
|
style: PropTypes.object,
|
||||||
|
className: PropTypes.string,
|
||||||
|
attrs: PropTypes.object
|
||||||
|
};
|
||||||
|
|
||||||
|
Row.defaultProps = {
|
||||||
|
editable: true,
|
||||||
|
style: {},
|
||||||
|
className: null,
|
||||||
|
attrs: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Row;
|
||||||
Loading…
Reference in New Issue
Block a user