在yii2中将数据传递到下一页
Pass data to next page in yii2
我正在做一个项目要求是当用户单击gridview中的一行时,它应该打开一个名为check in的新控制器,并显示该特定行的所有已检入的用户。
我很困惑,而不是使用actioncolumn
和创建一个新的按钮或使用rowopions
无论如何,当我像这样使用rowoptions
[
'class' => 'yii'grid'ActionColumn',
'template' => '{index} {view} {update} {delete} ',
'buttons' => [
'index' => function ($url,$model) {
return Html::a('<span class="glyphicon glyphicon-user"></span>', $url);
},
]
],
当我使用javascript的代码
<?php
$this->registerJs("
$('tbody td').css('cursor', 'pointer');
$('tbody td').click(function (e) {
var id = $(this).closest('tr').data('id');
if (e.target == this)
location.href = '" . Url::to(['checkin/index' ]) . "?id=' + id;
});
");
?>
它给出了行点击事件发生的id,但它不重定向到"checkin/index
"页面它在相同的日期刷新,并且行id附加在url的末尾。
但是当我使用这个脚本
<?php
$this->registerJs("
$('td').click(function (e) {
var id = $(this).closest('tr').data('id');
if(e.target == this)
location.href = '" . Url::to(['checkin/index']) . "?id=' + id;
});
");
?>
它重定向到checkin/index
页面但url没有得到任何id
显示checkin/index/id=undefined
我想将id传递给checkinSearch
控制器,并且只显示单击行的数据。
你可以试试这个…例如
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'rowOptions' => function ($model, $key, $index, $grid) {
return ['id' => $model['student_id'], 'class' => 'action-tr', 'data-link' => urldecode(Url::toRoute(['/student/student-transaction/update', 'id' => $model['student_id']]))];
},
'columns' => [
['class' => 'yii'grid'SerialColumn'],
[
'attribute' => 'student_roll_no',
'value' => 'rel_Stud_Info.student_roll_no',
],
[
'class' => 'yii'grid'ActionColumn',
'template' => '{update} {delete}',
'contentOptions' => ['class'=>'action-td'],
],
],
]); ?>
并在Js下面注册以防止ActionColumn
重定向行点击。
<?php
$this->registerJs("
$(document).ready(function(){
$('.action-tr').on('click', 'td:not(.action-td)', function(){
//get the link from data attribute
var the_link = $(this).parent().attr('data-link');
//do we have a valid link
if (the_link == '' || typeof the_link === 'undefined') {
//do nothing for now
}
else {
//open the page
window.location = the_link;
}
});
});
"); ?>
这个例子是真实项目的一部分,对我有用。试一试…
相关文章:
- 数据表自动生成的序列号无法正常工作.对于每一页
- PagingToolbar的Extjs问题-下一页的数据相同
- 从页面上点击的链接中删除数据,然后移动到下一页&在CasperJS中重复
- 一页上的多个数据表不起作用
- 如何将数据传递到HighCharts中的下一页
- 如果下一页或其他某个页面 JQuery 数据表中存在该行,如何删除该行
- 使用滚动重新加载 Jqgrid 时出现问题 - 重复的行数据并缺少最后一页
- 如何一次获取一页的数据
- 数据表在页面加载时转到最后一页
- 选择2-无限滚动不加载带有远程数据的下一页
- 有两个html页面.当我从下一页恢复到第一页时,我希望保存第一页的数据状态
- 一页上有多个表的数据表
- 当一页上有超过24个表单时,操作表单数据
- 使用Backbone Collection一次获取多页数据
- 富文本编辑器(使用YUI简单文本编辑器)未将数据发送到下一页
- 从前一页的数据传输到第二页PHP/MySQL
- Javascript发布数据并转到下一页
- 在yii2中将数据传递到下一页
- 在JS中发送数据到下一页以触发事件
- 为什么下面的JSPDF代码在下一页上打印数据?