Table
Custom Header Cell
Use the headerCell
render prop in a column definiton to
provide custom rendering control of all table header cells in that column.
See our Render Props Guide for additional information, including important considerations and examples.
Refer to the custom sortable header cell if your data is sortable.
Fruits | Vegetables | Grains | Dairy | Protein |
---|---|---|---|---|
Pomello | Bok Choi | Chia | Pule | Crickets |
Starfruit | Romanesco | Sorghum | Casu marzu | Barnacles |
Durian | Ramps | Teff | Vieux Lille | Inca nuts |
Persimmon | Fiddleheads | Quinoa | Milbenkase | Spirulina |
() => { const Root = styled('th')(({ theme }) => ({ padding: 0, verticalAlign: 'bottom', '&:not(:first-of-type)': { borderLeft: '1px dotted ' + theme.borderColor } })); const Inner = styled('span')(({theme}) => ({ alignItems: 'flex-end', display: 'flex', padding: pxToEm(12) + ' ' + theme.space_inline_md, whiteSpace: 'nowrap' })); const Content = styled('span')(({ theme }) => ({ fontSize: theme.fontSize_ui, fontWeight: theme.fontWeight_bold, textAlign: 'left' })); const Emoji = withProps({ 'aria-hidden': true, role: 'img' })(styled('span')(({ theme }) => ({ display: 'inline-block', marginRight: theme.space_inline_sm }) )); class CustomHeaderCell extends React.PureComponent { render() { const { children, emoji } = this.props; return ( <Root {...this.props}> <Inner> <Content> <Emoji>{emoji}</Emoji> {children} </Content> </Inner> </Root> ); } } const headerCell = ({ props }) => <CustomHeaderCell {...props} />; const columns = [ { content: 'Fruits', key: 'Fruits', emoji: 'π', headerCell }, { content: 'Vegetables', key: 'Vegetables', emoji: 'π₯', headerCell }, { content: 'Grains', key: 'Grains', emoji: 'πΎ', headerCell }, { content: 'Dairy', key: 'Dairy', emoji: 'π₯', headerCell }, { content: 'Protein', key: 'Protein', emoji: 'π', headerCell } ]; return ( <Table columns={columns} data={data} rowKey="Fruits" title="Delicious Foods" hideTitle /> ); }