Skip to content

Commit

Permalink
Improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Jan 14, 2016
2 parents bc0be37 + 707dcb6 commit 564379a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/TableBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var isFun=function(obj){
class TableBody extends React.Component{

constructor(props) {
super(props);
super(props);
this.state = {
currEditCell: null
};
Expand Down Expand Up @@ -189,6 +189,7 @@ class TableBody extends React.Component{
if(i == rowIndex-1){
key = row[this.props.keyField];
selectedRow = row;
return false;
}
}, this);
this.props.onSelectRow(selectedRow, isSelected);
Expand Down
41 changes: 40 additions & 1 deletion src/TableColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,46 @@ import Const from './Const';
class TableColumn extends React.Component{

constructor(props) {
super(props);
super(props);
}

shouldComponentUpdate(nextProps, nextState) {
const { children } = this.props;
let shouldUpdated = this.props.width !== nextProps.width
|| this.props.className !== nextProps.className
|| this.props.hidden !== nextProps.hidden
|| this.props.dataAlign !== nextProps.dataAlign
|| typeof children !== typeof nextProps.children
|| (''+this.props.onEdit).toString() !== (''+nextProps.onEdit).toString()

if(shouldUpdated){
return shouldUpdated;
}

if(typeof children === 'object') {
if(children.props.dangerouslySetInnerHTML) {
shouldUpdated = shouldUpdated ||
children.props.dangerouslySetInnerHTML.__html !==
nextProps.children.props.dangerouslySetInnerHTML.__html;
} else if(children.props.type === 'checkbox' || children.props.type === 'radio') {
shouldUpdated = shouldUpdated ||
children.props.type !== nextProps.children.props.type ||
children.props.checked !== nextProps.children.props.checked;
}
} else {
shouldUpdated = shouldUpdated || children !== nextProps.children;
}

if(shouldUpdated){
return shouldUpdated;
}

if(!(this.props.cellEdit && nextProps.cellEdit)) {
return false;
} else {
return shouldUpdated
|| this.props.cellEdit.mode !== nextProps.cellEdit.mode;
}
}

handleCellEdit(e){
Expand Down

0 comments on commit 564379a

Please sign in to comment.