I have a .json file containing US city data. I have successfully pulled the data into my selectize select box, but it does not display the optgroup headers. Here is an excerpt of the .json file:
[
[...],
[{
"Index": 16246,
"Display": "Auburn",
"City": "Auburn",
"County": "Lee",
"State": "Alabama",
"StateAbbv": "AL",
"Latitude": 32.5475,
"Longitute": -85.4682,
"Zipcode": 36830
}, {
"Index": 16247,
"Display": "Auburn",
"City": "Auburn",
"County": "Lee",
"State": "Alabama",
"StateAbbv": "AL",
"Latitude": 32.5782,
"Longitute": -85.349,
"Zipcode": 36831
}, {
"Index": 16248,
"Display": "Auburn",
"City": "Auburn",
"County": "Lee",
"State": "Alabama",
"StateAbbv": "AL",
"Latitude": 32.592,
"Longitute": -85.5189,
"Zipcode": 36832
}],
[{
"Index": 16249,
"Display": "Auburn University",
"City": "AuburnUniversity",
"County": "Lee",
"State": "Alabama",
"StateAbbv": "AL",
"Latitude": 32.6024,
"Longitute": -85.4873,
"Zipcode": 36849
}],
[...]
]
As you can see, there are three entries for Auburn, so I want "Auburn" to be the optgroup header and the three entries (displaying zipcodes) to be underneath it. I included a singular entry (Auburn University) that should also display the same way, but only with the single zipcode.
This is basically the format I am looking for in the dropdown:
AUBURN
36380
36831
36832
AUBURN UNIVERSITY
36849
Here is what I have set up on my page to configure the plugin:
$select_city = $('#zipcode-select').selectize({
optgroupField: 'Display',
optgroupLabelField: 'Display',
optgroupValueField: 'Index',
maxItems: zipcodeLimit,
valueField: 'Zipcode',
labelField: 'Zipcode',
searchField: ['Zipcode','Display']
});
Currently it just outputs the zipcodes:
Since I specified to search in both the 'Display' and 'Zipcode' fields, I can search for either the zipcode or the city and it will filter accordingly:
According to the plugin's usage page, I was led to believe supplying the optgroup*
options would achieve what I am looking to do, but apparently that is not so.
Does anyone know how to implement what I am seeking to do?