using kartik date range picker for filtering in gridview

Hi I am trying to use the Kartik Date Range picker for filter in gridview.

I have a column date_time field as discharge_date, the widget is showing fine in the gridview but the filtering is not working at all.

This is my code in the Gridview:




                'filterType' => GridView::FILTER_DATE_RANGE,

                'filterWidgetOptions' =>([











Any idea, where I am going wrong.


I have achieved that with the below setup, based on ideas from this link : (check a comment below from Claudio).


    'attribute' => 'date',


    'filterType'=> \kartik\grid\GridView::FILTER_DATE_RANGE,

    'filterWidgetOptions' => [

    'presetDropdown' => true,

    'pluginOptions' => [

    'format' => 'YYYY-MM-DD',

    'separator' => ' TO ',


    ] ,

    'pluginEvents' => [

    "apply.daterangepicker" => "function() { aplicarDateRangeFilter('date') }",




It doesn’t work.

I have gone through the link, but it looks like it uses non English language and some additional code then ur suggestion, which is little difficult to grasp how to adapt that code.

Can you please provide some more detail how you have implemented it.


I made changes to both my index view and search model: Am using Kartik’s select 2 widget for the dropdown filter and the daterange filter for the date filter.

this is how my search model looks like:

public function search($params)


    $query = Contributions::find();


    $dataProvider = new ActiveDataProvider([

        'query' => $query,



    if (!$this->validate()) {

        // uncomment the following line if you do not want to any records when validation fails

        // $query->where('0=1');

        return $dataProvider;



        'contributionid' => $this->contributionid,

        'amount' => $this->amount,


    $query->andFilterWhere(['like', 'members.memberid', $this->memberid]);

    $query->andFilterWhere(['like', 'comment', $this->comment]);

    if(isset($this->date) && $this->date!=''){

    $date_explode = explode("TO", $this->date);

    $date1 = trim($date_explode[0]);

    $date2=  trim($date_explode[1]);

    $query->andFilterWhere(['between', 'date', $date1,$date2]);


    return $dataProvider;


below is my index view file:


use yii\helpers\Html;

//use yii\grid\GridView;

use kartik\grid\GridView;

/* @var $this yii\web\View */

/* @var $searchModel frontend\models\ContributionsSearch */

/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = ‘Contributions’;

$this->params[‘breadcrumbs’][] = $this->title;


<div class="contributions-index">

&lt;h1&gt;&lt;?= Html::encode(&#036;this-&gt;title) ?&gt;&lt;/h1&gt;

&lt;?php // echo &#036;this-&gt;render('_search', ['model' =&gt; &#036;searchModel]); ?&gt;


    &lt;?= Html::a('Create Contributions', ['create'], ['class' =&gt; 'btn btn-success']) ?&gt;



use frontend&#092;models&#092;Members;

&#036;members=  Members::find()-&gt;all();

use yii&#092;helpers&#092;ArrayHelper;

&#036;items=  ArrayHelper::map(&#036;members, 'memberid', 'name');    

// Generate a bootstrap responsive striped table with row highlighted on hover


    ['class' =&gt; 'kartik&#092;grid&#092;SerialColumn'],        





        'attribute' =&gt; 'memberid',

        'filter'=&gt;ArrayHelper::map(Members::find()-&gt;orderBy('name')-&gt;asArray()-&gt;all(), 'memberid', 'name'),  

        'filterType' =&gt; GridView::FILTER_SELECT2,




        'filterInputOptions'=&gt;['placeholder'=&gt;'Select Member'],




        'class' =&gt; '&#092;kartik&#092;grid&#092;DataColumn',

        'attribute' =&gt; 'amount',


        'pageSummary' =&gt; true




    'attribute' =&gt; 'date',


    'filterType'=&gt; &#092;kartik&#092;grid&#092;GridView::FILTER_DATE_RANGE,

    'filterWidgetOptions' =&gt; [

    'presetDropdown' =&gt; true,

    'pluginOptions' =&gt; [

    'format' =&gt; 'YYYY-MM-DD',

    'separator' =&gt; ' TO ',


    ] ,

    'pluginEvents' =&gt; [

    &quot;apply.daterangepicker&quot; =&gt; &quot;function() { apply_filter('date') }&quot;,




    ['class' =&gt; 'kartik&#092;grid&#092;ActionColumn']


echo GridView::widget([

    'dataProvider'=&gt; &#036;dataProvider,

    'filterModel' =&gt; &#036;searchModel,


    'columns' =&gt; &#036;gridColumns,




    'showPageSummary' =&gt; true,









<script type="text/javascript">

function apply_filter() {




This may not be the most efficient implementation but it works and I would like to get more information and suggestions on this too. The javascript function at the end of the index view file helps to reload the grid once a selection of daterange is changed.Hope this helps