Skip to content
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

[Bug] useDataTable: Allow schema parameter to override default createdAt sort #233

Closed
john093e opened this issue Apr 15, 2024 · 1 comment

Comments

@john093e
Copy link

Describe the bug

Hello @sadmann7,

The useDataTable is currently always adding "createdAt.desc" to the URL, as it is the default sort in the use-data-table schema constant.

This is an issue, as we might need "updatedAt" or another type of time sorting, or even no time sorting at all, like sorting simply by IDs.

It seems to me that we should make the schema a mandatory parameter for the use-data-table, so users can choose whether to default to "createdAt", somthing else or nothing at all (thus using the ID as it is the default in queries.ts).

Kind regards.

How to reproduce

Link to reproduction

Additional information

No response

@john093e john093e changed the title [bug]: useDataTable -> Should receive the schema as parameter [bug]: useDataTable -> Should receive the schema as parameter to avoid createdAt when not needed Apr 15, 2024
@john093e john093e changed the title [bug]: useDataTable -> Should receive the schema as parameter to avoid createdAt when not needed [Bug] useDataTable: Allow schema parameter to override default createdAt sort Apr 15, 2024
@sadmann7
Copy link
Owner

Thanks for opening the issue.

Updated the useDataTable hook to handle perPage and sort props.

  const { table } = useDataTable({
    data,
    columns,
    pageCount,
    // optional props
    filterFields,
    enableAdvancedFilter,
    defaultPerPage: 10,
    defaultSort: "createdAt.desc",
  })

@sadmann7 sadmann7 closed this as completed Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants