Yii CGridView将数组排序为dataProvider

时间:2014-04-24 07:30:59

标签: php twitter-bootstrap yii

我有一个数组作为我的dataProvider(我也设置了自定义过滤器方法)它看起来和工作正常:

enter image description here

但是现在,出于响应的目的,我需要删除小型设备上的过滤器,我已经完成了这样的过程:

, 'htmlOptions' => array( 'class' => 'hidden-sm hidden-xs hidden-md' )
, 'headerHtmlOptions' => array( 'class' => 'hidden-sm hidden-xs hidden-md' )
, 'filterHtmlOptions' => array( 'class' => 'hidden-sm hidden-xs hidden-md' )

并添加排序按钮,如下所示:

enter image description here

如何使用自定义排序图像添加排序选项?

我可以发布完整的GridView代码,但它有点长(因此自定义列)

更新

这就是我的dataProvider最后一个脚本的样子:

if ( isset( $_REQUEST['FiltersForm'] ) )
    $filtersForm->filters = $_REQUEST['FiltersForm'];

# Get rawData and create dataProvider
$filteredData = $filtersForm->filter( $model->results['company'] );
$dataProvider = new CArrayDataProvider( $filteredData );

# Render
$this->render( 'results', array(
    'filtersForm' => $filtersForm,
    'dataProvider' => $dataProvider,
    'model' => $model
) );

1 个答案:

答案 0 :(得分:0)

您可以使用Csort

在使用Csort的控制器设置Dataprovider中,Example

public function actionIndex(){
  $sort = new CSort();
  $sort->attributes = array(
    'customer'=>array(
    'asc'=>'customer.customer_name',
    'desc'=>'customer.customer_name desc',
  ),

  'school'=>array(
    'asc'=>'school.school_name',
    'desc'=>'school.school_name desc',
  ),
    'submitted_date',
    'requested_date',
 );

  $dataProvider=new CActiveDataProvider('Printjob', array(
   'criteria'=>array(
   'alias'=>'pj',
   'join'=>'inner join customer on customer.customer_id=pj.customer_id inner join school on school.school_id=pj.school_id',
),
'sort'=>$sort,
'pagination'=>array(
  'pageSize'=>self::PAGE_SIZE,
),
));
$this->render('index',array('dataProvider'=>$dataProvider));