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

sort for tables not working with date strings #461

Closed
pascalwhoop opened this issue Mar 29, 2017 · 7 comments · Fixed by #1225
Closed

sort for tables not working with date strings #461

pascalwhoop opened this issue Mar 29, 2017 · 7 comments · Fixed by #1225
Labels
Milestone

Comments

@pascalwhoop
Copy link

Bug Report

calling sortData on TdDataTableService with sorting field being a date doesn't work as expected

Screenshots or link to CodePen/Plunker/JSfiddle

What is the expected behavior?

sorting date should sort the dates. But the line
if (!Number.isNaN(Number.parseFloat(compA)) && !Number.isNaN(Number.parseFloat(compB)))

causes Problems. This is beacuse Number.parseFloat("2018-05-14T00:00:00.000Z") returns a number. 2018

What is the motivation / use case for changing the behavior?

Dates should be sorted properly

Which version of Angular and Material, and which browser and OS does this issue affect?

@akomarovsky
Copy link

was it fixed? I see that in version 1.0.0-beta.3-1 it is still an issue

@pascalwhoop
Copy link
Author

No it wasn't fixed but there is no clean way of sorting this without being really careful what you do. I suggested including moment.js but the repo admins don't agree that's a good idea yet so I don't have a good idea at the moment. Doing some sketchy Regex on strings is not a smart move.

@emoralesb05
Copy link
Contributor

We are trying to avoid adding external dependencies to reduce the bundle size. Unless the dependency is used heavily in the project, its not really worth it. We want to be able to fix this without it if possible.

That being said, you can always pull moment.js on your project and use it.

@michael-lang
Copy link

Can you just do a custom sort? See code snippet in #521

@pascalwhoop
Copy link
Author

Yes of course it's possible to get my date strings sorted manually. And although we shouldn't expect covalent to figure out for us what the string means, a date string is so common it would be nice. The real problem however is that it currently(is it still current?) interprets a date string as a number which becomes the year of the date. That is not correct. I can't look into the code base ATM, I'm on mobile.

I think best would be to rethink the interpretation of what is a number and leave the date handling out until either moment.js is included or someone finds a solid well proven way of determining strings being ISO date strings or not.

@ankita3076
Copy link

ankita3076 commented Aug 28, 2017

Hi,
I am able to sort data manually, but the problem is when I am clicking on pagination, all the sorting is getting off. Can anyone help me in that.

@Vasanthvivi
Copy link

We are trying to avoid adding external dependencies to reduce the bundle size. Unless the dependency is used heavily in the project, its not really worth it. We want to be able to fix this without it if possible.

That being said, you can always pull moment.js on your project and use it.

any other thing other than moment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants