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

Cannot order alphabetically #24

Closed
felds opened this issue Aug 27, 2015 · 9 comments
Closed

Cannot order alphabetically #24

felds opened this issue Aug 27, 2015 · 9 comments

Comments

@felds
Copy link

felds commented Aug 27, 2015

Hi there!

This happens when I try to order a string list alphabetically:
screenshot 2015-08-27 02 40 08

screenshot 2015-08-27 02 40 19

It only happens on Chrome (Version 44.0.2403.157 @ Mac OS 10.10). The script works fine on Safari and Firefox.

@adamschwartz
Copy link
Contributor

I’m fairly confident the issue is that Date.parse('1&1') returns the current date in Chrome whereas Firefox returns NaN. This is the imperfect criteria we use to decide if a column contains “date” data. We could introduce an attribute data-sortable-type which you could add to the th to force a specific data-type to Sortable, with current options numeric, alpha and date. For the time being though if you ensure that the entry in the first row of the “Host” column (call it foo) have a value such that Date.parse(foo) returns NaN, you should see this issue resolve. Hope this helps!

@adamschwartz
Copy link
Contributor

Turns out someone already suggested this in #21. This should be closed as a duplicate.

@adamschwartz
Copy link
Contributor

(I’d close it myself but no longer have admin privileges for some reason.)

@timmfin @geekjuice @TrevorBurnham @graysky a little help here?

@timmfin timmfin closed this as completed Sep 13, 2015
@adamschwartz
Copy link
Contributor

Thanks @timmfin

@felds
Copy link
Author

felds commented Sep 14, 2015

@adamschwartz I'm working on an implementation that allows selecting the sort order via data-* attributes and also allows the user to add custom types and/or change how the types work. It has been pretty hard not to break BC and to keep the small footprint at the same time, but I think I'm getting there!

@adamschwartz
Copy link
Contributor

@felds Thanks, cool idea. Since window.Sortable.types and window.Sortable.getColumnType are already exposed, you could probably modify getColumnType slightly and you’d be pretty close. Hope this helps.

@felds
Copy link
Author

felds commented Sep 14, 2015

@adamschwartz
I made so that each type test the data to see if it matches its definition. (felds@f28945f)

It works, but it's not that easy defining new types, as it's not an object, but an array (so pushing a new type would append it to the list, after the default one).
Converting the array to an obj flips the problem: we cannot trust the obj order when iterating through its keys and the default type could come first on the loop.

I think a solution could be adding a "priority" key to the type obj, converting the types obj into an array before looping and then sorting by that property. Not that elegant, but I think that would work!

Any ideas?

@adamschwartz
Copy link
Contributor

Great idea! I think the array option is slightly better. See my couple comments, but I can’t wait to see the PR! Nice job. And thanks! 👍

@jcolemorrison
Copy link

Ran into this issue (that as mentioned above only occurs in chrome) due to it thinking any number is with a string is a valid date. Has anyone found a way, other than data-sortable-types in getting around Chrome's different way of dealing with Date.parse / new Date's?

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

4 participants