Search code examples
knockout.jsknockout-mapping-plugin

Knockoutjs select with option group


Is there any way in Knockoutjs binding where I can specify optionsGroup ? something like follwoing

<select data-bind="options: collection, optionsText: 'Text', optionsGroup: 'Group'/>

Please do reply.


Solution

  • I got the answer of the same, here is the answer if anybody wants,

    <td><select class="fieldValue" data-bind="foreach: $root.AvailableFields, value: FieldId, event :{ change: $root.onFieldSelectionChange}">
            <optgroup data-bind="attr: {label: FieldGroupName}, foreach: Fields">
                <option data-bind="text: HeaderText, value: FieldId"></option>
            </optgroup>
         </select>
      </td>