import React from 'react'; // Header component to be used as default for all the columns. export default class MyReactHeaderComponent extends React.Component { constructor(props) { super(props); this.props.column.addEventListener('sortChanged', this.onSortChanged.bind(this)); //The state of this component contains the current sort state of this column //The possible values are: 'asc', 'desc' and '' this.state = { sorted: '' } } render() { let sortElements = []; if (this.props.enableSorting){ let downArrowClass = "customSortDownLabel " + (this.state.sorted === 'desc' ? " active" : ""); let upArrowClass = "customSortUpLabel " + (this.state.sorted === 'asc' ? " active" : ""); let removeArrowClass = "customSortRemoveLabel " + (this.state.sorted === '' ? " active" : ""); sortElements.push(
) sortElements.push(
) sortElements.push(
) } let menuButton = null; if (this.props.enableMenu){ menuButton =
} return
{menuButton}
{this.props.displayName}
{sortElements}
} onSortRequested (order, event) { this.props.setSort (order, event.shiftKey); }; onSortChanged (){ if (this.props.column.isSortAscending()){ this.setState({ sorted: 'asc' }) } else if (this.props.column.isSortDescending()){ this.setState({ sorted: 'desc' }) } else { this.setState({ sorted: '' }) } }; onMenuClick (){ this.props.showColumnMenu (this.refs.menuButton); }; } // the grid will always pass in one props called 'params', // which is the grid passing you the params for the cellRenderer. // this piece is optional. the grid will always pass the 'params' // props, so little need for adding this validation meta-data. MyReactHeaderComponent.propTypes = { params: React.PropTypes.object };