0

我在这个屏幕上有这样的情况:截屏

我有用户检查行的列。之后,用户可以调用一些操作,例如删除数据。

为了向用户显示具有多项操作的菜单,我在 yii-booster TbButtonGroup 中使用按钮下拉菜单。我尝试了所有可能的按钮类型,但都不起作用。

我需要的只是发送有关选择了哪些行的信息,在控制器内部执行一些操作,然后重新加载网格。我不知道怎么...

要生成按钮下拉列表,我使用代码:

    Yii::app()->controller->widget('bootstrap.widgets.TbButtonGroup', array(
        'size'=>'mini',
        'type'=>'link',
        'buttons'=>array(
            array('icon'=>'edit', 'items'=>$this->filter),
        ),
    ));

To generate grid i use code:
$this->widget('bootstrap.widgets.TbJsonGridView', array(
    'dataProvider' => $model->search(),
    'filter' => $model,
    'type' => 'striped condensed',
    'summaryText' => false,
    'cacheTTL' => 10, // cache will be stored 10 seconds (see cacheTTLType)
    'cacheTTLType' => 's', // type can be of seconds, minutes or hours
    'selectableRows'=>2,
    'columns' => array(
        array(
            'class'=>'ext._TbJsonCheckBoxColumn._TbJsonCheckBoxColumn',
            'id'=>'selectedTickets',
            'filter'=>array(
                array('label'=>'close', 'url'=>'javascript:'.CHtml::ajax(array('type'=>'POST', 'url'=>array('','multi_action'=>'close'), 'success'=>'function(data, status){ console.log(data); console.log(status); }', 'error'=>"function(data, status){ console.log(data); console.log(status); }")) ),
                array('label'=>'Another action', 'url'=>'#'),
                array('label'=>'Something else', 'url'=>'#'),
                '---',
                array('label'=>'Separate link', 'url'=>'#'),
            ),
        ),
        'id',
        'email_from',
        'subject',
        'status',
        array(
            'name'=>'last_update',
            'value'=>'$data->last_update_from_now',
            //'filter'=>false,
        ),
        array(
            'header' => Yii::t('ses', 'Edit'),
            'class' => 'bootstrap.widgets.TbJsonButtonColumn',
            'template' => '{view} {update} {delete}',
        ),
    ),
    ));

要生成表单,我使用代码:

$this->widget('bootstrap.widgets.TbButton',array(
    'label' => 'Add new ticket',
    'type' => 'primary',
    'size' => 'medium',
    'url' => $this->createUrl('create'),
));

<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id'=>'tickets',
    'type'=>'horizontal',
    'enableAjaxValidation'=>true,
));

echo $this->renderPartial('_grid', array('model'=>$model));
echo CHtml::ajaxSubmitButton('Activate',array('menu/ajaxupdate','act'=>'doActive'), array('success'=>'reloadGrid'));

$this->endWidget();
4

1 回答 1

0

经过许多小时,我写了类似的东西,它解决了我的问题:

Yii::app()->clientScript->registerScript('multi_button', "
    $('[data-multi=action]').delegate('li a', 'click', function(event){
        event.preventDefault();

        var th = $(this),
        action = th.attr('href').substr(1);

        if( action=='delete' && !confirm('Are you sure you want to delete selected items?') ) return true;
        ".
        CHtml::ajax(array(
            'type'=>'POST',
            'data'=>'js:th.closest("form").serialize()',
            'url'=>'js:location.href+(/\?/.test(location.href) ? "&" : "?")+"multi_action="+action',
            'success'=>'function(data, status){ th.closest("div.grid-view").yiiJsonGridView("update"); }',
            'error'=>'function(data, status){ alert(status); }',
            'cache'=>false
        ))."
    });
");
于 2013-03-18T15:24:30.830 回答