Plugins

The plugins site is currently in development.

We've been looking to provide a higher-quality, spam-free experience at the plugins site for some time, and a major error on our part forced us to shut down the current site before we could put the new one in place. We are developing a new site, and you can follow along with its development on GitHub. For more information about this transition, including steps you can take as a plugin author to prepare, please read our post about what's going on.

Better control over sorting (This might be more of a documentation request than a feature request)


Project:ComboSelect
Version:1.0.2
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Sorting appears to be done only on the "value" attribute of the option tag. Value does not necessarily correspond to the text, as in many cases (in mine at least) its a series of codes, and not meaningful to sorting.

I would like to see more fine 'grain' sorting options, or maybe those options could simply be passed along to selso? Maybe that is a feature that already exists and I cannot find any documentation to help me along the way? If that's so maybe this should not be a feature request, but a documentation request?

This may not be the case on all platforms, so here is what I am working with:

  • Firefox 3
  • Safari
  • OSX 10.5.4
  • 3 Gig Ram
  • 2.16 G Intel Core 2

Attached is an example that doesn't sort for me based on the index.html file found in the release (Stripped down to show the example only).

To run the example, put it in the 'release' directory (i.e. the same one with all of the .css and .js files) and double click. Moving the items back and forth will only ever append them to the bottom of the list.

AttachmentSize
index.html1.52 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

#1

Hi,
I solved this issue.
You have to change this code of jquery.comboselect.js:
// add an ID to each option for the sorting plugin
opts.each(function(){
$(this).attr('id', $(this).attr('value'));
});

in:
// add an ID to each option for the sorting plugin
opts.each(function(){
$(this).attr('id', $(this).text());
});

A new option of comboselect such as orderBy: {value text} would be better.

I hope this hint will solve your problem.
Regards

#2

The solution in comment #1 is not correct.
For first if I have 2 or more select tags in the same page with the same values of options (ie. ids of articles in a database) the instruction:

$(this).attr('id', $(this).attr('value'));

generate more option tags with duplicated id in 2 or more differents select tags.

I.E.

<select id="id1" multiple="multiple">
<option value="1">car</option>
<option value="2">moto</option>
</select>

<select id="id2" multiple="multiple">
<option value="1">big</option>
<option value="2">small</option>
</select>

the plugin will generate:

<select id="id1" multiple="multiple">
<option id="1" value="1">car</option>
<option id="2" value="2">moto</option>
</select>

<select id="id2" multiple="multiple">
<option id="1" value="1">big</option>
<option id="2" value="2">small</option>
</select>

The ids will be the same in two different tags...that can be a problem for the sort function.

Moreover, changing

$(this).attr('id', $(this).attr('value'));

in

$(this).attr('id', $(this).text());

the sort function fails when the option text label cointain white spaces.

I have solved this issues creating an option id depending on select id (obviusly every select should have a unique id):

$(this).attr('id',selectID+$(this).attr('value'));

The code above will generate:

<select id="id1" multiple="multiple">
<option id="id11" value="1">car</option>
<option id="id12" value="2">moto</option>
</select>

<select id="id2" multiple="multiple">
<option id="id21" value="1">big</option>
<option id="id22" value="2">small</option>
</select>

The relative order between ids remain the same and the sort function will sort the option tags correctly.

I have proved this code with your index.html file and seems to be working only if you change the character ":" with "_" in the options value.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.