Hi I need to create table with tbody, tr and td, for example:

  <table>
   <tbody id="sortable1" class="droptrue">
    <tr><td class="ui-state-default">Can be dropped..</td></tr>
    <tr><td class="ui-state-default">Can be dropped..</td></tr>
    <tr><td class="ui-state-default">Can be dropped..</td></tr>
    <tr><td class="ui-state-default">Can be dropped..</td></tr>
  </tbody>
</table>

I am using Yii CGridView (this widget required)

$this->widget('bootstrap.widgets.TbGroupGridView', array(
'id'=>'order-table',
'type'=>'striped condensed',
'dataProvider'=>$orders->search(),
'filter'=>$orders,
'ajaxUpdate'=>true,
'columns' => 
    array(
        array(
            'header' => 'ID',
            'value' => 'Adminhelper::getRowNumber($row, @$_GET["OrderModel_page"])',
           ),
        'name',
        'model',
        'imei',
        'provider',
        array(
            'header' => 'payment_type',
            'value' => 'Adminhelper::getPaymentMethod($data, array("На счет телефона", "Qiwi", "Webmoney", "На карту Сбербанка", "Yandex Деньги", "PayPal" ))'
           ),
        array(
            'header'=>'AAAA',
            'value'=>'Adminhelper::getInfoButton($data)',
          ),
        array(
            'header'=>'Статус',
            'value'=>'Adminhelper::getStatusButton($data)',
          ),
        array(
            'header' => 'Copy',
            'value'=>'Adminhelper::getCopyButton($data)',
           ),
        array(
            'header'=>'Статус',
            'value'=>'Adminhelper::getDeleteButton($data)',
          ),
),

How can I set class and id for tbody tag, and classes for td tag? I didn't found this in CGridView class reference, but I think it can be configuired by htmlOptions. Thanks for help!

有帮助吗?

解决方案

Did you try this:

array(
    'header'=>'Статус',
    'value'=>'Adminhelper::getDeleteButton($data)',
    'htmlOptions'=>array('class'=>'td-class-here')
),

For tbody tag you can't define class, but you defined it for table 'id'=>'order-table', so you can access to tbody like $('#order-table tbody')

Update: You can't catch ajaxUpdate paging event, but you can use beforeAjaxUpdate, afterAjaxUpdate events, like this:

'afterAjaxUpdate' => 'function(id, data){/*write js-code there*/}'

其他提示

As @Alex explained, you can id your table or you can point to it like the following in your view file:

<style>
.grid-view table.items tbody {
    color: #000;
    ...
}
</style>

for your td (CGridColumn) you can define your class within your widget definition in two ways:

One (static):

array(
    'header'=>'Статус',
    'value'=>'Adminhelper::getDeleteButton($data)',
    'htmlOptions' => array(
        'style' => 'width:120px;text-align:left',
        'class' => 'yourClassName'
    ),
),

Two (dynamic):

array(
    'header'=>'Статус',
    'value'=>'Adminhelper::getDeleteButton($data)',
    'cssClassExpression' => 'Adminhelper::getDeleteButton($data)=="CompareValue"?
                              "error":"success"',
),
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top