yii cgridview 排序不起作用 [英] yii cgridview sort not working
问题描述
这是我的网格视图.当我单击电子邮件"标题时,标题旁边有一个箭头.但是 gridview 不会重新加载以对数据进行排序.
那么,什么是问题?我怎样才能找到它?
谢谢...
========================================================
这是我的观点:
widget('zii.widgets.grid.CGridView', array('id' =>'用户网格','数据提供者' =>$model->search(),'afterAjaxUpdate' =>'function(id, data) { var regex = data.match("data-counter=\"(.*)\"");$("#countUser").text(regex[1]);}','过滤器' =>$模型,'template'=>'{items}{pager}</div>','列' =>大批(大批('类' =>'CCheckBoxColumn','selectableRows' =>'2',),大批('htmlOptions' =>数组('宽度'=> 10),'标题' =>'不.','价值' =>'$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',),大批('名称' =>'全名','价值' =>'$data->first_name .\' \' .$data->last_name',),'电子邮件',大批('名称' =>'性别','价值' =>'($data-> 性别 == 1) ?Yii::t(\'app\', \'Male\') : Yii::t(\'app\', \'Female\')','过滤器' =>array('1' => Yii::t('app', 'Male'), '0' => Yii::t('app', 'Female')),),大批('名称' =>'生日','过滤器' =>$this->widget('zii.widgets.jui.CJuiDatePicker', array('模型'=>$模型,'属性'='生日','语言' =>'恩','i18nScriptFile' =>'jquery.ui.datepicker-ja.js',//(#2)'htmlOptions' =>大批('id' =>'datepicker_for_birthday','尺寸' =>'10',),'默认选项' =>数组(//(#3)'showOn' =>'重点','日期格式' =>'yy-mm-dd','showOtherMonths' =>真的,'selectOtherMonths' =>真的,'changeMonth' =>真的,'changeYear' =>真的,'showButtonPanel' =>真的,)),真),//(#4)),'家乡',大批('标题' =>'行动','类' =>'CButtonColumn',),),));?>这是我的控制器:
$model = new Users('search');$model->unsetAttributes();$this->render('index', array('模型' =>$模型,));
这是我的搜索代码:
公共函数搜索(){$criteria = 新的 CDbCriteria;$criteria->compare('id', $this->id);$criteria->compare('first_name', $this->first_name, true);$criteria->compare('last_name', $this->last_name, true);$criteria->compare('CONCAT(first_name, \' \', last_name)', $this->full_name, true);$criteria->compare('username', $this->username, true);$criteria->compare('email', $this->email, true);$criteria->compare('avatar', $this->avatar, true);$criteria->compare('home_town', $this->home_town, true);$criteria->compare('birthday', $this->birthday, true);$criteria->compare('gender', $this->gender);$criteria->compare('about_me', $this->about_me, true);$criteria->compare('password', $this->password, true);$criteria->compare('log_as', $this->log_as);$criteria->compare('token', $this->token, true);$criteria->compare('token_device', $this->token_device, true);$criteria->compare('notification_setting', $this->notification_setting, true);$criteria->compare('total_streams', $this->total_streams);$criteria->compare('total_punches', $this->total_punches);$criteria->compare('total_likes', $this->total_likes);$criteria->compare('status', $this->status);$criteria->compare('role_id', $this->role_id);$criteria->compare('long', $this->long);$criteria->compare('lat', $this->lat);$criteria->compare('social_id', $this->social_id);$criteria->compare('created_at', $this->created_at, true);$criteria->compare('updated_at', $this->updated_at, true);$criteria->addSearchCondition('concat(first_name, " ", last_name)', $this->full_name);$criteria->addCondition(array('condition'=>'role_id = 0'));///$criteria->condition = "role_id != 1";$criteria->order = '用户名';$sort = new CSort();$sort->attributes = array('full_name'=>数组('asc'=>'first_name ASC','desc'='=>'first_name DESC',),'*',//这会将所有其他列添加为可排序的);返回新的 CActiveDataProvider($this, array('标准' =>$标准,'排序' =>$排序,));}
解决方案 您的问题似乎是搜索功能中的 $criteria->order = 'username' 行.这表明结果应该如何排序.
如果你把它更新为 $criteria->order = Yii::app()->request->getParam('sort');(可能有一些验证和用户名"的默认值)那么你应该没问题.
This is my grid view. When I click "Email" header, there is a arrow beside the header. But the gridview not reload to sort data.
So, what is problem? How can I find it?
Thanks...
=======================================================
This is my view:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'users-grid',
'dataProvider' => $model->search(),
'afterAjaxUpdate' => 'function(id, data) { var regex = data.match("data-counter=\"(.*)\""); $("#countUser").text(regex[1]); }',
'filter' => $model,
'template'=>'{items}<div class="nav-controller">{pager}</div>',
'columns' => array(
array(
'class' => 'CCheckBoxColumn',
'selectableRows' => '2',
),
array(
'htmlOptions' => array('width'=>10),
'header' => 'No.',
'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
),
array(
'name' => 'full_name',
'value' => '$data->first_name . \' \' . $data->last_name',
),
'email',
array(
'name' => 'gender',
'value' => '($data->gender == 1) ? Yii::t(\'app\', \'Male\') : Yii::t(\'app\', \'Female\')',
'filter' => array('1' => Yii::t('app', 'Male'), '0' => Yii::t('app', 'Female')),
),
array(
'name' => 'birthday',
'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'birthday',
'language' => 'en',
'i18nScriptFile' => 'jquery.ui.datepicker-ja.js', // (#2)
'htmlOptions' => array(
'id' => 'datepicker_for_birthday',
'size' => '10',
),
'defaultOptions' => array( // (#3)
'showOn' => 'focus',
'dateFormat' => 'yy-mm-dd',
'showOtherMonths' => true,
'selectOtherMonths' => true,
'changeMonth' => true,
'changeYear' => true,
'showButtonPanel' => true,
)
),
true), // (#4)
),
'home_town',
array(
'header' => 'Action',
'class' => 'CButtonColumn',
),
),
));
?>
This is my controller :
$model = new Users('search');
$model->unsetAttributes();
$this->render('index', array(
'model' => $model,
));
This my search code:
public function search() {
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('first_name', $this->first_name, true);
$criteria->compare('last_name', $this->last_name, true);
$criteria->compare('CONCAT(first_name, \' \', last_name)', $this->full_name, true);
$criteria->compare('username', $this->username, true);
$criteria->compare('email', $this->email, true);
$criteria->compare('avatar', $this->avatar, true);
$criteria->compare('home_town', $this->home_town, true);
$criteria->compare('birthday', $this->birthday, true);
$criteria->compare('gender', $this->gender);
$criteria->compare('about_me', $this->about_me, true);
$criteria->compare('password', $this->password, true);
$criteria->compare('log_as', $this->log_as);
$criteria->compare('token', $this->token, true);
$criteria->compare('token_device', $this->token_device, true);
$criteria->compare('notification_setting', $this->notification_setting, true);
$criteria->compare('total_streams', $this->total_streams);
$criteria->compare('total_punches', $this->total_punches);
$criteria->compare('total_likes', $this->total_likes);
$criteria->compare('status', $this->status);
$criteria->compare('role_id', $this->role_id);
$criteria->compare('long', $this->long);
$criteria->compare('lat', $this->lat);
$criteria->compare('social_id', $this->social_id);
$criteria->compare('created_at', $this->created_at, true);
$criteria->compare('updated_at', $this->updated_at, true);
$criteria->addSearchCondition('concat(first_name, " ", last_name)', $this->full_name);
$criteria->addCondition(array('condition'=>'role_id = 0'));
///$criteria->condition = "role_id != 1";
$criteria->order = 'username';
$sort = new CSort();
$sort->attributes = array(
'full_name'=>array(
'asc'=>'first_name ASC',
'desc'=>'first_name DESC',
),
'*', // this adds all of the other columns as sortable
);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'sort' => $sort,
));
}
解决方案 Your problem seems to be the $criteria->order = 'username' line in your search function.
This is what indicates how the results should be sorted.
If you update this to $criteria->order = Yii::app()->request->getParam('sort'); (with some verification and a default value of 'username' perhaps) then you should be fine.
这篇关于yii cgridview 排序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文
相关文章
- Yii CGridview 使用 CSqlDataProvider 排序;
- Yii CGrid分页和CArrayDataProvider排序不起作用;
- YII 查询不起作用;
- Yii ClistView 分页不起作用;
- Yii ClistView分页不起作用;
- 排序不起作用;
- YII CGridView 错误;
- 事务在 Yii 中不起作用;
- 数组排序不起作用;
- Gridview排序不起作用;
- DataGrid排序不起作用;
- Yii cgridview ajaxUpdate 属性;
- Yii2.0 yiic 命令不起作用;
- yii2 表单验证不起作用;
- urlManager 在 Yii 2.0 中不起作用;
- Yii2自动登录不起作用;
- urlManager在Yii 2.0中不起作用;
- Yii2 Pjax删除不起作用;
- 合并排序不起作用。;
- 快速排序算法不起作用;
- jQuery DataTables排序不起作用;
- Flex arraycollection 排序不起作用;
- jQuery DataTables 排序不起作用;
- 角垫排序不起作用;
- MongoDB聚合排序不起作用;
PHP最新文章
- 请求头字段Access-Control-Allow-Headers在预检响应中不允许Access-Control-Allow-Headers;
- 路由问题导致Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException错误;
- 什么是NCFB和NOFB模式?;
- 警告:mysqli_connect():(HY000 / 1045):访问被拒绝用户'用户名'@'localhost'(使用密码:是);
- 如何处理致命错误:cURL错误7:无法连接到xxxx端口443;
- 参数3传递给GuzzleHttp\Client :: request()必须是数组类型,给定字符串;
- phpMyAdmin的#2054无法登录到MySQL服务器;
- SSL错误SSL3_GET_SERVER_CERTIFICATE:证书验证失败;
- 在PHPExcel中设置字体颜色,字体和字体大小;
- 如何解决cURL错误(7):无法连接到主机?;