-
Notifications
You must be signed in to change notification settings - Fork 68
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
how to properly combine selector and sortFunction options #144
Comments
Verified bug http://jsfiddle.net/Sjeiti/cfoqtk7z/ |
Thanks @Sjeiti , but that bug does not explain why the 2nd jsffidle above fails: it does NOT use charOrder script. I made a much simpler version showing just the button which fails running sortFunction option: What is failing there? |
You expect the custom sort function to sort a subselection when in fact it sorts the length of the entire list-element. The custom sort function ignores all other properties you set because it expects you to implement these yourself. This is by design. |
So the "selector" parameter above has no effect? sortByLength(a,b) should take care of finding the span.myclass element inside the li elements received as parameters (a,b), and measuring its content length or whatever I want to do to sort the list. Correct? Thanks a lot for your explanation @Sjeiti. Now it works: https://jsfiddle.net/abubelinha/ovr6cn21/35/ Also, there was a 2nd question I raised in the original message. I think you didn't answer yet: Do you know why sortFunction does not work if the charOrder plugin script is loaded? (even if I don't run its code). |
Still working on that last one, I did fix one charorder issue but there is still one thing wrong |
Thanks @Sjeiti |
@abubelinha I don't have time to look into it this week but when I do I'll refer you when it's fixed. As for your question regarding passing params: there is one open pull request touching that issue. I don't think I'll merge it as is, but I might extend the sortFunction with similar functionality... maybe... |
Any advances? I recall the status of my question: custom sort functions failed when charOrder plugin was loaded. Or perhaps mine was simply a collateral effect of what you said above about sortFunction? (so any sortFunction will ignore charOrder "by design", and not due to a fail in any of them):
And what about this other pending question? You mentioned a related pull request (I don't know the link):
I am specially interested in this, because a custom sortFunction can also be used to somehow resemble the failing charOrder plugin (at least in the mean time, if the issues above still persist). For example, I have now a custom myAZcharOrderFunction() which works perfectly with TinySort for sorting elements based on their inner text ( It works great like this: But this wouldn't work: BTW ... which one of the last two calls is the correct syntax? I guess the 1st one, but I still have not a clear understanding of when using separate curly brackets. This example confuses me a bit:
... would any of these make any different effect?
|
@Sjeiti have you any solution for passing parameters (i.e. a selector) to sortFunction? My example in https://jsfiddle.net/abubelinha/ovr6cn21/35/ can sort elements based on a given selector, but its name has to be hardcoded inside the custom function and that is not a general solution. |
This comes from #132 , but I think it might deserve a new issue title, since the sortFunction mentioned there does already work.
My problem comes only when I try to combine the selector and sortFunction options altogether.
The jsfiddles below reproduces the aforementioned "sort by text length" function.
For some reason, the "sort by length" button is failing when I am trying to use it to sort a list using a span as selector. Has the following tinysort() call an incorrect syntax?
I would expect the list to be sorted upside-down after the tinysort() call, based on the string lengths inside the right spans ... but when I try to call this from the "sort by length" button in my jsfiddle, it does not work:
Please note the jsfiddle also needs charorder plugin to be used in another button. So I tried to test differences in loading or not loading that plugin, although it shouldn't change the behaviour of the "sort by length button" (since the tinysort call in it does not use charorder):
https://jsfiddle.net/abubelinha/kcfpu3sr/161/
https://jsfiddle.net/abubelinha/kcfpu3sr/162/
The text was updated successfully, but these errors were encountered: