Skip to content

Commit 564379a

Browse files
committed
Improve performance
2 parents bc0be37 + 707dcb6 commit 564379a

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/TableBody.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var isFun=function(obj){
1313
class TableBody extends React.Component{
1414

1515
constructor(props) {
16-
super(props);
16+
super(props);
1717
this.state = {
1818
currEditCell: null
1919
};
@@ -189,6 +189,7 @@ class TableBody extends React.Component{
189189
if(i == rowIndex-1){
190190
key = row[this.props.keyField];
191191
selectedRow = row;
192+
return false;
192193
}
193194
}, this);
194195
this.props.onSelectRow(selectedRow, isSelected);

src/TableColumn.js

+40-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,46 @@ import Const from './Const';
44
class TableColumn extends React.Component{
55

66
constructor(props) {
7-
super(props);
7+
super(props);
8+
}
9+
10+
shouldComponentUpdate(nextProps, nextState) {
11+
const { children } = this.props;
12+
let shouldUpdated = this.props.width !== nextProps.width
13+
|| this.props.className !== nextProps.className
14+
|| this.props.hidden !== nextProps.hidden
15+
|| this.props.dataAlign !== nextProps.dataAlign
16+
|| typeof children !== typeof nextProps.children
17+
|| (''+this.props.onEdit).toString() !== (''+nextProps.onEdit).toString()
18+
19+
if(shouldUpdated){
20+
return shouldUpdated;
21+
}
22+
23+
if(typeof children === 'object') {
24+
if(children.props.dangerouslySetInnerHTML) {
25+
shouldUpdated = shouldUpdated ||
26+
children.props.dangerouslySetInnerHTML.__html !==
27+
nextProps.children.props.dangerouslySetInnerHTML.__html;
28+
} else if(children.props.type === 'checkbox' || children.props.type === 'radio') {
29+
shouldUpdated = shouldUpdated ||
30+
children.props.type !== nextProps.children.props.type ||
31+
children.props.checked !== nextProps.children.props.checked;
32+
}
33+
} else {
34+
shouldUpdated = shouldUpdated || children !== nextProps.children;
35+
}
36+
37+
if(shouldUpdated){
38+
return shouldUpdated;
39+
}
40+
41+
if(!(this.props.cellEdit && nextProps.cellEdit)) {
42+
return false;
43+
} else {
44+
return shouldUpdated
45+
|| this.props.cellEdit.mode !== nextProps.cellEdit.mode;
46+
}
847
}
948

1049
handleCellEdit(e){

0 commit comments

Comments
 (0)