primereact icon indicating copy to clipboard operation
primereact copied to clipboard

TreeTable: Custom sorting (for example from an API) needs better docs

Open SpajicM opened this issue 1 year ago • 9 comments

Describe the bug

Hi, I'm using onSort function to make an API call for sorting, but when onSort function is used, original icon highlight and toggling between ASC and DESC is lost.

Expected:

image

  • Highlight icon showing up
  • Click on arrows toggling the state between ASC and DESC (0 and 1)

Actual:

  • No indicator of sort being enabled
  • sortOrder in event is always 1

image

image

Reproducer

https://stackblitz.com/edit/vqw5gi-vnizjy?file=src%2FApp.jsx

PrimeReact version

9.5.0

React version

17.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

SpajicM avatar Mar 04 '24 09:03 SpajicM

Duplicate of #6115 which has a reproducer so subscribe to that ticket please.

melloware avatar Mar 10 '24 13:03 melloware

@melloware I have checked the other ticket - it's not the same issue. This one is about table-level "onSort" prop, the other one is column-level "sortFunction", and the behavior problem is different.

I'll try to put together a reproductor example ASAP. Thanks!

SpajicM avatar Mar 10 '24 14:03 SpajicM

ok if you add a reproducer i can re-open this one.

melloware avatar Mar 10 '24 14:03 melloware

@melloware Added reproductor and more details to description of the issue! Thank you.

SpajicM avatar Mar 11 '24 14:03 SpajicM

@melloware Hello! Can you assign me please ?

KirilCycle avatar May 07 '24 14:05 KirilCycle

@SpajicM The TreeTable works fine, you just need to manually connect the states to the TreeTable using the 'sortOrder' and 'sortField' properties:
BDF4CF59-4811-4A59-B121-3261806C5F84_1_201_a

KirilCycle avatar May 07 '24 15:05 KirilCycle

@KirilCycle oh, thanks! Is this documented anywhere or I've missed it?

TreeTable's main page only explains sortable and sortMode props, while API page for sortOrder says: "Order to sort the data by default.", which sounds like it's only for setting prefered initial order, not that it should be used in combination with onSort function.

SpajicM avatar May 07 '24 15:05 SpajicM

@KirilCycle oh, thanks! Is this documented anywhere or I've missed it?

Well, I didn't see it in the documentation, only descriptions of specific props

KirilCycle avatar May 07 '24 16:05 KirilCycle

I noticed that vueprime TreeTable doesn't need to pass options manually, I think we should modify the current TreeTable to have similar behaviour, as even props description says that 'sortField' and 'sortOrder' should be used at initial render

StackBlitz

KirilCycle avatar May 07 '24 16:05 KirilCycle