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

event listener for sorting

Open shasanka opened this issue 6 years ago • 7 comments

Is there a way to add event listener to sorting in the table column headers. For example, if I click on the table header it sorts it in "asc" or "desc" order, but what I want is when user clicks on it, I should be able to get the state of sorting and then store it in react state so that even if user moves to another page and returns back, his sorting state should be same which he selected previously instead of sorting again. Please let me know for any doubts.

shasanka avatar May 27 '20 16:05 shasanka

did you try this? onOrderChange(orderedColumnId, orderDirection)

hongjs avatar May 28 '20 04:05 hongjs

did you try this? onOrderChange(orderedColumnId, orderDirection)

Hi thankyou for you reply. I have tried onOrderChange(orderedColumnId, orderDirection), here the issue is, sometimes orderedColumnId goes to -1 and I am not sure why and my second issue is even if I get column Id how do I set "asc" or "desc" on a specific column which user has selected even if page is refreshed.

shasanka avatar May 28 '20 15:05 shasanka

Ordered Column id will be -1 if no sorting is taking place and the data is not sorted . You need to persist the current sorting for example adding it to the URL and set the default sorting of the columns of the URL has the appropriate parameters on render.

Domino987 avatar May 29 '20 06:05 Domino987

this could help options: { thirdSortClick: false }

hongjs avatar May 29 '20 07:05 hongjs

Ordered Column id will be -1 if no sorting is taking place and the data is not sorted . You need to persist the current sorting for example adding it to the URL and set the default sorting of the columns of the URL has the appropriate parameters on render.

I understand, Thankyou

shasanka avatar May 29 '20 15:05 shasanka

this could help options: { thirdSortClick: false }

That worked, thankyou

shasanka avatar May 29 '20 15:05 shasanka

Looks like this has been resolved. Feel free to reopen if it's not resolved.

matthewoestreich avatar May 31 '20 13:05 matthewoestreich