Material-table: Sorting with remote data

Created on 22 Sep 2020  路  9Comments  路  Source: mbrn/material-table

Using remote data.

  1. I click on column to sort by it
  2. I get correct orderBy and orderDirection (_asc_)
  3. I click on the same column to sort again.
  4. I get correct orderBy and incorrect orderDirection (_asc again, should be desc now_)
  5. I click on the same column to sort again, I expected sort to be disabled for this column now as I already clicked three times.
  6. I get incorrect orderBy (_should be null_) and incorrect orderDirection (desc, should be null now because it is third time I click sort)

Logs screen:

image

Material-table version: 1.69.0

bug

Most helpful comment

Not stale

All 9 comments

I'm also suffering from this issue

this is also the case is for the pagination and the search

Could you comment on this @mbrn ?

Ditto, I have the same problem. Waiting for response, thanks!

Actually i'm finding this table is totally useless.lot of issues are not resolving.there is problem with search also..

Also been having this issue for a while now.

I solved it with setting defaultSort for each field.
const [filter, setFilter] = useState({ field: "name", order: "asc" }) ... <MaterialTable columns={[ { field: "name", title: "name", defaultSort: sortField.order, ]} />
However, it has some drawbacks. When you change state, material table sorts your current data by order you provided, so there is glimpse of data visually getting sorted twice. You may change order state after your data is loaded as well to avoid such behaviour.

Not stale

I solved it with setting defaultSort for each field.
const [filter, setFilter] = useState({ field: "name", order: "asc" }) ... <MaterialTable columns={[ { field: "name", title: "name", defaultSort: sortField.order, ]} />
However, it has some drawbacks. When you change state, material table sorts your current data by order you provided, so there is glimpse of data visually getting sorted twice. You may change order state after your data is loaded as well to avoid such behaviour.

where does sortField come from ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mihier-Roy picture Mihier-Roy  路  3Comments

victorwvieira picture victorwvieira  路  3Comments

jlgreene2 picture jlgreene2  路  3Comments

VipinJoshi picture VipinJoshi  路  3Comments

KKrisu picture KKrisu  路  3Comments