kartik-v / yii2-widget-select2

Enhanced Yii2 wrapper for the Select2 jQuery plugin (sub repo split from yii2-widgets).
http://demos.krajee.com/widget-details/select2
Other
323 stars 145 forks source link

Last item can't be removed in multiple GridView filter #145

Closed shum16 closed 6 years ago

shum16 commented 8 years ago

I'm using Select2 as a multiple GridView filter. And it works fine afterall, except for one thing: it's not possible to remove the last selected item from the list. Every time I try to do that, it reloads the grid with the same item in the filter, - becasue the value comes again with $_GET array!

Here's how it looks like: filter

Here's the column definition:

[
            'label' => 'Status',
            'class' => 'kartik\grid\DataColumn',            
            'attribute' => 'kid_status',            
            'filter' => Select2::widget([
                'name' => 'kid_status',             
                'data' => ['1' => 'status 1', '2' => 'status 2', ],
                'value' => isset($params['kid_status']) ? $params['kid_status'] : null,
                'language' => 'ru',
                'options' => [             
                    'placeholder' => 'Select status...',
                    'multiple' => true
                ],
                'pluginOptions' => [
                    'tags' => true,                     
                    'allowClear' => false,
                ],                    

             ]),                    
            'vAlign'=>'middle',
            'hAlign'=>'center',             
            'width' => '130px !important '
        ],      
shum16 commented 8 years ago

I wonder if nobody uses Select2 as a multifilter...

armpogart commented 8 years ago

@shum16 I have the same issue, after clearing the last item, it remains there.

shum16 commented 8 years ago

up!

abalest14 commented 8 years ago

i have the same issue, please help us!

abalest14 commented 8 years ago

no fix or workaround for this issue? thanks

kartik-v commented 8 years ago

Will need to check on this...

kartik-v commented 8 years ago

Set allowClear to true and then use the main CLEAR cross button to clear all selected items in the multi select.

shum16 commented 8 years ago

Kartik, this solution doesn't work!

abalest14 commented 8 years ago

Even for me dosent work. At the moment i have resolved moving the search fields outside the gridview like this work like a sharm.

Il 15/ago/2016 14:19, "shum16" notifications@github.com ha scritto:

Kartik, this solution doesn't work!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kartik-v/yii2-widget-select2/issues/145#issuecomment-239788916, or mute the thread https://github.com/notifications/unsubscribe-auth/AOVz3JiQ7sVQqFv00QIg6ozJZv8Raeucks5qgFlVgaJpZM4INg45 .

shum16 commented 8 years ago

Kartik, any news on this issue?

kartik-v commented 8 years ago

Will need to study this. Unfortunately it seems this is out of scope of both the Select2 widget as well as this extension... but more to do with how you load search model using mass assignment and write your search method to filter grid rows. There needs to be some way you can trap the last unselected data.

Will check back to see if there is something that can be done here when I get some time.

shum16 commented 8 years ago

@kartik-v , ok, thank you.

shum16 commented 8 years ago

@kartik-v any news on this issue?

kzpromo commented 6 years ago

i have the same problem, @kartik-v can you help?

abalest14 commented 6 years ago

this issue still not resolved? i have start a new project and still have the problem. thanks

pamkil commented 6 years ago

Whether is understanding when it is possible to wait for a fix of this problem? thanks.

DarkDrim commented 6 years ago

I have this issue also.. Somebody know how to fix this?

$("#select2_id").select2("val", ""); does not work too...

PS It seems that this is a bug in yii2.. I tried other multi-select widgets and they have the same problem.

Update, I found solution: you need set 'filterUrl' => Url::to(["/your-grid-view-url"]), (in GridView)

garytopor commented 6 years ago

Kartik, help us please, we need go on developing. Fix this bug, please

kartik-v commented 6 years ago

Not sure this is an issue any more. It depends on how you are configuring this.

Check the updated grid demo - the author is a multi select filter and seems to work like a charm. Go through the demo config and let know if any issues.

playwolf719 commented 6 years ago

@kartik-v hi, same issue, what's the solution? Anyone can help me

pamkil commented 6 years ago

Working example. One column:

    [
        'attribute' => 'status_id',
        'label' => 'Статус',
        'enableSorting' => true,
        'filter' => Select2::widget([
            'name' => 'status',
            'pjaxContainerId' => $pjaxContainer,
            'value' => $_GET['status'] ?? '',
            'data' => $statuses,
            'size' => Select2::SMALL,
            'options' => [
                'multiple' => true,
                'placeholder' => Yii::t('admin', 'Не указан')
            ],
            'pluginOptions' => [
                'allowClear' => true,
                'required' => true
            ]
        ]),
        'content' => function ($model)  {
            ..... 
           return $str;
            }

            return $model->status ? $model->status->name : '';
        },
        'headerOptions' => ['style' => 'text-align:center;width:120px;']
    ]
cornernote commented 5 years ago

I got it to work by adding a hidden input with the same name right before the select2, eg:

$columns[] = [
    'attribute' => 'status',
    'filter' => Html::hiddenInput('CompanySearch[status]')
        . Select2::widget([
            'name' => 'CompanySearch[status]',
            'value' => $searchModel->status,
            'data' => $data,
            'options' => [
                'multiple' => true,
            ],
        ]),
]
kartik-v commented 5 years ago

As mentioned before - check the updated grid demo - the author is a multi select filter and seems to work like a charm. Go through the demo config and let know if any issues.

Daniel123wq commented 4 years ago

I got it to work by adding a hidden input with the same name right before the select2, eg:

$columns[] = [
    'attribute' => 'status',
    'filter' => Html::hiddenInput('CompanySearch[status]')
        . Select2::widget([
            'name' => 'CompanySearch[status]',
            'value' => $searchModel->status,
            'data' => $data,
            'options' => [
                'multiple' => true,
            ],
        ]),
]

this working, tky.