override jquery.yiigridview.js

file location is: yiiroot/framework/widjets/assets/gridview/jquery.yiigridview.js

I need to change one line in this file so that I can use it in my requirements.

the original code is:


				if (settings.ajaxUpdate.length > 0) {

					$(document).on('click', settings.updateSelector, function () {

						$('#' + id).yiiGridView('update', {url: $(this).attr('href')});

						return false;

					});

				}



I want to change it to:




                                if (settings.ajaxUpdate.length > 0) {

                                        $(this).parent().on('click', settings.updateSelector, function () {

                                                $('#' + id).yiiMyGridView('update', {url: $(this).attr('href')});

                                                return false;

                                        });

                                }



Now, what is the right way to override this without needing to change a yii source code file?

PS, to be honest I don’t know why exactly I had to make this change, but I know very well that I need to do it. Making this change has made my live happy again.

Try CClientScript::scriptMap.




Yii::app()->getClientScript()->scriptMap = array(

	'jquery.yiigridview.js' => Yii::app()->baseUrl . 'path/to/your/custom.js',

	...

);



P.S.

I don’t know if it’s a good thing for you to do this work around in the long run.

The original on(‘click’) is assigned to $(document), so that it will be effective after the grid is updated by ajax.

And maybe you had to cancel the on(‘click’) after ajax update by assigning it to $(this).parent() … which is reloaded by the ajax and on(‘click’) will be forgotten.

Not sure, but it’s just a guess. :)

Thank you,

your guess is nearly right

but my question is:… what would I put in the custom.js file so that I can override that very line of code without needing to override all the code?

You have to copy all the lines of jquery.yiigridview.js to your custome.js and edit the single line.

By defining the script map, Yii will load your custom.js instead of the standard one.

o_O I hoped there is a better way !!!

:D I agree that this is not by far a preferred way.

It’s just a guess, but I think you could stick to the original js with the help of CGridView::afterAjaxUpdate.