I am trying to implement fixed columns in my react-data-grid.
I follow the example by adding locked: true
but it doesn't work, so I also try to use a custom row rendered, like the other example.
I get _this.refs[i].setScrollLeft is not a function
error. Trying the hacky comment on this same question also doesn't work for me (sorry not enought rep to comment!).
I also tried to create a custom cell render class, but still no luck.
I also try to use refs
the callback way instead:
class CellRenderer extends React.Component {
render() {
return <ReactDataGrid.Cell {...this.props}/>
}
};
class RowRenderer extends React.Component {
static propTypes = {
idx: React.PropTypes.string.isRequired
};
setScrollLeft = (scrollBy) => {
// if you want freeze columns to work, you need to make sure you implement this as apass through
this.row.setScrollLeft(scrollBy);
};
getRowStyle = () => {
return {
color: this.getRowBackground()
};
};
getRowBackground = () => {
return this.props.idx % 2 ? 'green' : 'blue';
};
render() {return (<div style={this.getRowStyle()}>
<ReactDataGrid.Row
{...this.props}
ref={r => { this.row = r; }}
cellRenderer={CellRenderer}
/>
</div>);
}
};
Any help is much appreciated!
EDIT: Trying many things, still no luck, but I've figured out that the setScrollLeft
method is never passed down to the Row
component, so maybe it is indeed a problem with refs and/or props passed.