0

我有一个自定义删除按钮,我想要的只是在删除操作发生之前进行某种确认。我已经尝试了多种方法,但到目前为止没有成功。

这是我的代码,我正在使用 CArrayDataProvider 因此必须为删除按钮创建一个模板。

 array(
       'class' => 'CButtonColumn',
       'template' => '{delete}{reset}',
       'deleteConfirmation'=>"js:'Are You Sure?'",
       'afterDelete'=>'function(link,success,data){ if(success) alert("Delete completed successfully"); }',
       'buttons' => array(
           'delete' => array(
               'label'=> 'Remove this device',
               'imageUrl'=> Yii::app()->request->baseUrl.'/img/delete.png',
               'url' => 'Yii::app()->controller->createUrl("controller/action", array("trace_id"=>$data["trace_id"], "mac"=>$data["mac"]))',
               'click'=><<<EOD

                      function(){
                      confirm('Are you sure?')
                      }EOD
                ),
4

1 回答 1

0
            'status' => array(
                'label'=>"<i class='fa fa-eye-slash'></i>",     // text label of the button
                'url'=>function ($data)
                {
                    return $this->createUrl("counters/changeStatus",array('id'=>$data->counter_id, "status"=>$data->status ? 0 : 1  ));
                },       // a PHP expression for generating the URL of the button
                'imageUrl'=>false,  // image URL of the button. If not set or fa lse, a text link is used
                'options'=>array(
                    'class'=>'btn roundPoint4 btn-xs green btn-warning statusBtn',
                    'title'=>"Activate/Deactivate",
                ), // HTML options for the button tag
                'click'=>'function(e){
                                                  e.preventDefault();

                            //open confirmation box write ur code here


                                       }',     // a JS function to be invoked when the button is clicked
                'visible'=>function ()
                {
                    return true;
                },   // a PHP expression for determining whether the button is visible
            ),

现在我向你展示我在我的代码中为你想做的事情做了什么

            'status' => array(
                'label'=>"<i class='fa fa-eye-slash'></i>",     // text label of the button
                'url'=>function ($data)
                {
                    return $this->createUrl("counters/changeStatus",array('id'=>$data->counter_id, "status"=>$data->status ? 0 : 1  ));
                },       // a PHP expression for generating the URL of the button
                'imageUrl'=>false,  // image URL of the button. If not set or fa lse, a text link is used
                'options'=>array(
                    'class'=>'btn roundPoint4 btn-xs green btn-warning statusBtn',
                    'title'=>"Activate/Deactivate",
                ), // HTML options for the button tag
                'click'=>'function(e){
                                                  e.preventDefault();

                                                  $(this).parents("table").find("tr.workingRowClass").removeClass("workingRowClass");

                                                  $("#secretForm").html("");
                                                  var parts =  getMyIdNew($(this).attr("href"), "/status/", "/id/") ;
                                                  setAction($("#secretForm"), "POST",  parts[2], 1)
                                                  moslakeFormInput( $("#secretForm") , "Counters[id]", "hidden", parts[1] , "id");
                                                  moslakeFormInput( $("#secretForm") , "Counters[status]", "hidden", parts[0], "status");
                                                  moslakeFormInput( $("#secretForm") , "operation", "hidden", "statusChange", "operation");

                                                  $("#promptAlert").find(".modal-body").html("<p>Are you sure you want to change status of the this Item ?</p>");
                                                  $("#promptAlert").modal("show"); $(this).parents("table").find("tr").removeClass("deleteMode");
                                                  $(this).parents("tr").addClass("workingRowClass");


                                       }',     // a JS function to be invoked when the button is clicked
                'visible'=>function ()
                {
                    return true;
                },   // a PHP expression for determining whether the button is visible
            ),

我有复制粘贴代码。所以这将是额外的。当有人点击“状态”按钮时。它将打开引导模式。并要求确认。在执行此操作时,我创建了一个带有操作和一些字段的表单。在那个模式中我有继续按钮。在继续按钮上单击表单将被提交。关闭时,表格将变为空。表格将显示无表格。并且将隐藏所有字段..我知道它比 urs 更复杂......但我用 post 来做......但你可以将你的 HREF 分配给这个函数中的 POST 按钮链接,然后点击它会是重定向

于 2015-07-01T09:57:32.097 回答