简体   繁体   中英

Yii2 Ajax Filter onblur

I'm new to yii2 web development and it's the first time I work with javascript. I've already made search results appear using JPax. I only need to start filtering results (inside Gridview) as soon as user removes cursor from either search field (name/price) of course without pressing the search button. I think it has to do with onblur. The problem is I don't have any idea where should I start. Do I have to write inline js code inside text fields? Or create an asset? What should I do?

在此处输入图片说明

I think there are two ways.

1-Create a asset

You can create a asset with your own JS and CSS files

Here a great guide to use it

2-Register only one JS

View Class have a really usefull method, registerJsFile() you can use it to load an specific JS to your view.

In controller you can use:

Yii::$app->view->registerJsFile('path/file.js', [
                                    'depends' => [
                                         'yii\web\YiiAsset',
                                         'yii\bootstrap\BootstrapAsset',
                                    ]
                                ]);

Use depends option to load your js AFTER Jquery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM