1

I have a gridview inside the modal popup. I tried to sort the grid view columns inside the model popup. i tried with Pjax but it changes the page url. I want to sort gridview in the modal popup without changing the url. Code:

     <?php  \yii\widgets\Pjax::begin();
             echo GridView::widget([
                 'dataProvider' => $dataProvider,
                 'filterModel' => $searchModel,
                 'id' => 'data_lines_tables',
                 'columns' => [
                          [
                           'name',
                            'id'
                           ]
                         ]
                  ]);
            \yii\widgets\Pjax::end();?>
Janani Kumar
  • 371
  • 3
  • 18

2 Answers2

1

By default, Pjax will use pushState to update url, you should simply disable this by using :

\yii\widgets\Pjax::begin(['enablePushState' => false]);

Read more about Pjax widget.

soju
  • 25,111
  • 3
  • 68
  • 70
  • 1
    I have resolved my issue, its because i didnt gave unique id to PJAX. \yii\widgets\Pjax::begin(['enablePushState' => false,'id' =>'UniQueiD']); so sorting results are displayed in the modal itself – Janani Kumar May 12 '16 at 11:11
0

Hi there are two ways to do sorting for Cgridview in Modal popup, I have tried in bootstrap modal popup.

  1. Try using the CSort. Please remember, they keys in in $sort->attributes should match columns in the CGridView:

    public function actionIndex(){
    $sort = new CSort();
    $sort->attributes = array(
    'employee'=>array(
      'asc'=>'employee.name',
      'desc'=>'employee.name desc',
    ),
    'company'=>array(
      'asc'=>'company.company_name',
      'desc'=>'company.company_name desc',
    ),
    );
    
    $dataProvider=new CActiveDataProvider('job', array(
     'criteria'=>array('Criteria goes here'),
     'sort'=>$sort,
    ));
    $this->render('index',array(
    'dataProvider'=>$dataProvider,
    ));
    
  2. You can also use the sort like this, if u want to sort according to time or id whatever you choose according to your fields in database.

    $dataProvider=new CActiveDataProvider('job', array(
        'criteria'=>array('Criteria goes here'),
        'sort'=>array(
            'defaultOrder'=>'createTime DESC',
            ),
     ));
    
Asfandyar Khan
  • 1,677
  • 15
  • 34