Skip to content

Conversation

DivadNojnarg
Copy link
Collaborator

Fix #17. @olajoke For now, we can activate sort by passing sort = TRUE in column_def(). There is a more advanced usage which requires to pass it with JS (like in DT, reactable, ...). This does not work yet, as I was unable to get it working properly:

{
      field: "no",
      caption: "no",
      width: 50,
      // define custom sort logic
      sort(order, col, grid) {
        const compare =
          order === "desc"
            ? (v1, v2) => (v1 === v2 ? 0 : v1 > v2 ? 1 : -1)
            : (v1, v2) => (v1 === v2 ? 0 : v1 < v2 ? 1 : -1);
        records.sort((r1, r2) => compare(r1.no, r2.no));
        console.log("sorted:", records);
        grid.records = records;
      },
    },
    {
      field: "name",
      caption: "name",
      width: 200,
      // use default sort logic
      sort: true,
    }

As a side note, I removed the toJSON here as it does not seems useful and causes issues if we have to pass JS callbacks with the JS function.

@DivadNojnarg DivadNojnarg requested a review from olajoke April 15, 2025 07:15
@olajoke olajoke changed the base branch from main to development April 23, 2025 07:22
@olajoke olajoke merged commit bdbafb6 into development Apr 23, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Make table sortable
2 participants