Skip to content

activate sort for column_def #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

activate sort for column_def #26

wants to merge 2 commits into from

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
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
1 participant