Knockoutjs select with option group

TBone picture TBone · Jan 23, 2012 · Viewed 10.7k times · Source

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.

Answer

TBone picture TBone · Feb 15, 2012

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>