Specify Additional Attributes For Dropdownlist Options

How can I create every dropdownlist option to have this markup:

<option value="1" data-cat-id="5" data-type="Cars">Ford Fiesta</option>

<?php echo $form->dropDownList($model, 'cars', $model->getCarsList()); ?>

// $model->getCarsList() returns CHtml::listData();

Furthermore, is it possible to customise the OPTGROUP tag (generated from listData) to have this markup:

<optgroup label="Cars" data-cat-id="5">


Did you try this ?

echo $form->dropDownList($model, 'cars', $model->getCarsList(),array('data-cat-id'=>'5'));

Also fo the second issue check this


Well that will add the attribute to the SELECT tag - I want to add the attribute to each OPTION tag within the SELECT.

I had a similar issue, check this