Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table Title render function does not have enough information about the current column that is sorted #19007

Closed
1 task done
swillis12 opened this issue Sep 25, 2019 · 2 comments

Comments

@swillis12
Copy link
Contributor

swillis12 commented Sep 25, 2019

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

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Open the codesandbox console and click sort on name, observe the log message.

"ascend/descend, but no column name
Object {filters: Object, sortOrder: null}"

What is expected?

The object should contain the "dataIndex" of the currently sorted column/columns

What is actually happening?

DataIndex is not available to the title render function so the ascending/descending information cannot be used to render a header for a specific column.

Other

This has already been mentioned here a couple of times: #11246 (comment)

Environment Info
antd 3.23.4
React 16.9.0
System Mac OS X Mojave
Browser Chrome
@afc163
Copy link
Member

afc163 commented Sep 26, 2019

You already know which is the column when setting title.

const renderTitle = (dataIndex, info) => {
  console.log(dataIndex, info);
  return "Title";
};

...

  {
    title: (info) => renderTitle('name', info),
    dataIndex: "name",
    key: "name",
    render: text => <a>{text}</a>,
    sorter: (a, b) => (a.name > b.name ? (1 ? b.name > a.name : -1) : 0)
  },
  {
    title: (info) => renderTitle('age', info),
    dataIndex: "age",
    key: "age"
  },

@afc163 afc163 closed this as completed Sep 26, 2019
@swillis12
Copy link
Contributor Author

swillis12 commented Sep 26, 2019

@afc163 There is no way to tell which column is sorted from the info argument that is passed in in your example. All we get is "ascend/descend" regardless of which column is currently sorted.

E.g. Sort the age column "ascending" and the the info object passed to the renderTitle function for the NAME column will only contain { sortOrder: "ascend" } even though the name column is not even sorted.

PR Created on feature branch: #19012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants