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

Comparison enhancement and select2SortableOrder() binding change proposal #4

Open
matteopoile opened this issue Jul 9, 2013 · 3 comments

Comments

@matteopoile
Copy link
Contributor

First of all, I have got a quite complex interface with some simple select2 and in some cases up to 20/30 select2 + select2Sortable that use select2 formatSelection function.

In this case i prefer to bind the select2SortableOrder on jQuery UI stop and on original select change.
Sorting 300 items of a single select2Sortable instance takes around 100 milliseconds on my hardware while sorting 20/30 instances on form submit will take 2/3 seconds...
I prefer a lot of little sorts instead of a big one but this is questionable.
Maybe the best way would be choose a default and add a parameter to let the developer change the default behaviour (bind: sortableStop|formSubmit). No time to develop this now :(.

I spotted a bug using select2 formatSelection function. In select2Sortable there's a weak text comparison between the original option text and the visualized li.select2-search-choice text to sort the original select option. This will fail if you format li.select2-search-choice content trough select2 formatSelection function so I change that option text comparison with an option value comparison.

At the end of select2SortableOrder there are a call to select2SortableDestroy() followeb by a call to select2Sortable() that don't take in consideration the new and optional sortableOptions argument passed on select2Sortable initilization. It seems it works fine commenting that 2 functions calls but I'm not sure removing them will not lead to other problems I didn't spotted yet.

Hoping my english will be understandable, your opinion will be very appreciated.

P.S.: Have you ever tried select2Sortable on a select2 ajax configured?

@ayublin
Copy link
Member

ayublin commented Jul 9, 2013

Hi Matteo,

Good Idea! I have just pushed a change to support configurable bind to actual ordering, so you can now do this:

jQuery('#myselect').select2Sortable({
    bindOrder: 'sortstop', // default to `form_submit`
    sortableOptions: {placeholder : 'ui-state-highlight'}
});

And the select2SortableDestroy() followed by select2Sortable() lines are already deleted on my previous commit, I guess you missed them :)

About the text comparison, I can't find a better way to do that, can you give me a clue on how you tweak it using option value comparison?

I am using select2sortable on an ajax form page, is that what you mean?

Thanks!

@matteopoile
Copy link
Contributor Author

Hi Ayub,
bindOrder is a very usefull option and I'm glad that you already deleted select2SortableDestroy() and select2Sortable().
I will open a pull request now with my code so you can look at the option value comparison.

When I talked about the select2 ajax configured I meant using ajax to retrieve select2 option.
Anyway I will test this as soon as possible :).

@ayublin
Copy link
Member

ayublin commented Jul 11, 2013

Ohh, I've never used it with ajax loaded options, do you find any issue with that? I am not sure about it myself, got to test it, he he.

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