React-table: Custom Header

Created on 30 Mar 2017  路  4Comments  路  Source: tannerlinsley/react-table

I am restyling your table. But I couldn't add a sort icon in the header.

Like:

| ___ Name ___ | ___ Age 馃” ___ |

I tried to tie into the header like so:
<ReactTable columns={ [ { accessor: 'age', header: ( { column } ) => ??? } ] } />

But maybe there is an even better solution to create a template for all the column-headers to add a font-awesome icon like <i className="fa fa-arrow-down"></i> in the end of the column (depending if it's sort ASC or DESC)

Any recommendations?

Most helpful comment

Why don't you use CSS for that?
Here's what I use:

div.-sort-asc::after {
content: "25BC";
float: right;
}
div.-sort-desc::after {
content: "25B2";
float: right;
}

All 4 comments

you need to add the header: () => <span><i className='fa-tasks' /> Progress</span>, as described in this section of the readme.

something like this should work...

const columns = [
  {
    header: () => (<span>Age<i className='fa fa-arrow-up' /></span>)
  }
];

I would render another small component outside of the header property and just include it, you can then use state to track whether its sorting ASC or DESC and adjust accordingly.

Yeah, I was aware of this, but I don't know the information which column is sorted and if ASC or DESC

Why don't you use CSS for that?
Here's what I use:

div.-sort-asc::after {
content: "25BC";
float: right;
}
div.-sort-desc::after {
content: "25B2";
float: right;
}

Both of those are perfectly fine examples. To discuss implementation more, please join the slack organization :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Codar97 picture Codar97  路  3Comments

ocalde picture ocalde  路  3Comments

DaveyEdwards picture DaveyEdwards  路  3Comments

Abdul-Hameed001 picture Abdul-Hameed001  路  3Comments

mellis481 picture mellis481  路  3Comments