An open API service indexing awesome lists of open source software.

https://github.com/aduth/jquery.optgrouper

Automatically group <option>'s into <optgroup>'s using a custom data-optgroup attribute
https://github.com/aduth/jquery.optgrouper

Last synced: about 1 year ago
JSON representation

Automatically group <option>'s into <optgroup>'s using a custom data-optgroup attribute

Awesome Lists containing this project

README

          

# jQuery Optgrouper

Optgrouper is a jQuery plugin which makes it easy to group related `` elements into `` groupings using a custom `data-optgroup` attribute.

[Demonstration](http://aduth.github.com/jquery.optgrouper/)

## Usage

Add `data-optgroup` attribute to each `` element.

```html

Cheetah
Lizard
Snake
Elephant

```

Include jquery.js and jquery.optgrouper.js, then call Optgrouper when page is ready.

```html

$(document).ready(function() {
$('#selAnimals').optgrouper();
});

```

## Options

There are currently two options to control the behavior of Optgrouper.

* `sortGroups` (Function) - Given an array of group names, return the same array in a custom sort order
* `renderImmediately` (Boolean) - Control whether groups are rendered immediately upon plugin call (defaults to true)

_Example_

```javascript
$('#selAnimals').optgrouper({
sortGroups: function(groups) {
return groups.sort();
},
renderImmediately: false
}).data('plugin_optgrouper').renderGroups();

```

## License

Copyright (c) 2014 Andrew Duthie

Released under the MIT License (see LICENSE.txt)