Get 2024 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $99
Get for 99$

Sort by date in users app


Hi,

I'm trying to sort a column by date in the users app.

The data model that is used in Metronic looks like this:

_models.ts


import {ID, Response} from "../../../../../../_metronic/helpers"
export type User = {
id?: ID
name?: string
avatar?: string
email?: string
position?: string
role?: string
last_login?: string
two_steps?: boolean
joined_day?: string
online?: boolean
initials?: {
label: string
state: string
}
}

export type UsersQueryResponse = Response<Array<User>>

export const initialUser: User = {
avatar: "avatars/300-6.jpg",
position: "Art Director",
role: "Administrator",
name: "",
email: "",
}


I'm trying to add an additional field:


export type User = {
id?: ID
created?: Date
name?: string
avatar?: string
email?: string
position?: string
role?: string
last_login?: string
two_steps?: boolean
joined_day?: string
online?: boolean
initials?: {
label: string
state: string
}



And in my columns definition:

{
Header: (props) => (
<ResultCustomHeader tableProps={props} title='Created Date' className='min-w-125px' />
),
accessor: 'created',
sortType: 'datetime',
Cell: ({...props}) => <>{props.data[props.row.index].date.toString()}</>
},


When running this is doesn't sort them by date... it looks like it's sorting by something else, probably a string.

Can you please provide a working example?

Thanks!


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (5)


Are you using this technique?

https://react-table-v7.tanstack.com/docs/faq#how-can-i-use-the-table-state-to-fetch-new-data



Hi,

Yes in our datatable examples, we are using react-tables. In our Users Managment example we are handling sorting on server side, you can use the same approach and return sorted array by date to your client-side.

You can check our Swagger API example: https://preview.keenthemes.com/theme-api/api/documentation#/

Regards,
Lauris Stepanovs,
Keenthemes Support Team



Is there a reason you're not using "automatic sorting" (useSortBy) in the users app in Metronic?

Here's an example:

https://github.com/TanStack/table/tree/v7/examples/sorting



I've got the same issue with a field of type number:

age?: number

Can you please provide an example for this one as well?


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(