Skip to content

dataprovider fails to load when attemping to pass groups. #356

@pascoea

Description

@pascoea

I couldn't think of a better title, sorry. But the gist of it, I'm using dataprovider to load the dropdown, and I'm trying to use grouping.

data format:

data=[{title:"group1",stuff:{label:"one",value:1},{label:"two",value:2"}},
{title:"group2",stuff:{label:"three",value:3},{label:"four",value:4"}}]

jquery's "isarray" returns false on an object. I had to hack your code up:

        dataprovider: function(dataprovider) {
            var optionDOM = "";
            var groupCounter = 0;
            var selected="";
            $.each(dataprovider, function (index, option) {

                if (option['title']!==undefined) {

                    groupCounter++;
                    optionDOM += '<optgroup label="' + (option.title || 'Group ' + groupCounter) + '">';

                    $.each(option['stuff'], function (index, option) {
                        optionDOM += '<option value="' + option.value +'" >' + (option.label || option.value) + '</option>';                   
                    });
                    optionDOM += '</optgroup>';
                }
                else {
                    optionDOM += '<option value="' + option.value +'">' + (option.label || option.value) + '</option>';
                }
            });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions