3

this is the table i have and if i click any one of the heading id dosent sort

when i click on rank, location or deaths on top it used to sort the list before but now it doesn't work. The data you see is not all of the data i have used there is a few more that would just make the question long so i only added first few. Any help would be appreciated.

const

 data = [
        {
            location: 'Texas',
            deaths: '4,164',
            rank: 1
        },
        {
            location: 'California',
            deaths: '3,449',
            rank: 2
        }
    ]



  const columns = [
        {
          name: <h2>Rank</h2>,
          selector:  row => <h3>{row.rank}</h3>,
          sortable: true,
        },
        {
          name: <h2>Location</h2>,
          selector:  row => <h3>{row.location}</h3>,
          sortable: true,
        },
        {
          name: <h2>Deaths</h2>,
          selector:  row => <h3>{row.deaths}</h3>,
          sortable: true,
        }
      ];


  return (
    <div className='table_map'>
        <DataTable  
            data={data}
            columns={columns}
            print='true'
            theme="solarized"
            fixedHeader
            fixedHeaderScrollHeight="700px"
            customStyles = {customStyles }
        />
    </div>
  )
}
 
export default Table
 
2
  • Did you find a solution to this. Stuck here too Commented Jul 19, 2022 at 19:29
  • 1
    @Taio yeah for me it happened because i used h2 tags for name in columns section. I removed the h2 tags and it worked properly, hope it helps Commented Jul 20, 2022 at 7:26

1 Answer 1

0

It can help other people : use cell function to display data with h3 and remove h3 from selector it works for me :

const columns = [
       {
         name: <h2>Rank</h2>,
         selector:  row => row.rank,
         cell:  row => <h3>{row.rank}</h3>,
         sortable: true,
       },
       {
         name: <h2>Location</h2>,
         cell:  row => <h3>{row.location}</h3>,
         selector:  row => row.location,
         sortable: true,
       },
       {
         name: <h2>Deaths</h2>,
         selector:  row => row.deaths,
         cell:  row => <h3>{row.deaths}</h3>,
         sortable: true,
       }
     ];
Sign up to request clarification or add additional context in comments.

1 Comment

The selector works, but the cell doesn't re-render after each sorting change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.