Column sortFunction documentation seems to be incorrect

UI Components for React
Post Reply
reid
Posts: 7
Joined: 12 Jul 2014, 20:30

26 Nov 2022, 23:17

The documentation for implementing a custom sortFunction seems to be incorrect.

The documentation gives this short code snippet:

Code: Select all

const mysort = (event) => {
    //event.data = Data
    //event.field = Field to sort
    //event.order = Sort order
    //event.multiSortMeta = An array of SortMeta objects to sort the data by default in multiple sort mode.
}
However, in practice (and when looking through the source code), the function takes a single parameter of type ColumnSortParams, which only has a field and order property. I don't have easy access to the table data where I implement my columns, so not passing it as part of the sortFunction event/parameters is causing me problems and is unexpected given the documentation.

Am I missing something?

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

02 Dec 2022, 18:59

I think you may not be looking at it correct its defined like this...

Code: Select all

interface ColumnSortMetaData {
    field: string;
    order: ColumnSortOrderType;
}

interface ColumnSortParams extends ColumnSortMetaData {
    data: any;
    multiSortMeta?: ColumnSortMetaData[];
}
Notice ColumnSortParams extends ColumnSortMetaData so the combined typescript object would look like this...

Code: Select all

interface ColumnSortParams extends ColumnSortMetaData {
    data: any;
     field: string;
    order: ColumnSortOrderType;
    multiSortMeta?: ColumnSortMetaData[];
}
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

reid
Posts: 7
Joined: 12 Jul 2014, 20:30

02 Dec 2022, 19:55

Thanks for the reply :D

Unfortunately, that just doesn't appear to be what I'm seeing, although I very well could be looking in the wrong place.
BTW, this is for primereact 8.1.0.

In column.d.ts I see:

Code: Select all

export interface ColumnProps {
    ...
    sortFunction?(e: ColumnSortParams): void;
   ... 
}
...
interface ColumnSortParams {
    field: string;
    order: ColumnSortOrderType;
}
...
type ColumnSortOrderType = 1 | 0 | -1 | undefined | null;
The definitions above also seem to agree with what I have access to when I actually try to use the parameters from the sort function.

reid
Posts: 7
Joined: 12 Jul 2014, 20:30

02 Dec 2022, 19:58

I just update to the latest version of PrimeReact and the interfaces are now in line with what you are saying and the documentation.

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

02 Dec 2022, 20:26

Yes sorry forgot to mention I was looking at 8.7.2 source code.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests