2012-12-20 139 views
1

问:如何使用自定义按钮创建自定义列?使用自定义按钮创建自定义列?

我想用cgridview创建一个网格视图如下。我能怎么做?

公司名|头1.1 |头1.2 | header 2.1 |头2.2 | header 3.1 |标题3.2

AAAA1 | [按钮] | [按钮] | [按钮] | [按钮] | [button] | [button]

BBBB1 | [按钮] | [按钮] | [按钮] | [按钮] | [button] | [button]

CCCC1 | [按钮] | [按钮] | [按钮] | [按钮] | [button] | [按钮]

========================================= ========================================= 更新

这是我的cgridview代码

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'customer-grid', 
    'dataProvider'=>$model->search(), 
    'filter'=>$model, 
    'columns'=>array(
     'customer_name', 
     array(
      'class'=>'CButtonColumn', 
      'template'=>'{select1} {select2} {select3} {select4} {select5} {select6} {select7} {select8}', 
      'buttons'=>array 
      (
       'select1' => array 
       (
        'label'=>'Send an e-mail to this user', 
        'url'=>'Yii::app()->createUrl("job/getjobno", array("c_code"=>$data->c_code))', 
        'imageUrl'=>Yii::app()->request->baseUrl.'/protected/assets/images/gridview/icon_select.gif', 
        'options'=>array('style'=>'width:10px; border:none'), 
        'click'=>'function(event) { 
         $.ajax({ 
          url:$(this).attr("href"), 
          dataType: \'json\', 
          success: function(data){ 
           //alert(data.newjobno); 

           $("#Job_name").val(data.newjobno); 
           //console.log(\'target tr: \' + target); 
           //$(target).find(\'.item-price\').val(data.newjobno); 
           $("#customerlist").dialog("close"); 
          } 
         });      
         event.preventDefault(); 
        }', 
       ),  
      ), 
     ), 
     array(
      'type'=>'raw', 
      'value'=>'$data->c_code', 
      //'filter'=>array('style'=>'visible:none'), 
      'headerHtmlOptions'=>array('style'=>'width:0px; display:none; border:none; textdecoration:none'), 
      'htmlOptions'=>array('style'=>'display:none; border:none;', 'class'=>'customer-id'), 
      'header'=>false, 
      'filter'=>false, 
     ), 
    ), 
)); ?> 
+0

你试过什么吗?你能展示一个样例按钮的样子(代码)吗? –

+0

我不知道该怎么做。我更新了我的cgridview代码。 –

+0

你在正确的轨道上。你是说每列都有一个按钮?或每个列都有所有的按钮? –

回答

3

你几乎说得没错。只是,你将需要更多的按钮栏,使用proper template为每个列,并指定buttons为每列正确:

'columns'=>array(
    'customer_name', 
    array(
     'header'=>'Header 1.1', // add headers this way 
     'class'=>'CButtonColumn', 
     'template'=>'{select1}', // only 1 button 
     'buttons'=>array 
     (
      'select1' => array 
      (
       // ... options for select1 button 
      ),  
     ), 
    ), 
    array(
     'header'=>'Header 1.2', // add headers this way 
     'class'=>'CButtonColumn', 
     'template'=>'{select2}', // only 1 button 
     'buttons'=>array 
     (
      'select2' => array 
      (
       // ... options for select2 button 
      ),  
     ), 
    ), 
    // ... and so on add the other button columns ... 
    // ... rest of columns ... 
), 

柜面你想在1列中的所有按钮,你只需要添加按钮在buttons属性中选择:

'columns'=>array(
    'customer_name', 
    array(
     'class'=>'CButtonColumn', 
     'template'=>'{select1}{select2}{select3}', // only 1 button 
     'buttons'=>array 
     (
      'select1' => array 
      (
       // ... options for select1 button 
      ), 
      'select2' => array 
      (
       // ... options for select2 button 
      ), 
      'select3' => array 
      (
       // ... options for select3 button 
      ),  
      // ... and so on add the other button options ... 
     ), 
    ), 
    // ... rest of columns ... 
), 

更新:请记住,无论你buttonId在提,使用该按钮ID来指定按钮选项:

'class'=>'CButtonColumn', 
'template'=>'{buttonId1}{buttonId2}', 
'buttons'=> array(
    'buttonId1'=>array(
     // ... options ... 
    ), 
    'buttonId2'=>array(
     // ... options ... 
    ) 

)