Two delete button columns in a CGV

I ran into this when I needed two delete button columns that use different actions.

This will work badly:


array(

    'class'=>'CButtonColumn',

    'header' => 'Delete that',

    'deleteButtonUrl' =>

        'Yii::app()->controller->createUrl("deleteThat", array("id" => $data->id))',

    'template' => '{delete}',

),

array(

    'class'=>'CButtonColumn',

    'header' => 'Delete this',

    'template' => '{delete}',

),

Given the above column spec, CButtonColumn registers two delete button click handler scripts but the selector for both is identical: ‘#chart-grid a.delete’. The result is that you get the confirm confirm dialog twice and the delete request is sent to the server twice. Not good.

I found a simple work around: add ‘id’ => ‘something’ to both column specs and then handler appears only once. If the id option is the same for both columns then CButtonColumn still registers the script twice but it does so under the same script id. CClientScript then pastes the handler script into the output only once.