Merge options under <optgroup> when possible
See original GitHub issueI have a grouped select2 list that uses pagination to load 30 list items at a time. Each <optgroup>
contains one or more <option>
list items.
Feature request: an option group can cross the boundary of 30 items. When this happens, groups with the same labels at the page boundaries should be merged.
Example
optgroup group 1
contains 31 options, AJAX page size is 30.
AJAX Page 1
{
"results" : [
{
"text" : "group 1"
"children" : [
{
"id" : "item1"
"text" : "first item"
},
{
"id" : "item2"
"text" : "second item"
},
// items 3 to 29 omitted for brevity
{
"id" : "item30"
"text" : "thirtied item"
}
]
}
]
"pagination" : {
"more" : true
}
}
AJAX Page 2
{
"results" : [
{
"text" : "group 1"
"children" : [
{
"id" : "item31"
"text" : "thirty-first item"
}
]
}
]
"pagination" : {
"more" : false
}
}
Expected result
The code should recognize that page 2 should be merged with page 1 instead of appended, because the group header is the same.
<optgroup label="group 1">
<option value="item1">first item</option>
<option value="item2">second item</option>
<!-- items 3 to 29 omitted for brevity -->
<option value="item30">thirtied item</option>
<option value="item31">thirty-first item</option>
</optgroup>
Actual result
<optgroup label="group 1">
<option value="item1">first item</option>
<option value="item2">second item</option>
<!-- items 3 to 29 omitted for brevity -->
<option value="item30">thirtied item</option>
</optgroup>
<optgroup label="group 1">
<option value="item31">thirty-first item</option>
</optgroup>
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Add optgroup and options dynamically one by one
1 Answer 1 ... You can try to watch checkbox change event and reiterate over all checkboxes to collect questions. Then, generate HTML...
Read more >Mixing grouped and non-grouped OPTIONs inside a SELECT?
Simply spoken, if some options are not grouped, you don't use an option group to combine them. For example if you have a...
Read more >H85: Using optgroup to group option elements inside a select
It is possible for a select element to contain both single option elements and optgroup groups, though authors should consider if this is...
Read more >change select based on optgroup filter - CodePen
Ever have a need to fine tune a select box based on external triggers but don't want/need to update the select contents via...
Read more >grouped_options_for_select (ActionView::Helpers - APIdock
Note: It is possible for this value to match multiple options as you might have the same option in multiple groups. Each will...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Any chance to update the main project to implement this feature?
This is a feature I’d love to have, since I deal with a lot of data and sometimes that data is grouped.
For anybody else finding this thread via Google, here’s a small example of how I was able to achieve a similar feature. This code manipulates the returned server data, replacing “duplicate” groups with their children. (Alternatively, you could also send the “latestGroup” variable to the server and check the group on the server-level.)
Feel free to use however you want, no credit needed.