A
A
Alexey2015-10-11 15:07:31
Yii
Alexey, 2015-10-11 15:07:31

Yii2 Filtering ListView by click and split by dates, how to implement?

Hello! Need help with filtering data displayed through ListView.
There is a CrmController.php controller that passes all data to the view

public function actionIndex()
    {
        $dataProvider = new ActiveDataProvider([
            'query' => Requests::find()->orderBy('id ASC'),
            'pagination' => [
                'pageSize' => 10,
            ],
        ]);

        $this->view->title = 'CRM';
        return $this->render('index', ['listDataProvider' => $dataProvider]);
    }

There are 2 view files index.php
<?= ListView::widget([
    'dataProvider' => $listDataProvider,
    'itemView' => '_item',
]); ?>

and _item.php
<?php
use yii\helpers\Html;
?>  
    <tr>
      <td><?=$model->date; ?> <?=$model->time; ?></td>
      <td><?=$model->type;?></td>
      <td><?=$model->contacts;?></td>
      <td><?=$model->content;?></td>
      <td><?=$model->status;?></td>
      <td><i class="fa fa-pencil"></i> <i class="fa fa-star-o"></i></td>
    </tr>

Question one: On the same page there are buttons for sorting by a certain date, status and type. How to implement sorting when clicking on one of the buttons?
Question two: When displaying all the data in the table, you need to make sure that the records are grouped by date, for example
Today -> Below are all records for today, Yesterday -> Below are all records for the last day, how can this be done in ListView?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2015-10-11
@SamarNevil

You need to create a SearchModel and use it.
read everything here: www.yiiframework.com/doc-2.0/guide-output-data-wid...
and a bit here: www.yiiframework.com/doc-2.0/guide-output-sorting.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question