我有一个自定义删除按钮,我想要的是在删除操作发生之前的某种确认.. 到目前为止,我已经尝试了多种方法,但没有成功。
这是我的代码,我使用的是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
),
答案 0 :(得分: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
),
我有复制粘贴代码。所以这将是额外的。有人点击“状态”按钮。它将打开bootstrap模式。并要求确认。在执行此操作时,我创建了一个包含操作和某些字段的表单。在那个模态我有继续按钮。在继续按钮单击表格将被提交。在结束时,表格将变为空。表格将不显示任何形式。并且会隐藏所有的字段..我知道它比urs更复杂......但是我用post ... 但是你可以指定你的HREF来发布按钮链接这个功能并点击它它将被重定向