yii2 gridview,js未在页面上加载
我正在加载 gridview
public function actionIndex()
{
$searchModel = new ReconReportSearch();
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams);
return $this->render('index', [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
'company_list' => $companyList
]);
}
并且在视图中
use yii\grid\GridView;
echo GridView::widget([
'id' => 'recon_reports',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'accounting_year','accounting_month'
],
]);
我的模型和搜索模型将字段规则设置为“安全”
<?php
namespace app\models;
use app\models\ReconReport;
use yii\base\Model;
use yii\data\ActiveDataProvider;
/**
* Class ReconReportSearch
* @package app\models
*/
class ReconReportSearch extends ReconReport
{
public function rules()
{
return [
[['accounting_year','accounting_month'],'safe']
];
}
/**
* @param $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
if ($this->load($params) && $this->validate()) {
$this->_filtered = true;
}
$query = ReconReport::find()->with('company');
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
]);
$query->andFilterWhere(['=', 'accounting_year', $this->accounting_year]);
$query->andFilterWhere(['=', 'accounting_month', $this->accounting_month]);
return $dataProvider;
}
}
过滤器无法提交。 我追踪到 gridview.js 没有加载。
因此,没有启动任何查询。无论有没有 Pjax,该操作都不会再次被调用(我在调试器中等待该操作,并且它也会到达页面加载。此外,浏览器开发工具栏上的 NW 选项卡不会显示再次调用的操作。
第二次项目过滤正确,因为 gridview.js 已加载到页面上。
我还尝试手动添加 gridview js。首先,这并不能解决搜索未触发的问题。但是,我注意到 .js文件被列出两次,而当我不手动添加 .js 文件时,
我做错了什么?如何在页面上添加 gridview?
I am loading a gridview
public function actionIndex()
{
$searchModel = new ReconReportSearch();
$dataProvider = $searchModel->search(\Yii::$app->request->queryParams);
return $this->render('index', [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
'company_list' => $companyList
]);
}
And in the view
use yii\grid\GridView;
echo GridView::widget([
'id' => 'recon_reports',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'accounting_year','accounting_month'
],
]);
My model and searchmodel has the field rule as 'safe'
<?php
namespace app\models;
use app\models\ReconReport;
use yii\base\Model;
use yii\data\ActiveDataProvider;
/**
* Class ReconReportSearch
* @package app\models
*/
class ReconReportSearch extends ReconReport
{
public function rules()
{
return [
[['accounting_year','accounting_month'],'safe']
];
}
/**
* @param $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
if ($this->load($params) && $this->validate()) {
$this->_filtered = true;
}
$query = ReconReport::find()->with('company');
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
]);
$query->andFilterWhere(['=', 'accounting_year', $this->accounting_year]);
$query->andFilterWhere(['=', 'accounting_month', $this->accounting_month]);
return $dataProvider;
}
}
The filter is failing to submit.
I tracked this down to the gridview.js not loading.
As a result, there is no query being launched. The action is not called again, with or without Pjax (I wait on the action in the debugger and it also reaches on the page load. Additionally, the NW tab on the browser dev toolbar does not show the action being called again.
A second project filters properly because the gridview.js is loaded on the page. There is nothing extra in both projects to add or configure gridview.
I also tried manually adding the gridview js. Firstly this does not solve the problem of the search not being fired. However, I notice the .js file is listed twice, compared to zero times when I do not manually add the .js file.
What am I doing wrong? and how can I add gridview on the page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论