1

I have Kartik gridView and custom filter. After gridfilter in my browser i got URL like

localhost:20024/consignment?fid=&post_code=&pud2_mrn=&pud2_status=PUDP&pud_status=&pud2_remaining_date=&mrn=&mrn_status=&ioss_number=&declaration_type=&status=&entry_at=&exit_at=&created_at=

Is there a way to remove unfilled parameters from url inside YII instead javascript? Or can anybody provide full example of javascript to achieve the goal.

4
  • You may want to look at github.com/yiisoft/yii2/pull/16848. I don't think there is anything like that merged in framework, but you could patch it. Commented Dec 3, 2021 at 12:59
  • @rob006 Thank you for your response, but this doesn't fit my need. First of all because i am using Kartik and second i cant rewrite vendor files Commented Dec 3, 2021 at 13:26
  • I'm pretty sure that Kartik is using default scripts from Yii 2 to handle filtering. Commented Dec 3, 2021 at 16:06
  • @rob006 it is still in vendor, sorry Commented Dec 3, 2021 at 19:34

1 Answer 1

1

Copy vendor/yiisoft/yii2/yii.gridView.js somewhere under web directory (e.g. web/js and add this line:

$.each(data, function (name, value) { if (value[0].length === 0) data[name] = null; });

prior this line in applyFilter method:

var pos = settings.filterUrl.indexOf('?');

Then add this to web.conf (update paths if you used different place for this js file):

'assetManager' => [
    'bundles' => [
        'yii\grid\GridViewAsset' => [
            'sourcePath' => '@webroot/js',
            'basePath' => '@webroot/js',
            'baseUrl' => 'vendor/js',
        ],
    ],
],

This was you are not modifying anything in the vendor folder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.