question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Table: Add ability to customize header and sorter

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

It seems like right now there is no possibility to customize table’s header clickables such as sorter and filter, as well as their positions.

E.g. A lot of users are used to sorters with toggle logic tied to header title and sort icon being changed upon that action. There is already an open issue for this particular example.

But there, probably, could be more and ideally a solution would be flexible enough to cover other cases. Worth covering situations for when a specific column can be changed and not only on a table level.

With that being told, table should be able to provide ways to render custom header as well as to fire sorter callback. Adding such API will give developers to build their tables upon antd more easily.

What does the proposed API look like?

Below is a raw schematic API that supposedly explains the idea

static defaultProps = {
  ColumnHeader: (...args) => (
    <React.Fragment>
       {this.props.renderColumnTitle(...args)}
       {this.props.renderColumnSorter(...args)}
       {this.props.renderColumnFilter(...args)}
   </React.Fragment>
 )
}

...
// https://github.com/ant-design/ant-design/blob/bf5b6ae1f3b5da4629a7d10a2d1764eaa3fbbb04/components/table/Table.tsx#L760
column.title = (
  <span key={key}>
    {this.props.ColumnHeader(column, this.props, this, ...)}
  </span>
);



...
<Table
   renderColumnSorter: (col, props, ctx) => {
     const icon = col.sorter.order === 'ascend' ? 'up' : 'down';
     const direction = col.sorter.order === 'ascend' ? 'descend' : 'ascend;

      return <Button icon={icon} onClick={ctx.toggleSortOrder(direction) />
   }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

19reactions
afc163commented, Sep 17, 2018

I see, we could support passing function to title:

columns={[{
  title: (filters, sortOrder) => <div>Title</div>,
}]}
12reactions
vavdavcommented, Jun 12, 2020

@RixBai how do you hide default sort icons in the header?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Make Custom Sorting Headers in Tableau - phData
In this post, I'll be walking through how to create table headers in Tableau that allows your users to customize the sorting of...
Read more >
How to Make Custom Sorting Headers in Tableau - YouTube
Discover how to make custom sorting headers in Tableau with this step-by-step guide from Autumn Battani, a Tableau expert.
Read more >
Creating Custom Sort Headers - Viz Zen Data
The first thing you want to set up is your sort parameter because this will be the starting place to create the calculations...
Read more >
Sortable & Searchable Tables : TechWeb - Boston University
Adding the “sortable” class to a <table> element provides support for sorting by column value. Clicking the column headers will sort the table...
Read more >
Implementing Custom Sorting in Columns in JavaScript
To do that, import the MatSort directive and add mat-sort-header to each ... Once you've added sorting capability to your table using the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found