调用网格动作的函数时请单击 [英] Calling a function on grid action coumn click
本文介绍了调用网格动作的函数时请单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在yii中有一个网格,其中有一个带有自定义按钮的操作列,当我单击网格按钮但我遇到错误时,我想调用函数
I have a grid in yii that has an action column with a custom button I would like to call function when the grid button is clicked but i get an error
这是我的代码:
[
'class' => 'kartik\grid\ActionColumn',
'template' => '{approve}{new}{reject}',
'buttons' => [
'approve' => function ($url, $model) {
return Html::button('<i class="fa fa-check"></i>', ['value' => Url::to('approvetruck?id='.$model->id),'style' =>'background:none;border:none;','id' => 'approve','onclick'=>'alert('.$model->id.')']);
},
'reject' => function ($url, $model) {
return Html::button('<i class="fa fa-close"></i>', ['value' => Url::to('checktruck?id='.$model->id."&category=1"),'style' =>'background:none;border:none;', 'onclick'=>'reject('.$model->id.')');
},
],
'dropdown' => false,
'vAlign' => 'middle',
'urlCreator' => function ($action, $model, $key, $index) {
return '#';
},
'deleteOptions' => ['label' => '<i class="glyphicon glyphicon-remove"></i>']
]
在网格之后(在同一页面上)
After the grid i have(on the same page)
<?php
$script = <<< JS
function reject(id) {
alert(id);
}
JS;
$this->registerJs($script);
?>
第一个批准执行警报的工作正常,但是调用函数拒绝的拒绝失败.
它返回错误Uncaught ReferenceError: reject is not defined
The first one approve doing the alert works but the reject which calls a function reject fails..
it returns an error of Uncaught ReferenceError: reject is not defined
我该怎么做
推荐答案
似乎您必须使用以下代码注册js
It seems you have to use below code for register js
<?php
$this->registerJs('
function reject(id) {
alert(id);
}', \yii\web\VIEW::POS_HEAD);
?>
这将在头部添加js,并且可能会获得您定义的功能
that will add the js in head part and it may get the function which you defined
这篇关于调用网格动作的函数时请单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文