material-table icon indicating copy to clipboard operation
material-table copied to clipboard

How to sort the data by clicking column (not only text or icon)

Open tkk777 opened this issue 5 years ago • 4 comments

I would like to ask how to sort the data by clicking column?

it is because data cannot be sorted when I click the column (not on column text or icon).

Thanks.

tkk777 avatar Aug 25 '21 02:08 tkk777

give all datas to material table. It can handle sort

kadirtereci avatar Aug 29 '21 10:08 kadirtereci

also if your column is numbers dont forget to give type: 'numeric' that column.

column must be like this;

  columns={[
    { title: 'Birth Year', field: 'birthYear', type: 'numeric' },
  ]}

you must add sorting:true to material table options

  options={{
    sorting: true
  }}

kadirtereci avatar Aug 29 '21 10:08 kadirtereci

If customized render function returns react components, sorting may not work. In this case you should set column.customSort like

columns={[
    {
        title: 'Birth Year',
        render: (row) => (<span class="birthYear">{row.birthYear}</span>),
        customSort: (a, b) => a.birthYear - b.birthYear
    },
]}

tian-lan-landing avatar Nov 05 '21 04:11 tian-lan-landing

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

stale[bot] avatar Feb 06 '22 16:02 stale[bot]