yii中的网格视图,选中复选框返回空

时间:2017-12-16 06:40:49

标签: php jquery gridview yii

我在yii 1.1中使用带有复选框的网格视图,但是当我尝试获取检查值时,它们返回空值数组。

- 我在这里提到了所有的答案

- 我也使用了$.fn.yiiGridView.getChecked("grid-id","selectedIds");

仍然不适合我。

我的网格视图代码是:

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'patient-wallet-credit-grid-id',
    'dataProvider'=>$dataProvider,
    'selectableRows'=>100,
    'emptyText'=>"You don't have patients connected yet",
    'beforeAjaxUpdate'=>'function(id,options){options.data={checkedIds:$.fn.yiiGridView.getChecked("patient-wallet-credit-grid-id","selectedIds").toString(),
    uncheckedIds:getUncheckeds()};
    return true;}',
    'afterAjaxUpdate'=>'function(){
        $("#patient-wallet-credit-grid table").attr("data-tablesaw-mode","columntoggle");
        $("#patient-wallet-credit-grid table").attr("data-tablesaw-minimap","");
        $("#patient-wallet-credit-grid table").attr("data-tablesaw-sortable","");
        $("#patient-wallet-credit-grid table").attr("data-tablesaw-mode-switch","");
        $(document).trigger( "enhance.tablesaw" );
     }',
    'itemsCssClass' =>'tablesaw tablesaw-columntoggle items',
    'columns'=>array(
        array(
            'name' => 'check',
            'id' => 'selectedIds',
            'value' => '$data["patient_id"]',
            'class' => 'CCheckBoxColumn',
            'checked'=>'Yii::app()->user->getState($data["patient_id"])',
        'headerHtmlOptions'=>array(
                'data-tablesaw-priority'=>'1',
                'data-tablesaw-sortable-col'=>'',
                'class'=>'',
                'style'=>"width:10px"
            )
        ),
        array(
            'name'=>'Name',
            'value'=>'$data["patient_first_name"]',
            'headerHtmlOptions'=>array(
                'data-tablesaw-priority'=>'1',
                'data-tablesaw-sortable-col'=>'',
                'class'=>'start-xs'
            ),
        ),
        array(
            'name'=>'Mobile',
            'value'=>'$data["patient_id"]',
            'headerHtmlOptions'=>array(
                'data-tablesaw-priority'=>'1',
                'data-tablesaw-sortable-col'=>'',
                'class'=>'start-xs'
            ),
        ),
    ),
    'htmlOptions'=>array(
            'style'=>'overflow: auto;'
    ),
)); 

我在相同的视图中编写了函数getUnchecked()---

Yii::app()->clientScript->registerScript('getUnchecked', "
   function getUncheckeds(){
        var unch = [];
        /*corrected typo: $('[name^=someChec]') => $('[name^=someChecks]') */
        $('[name^=someChecks]').not(':checked,[name$=all]').each(function(){unch.push($(this).val());});
        return unch.toString();
   }
    "
);

当我试图通过

获取控制台中的值时
$.fn.yiiGridView.getChecked("patient-wallet-credit-grid-id","selectedIds");

假设我选择了3个复选框然后我得到像----

这样的输出
(3) ["", "", ""]
0: ""
1: ""
2: ""
length: 3
__proto__: Array(0)

0 个答案:

没有答案