2012-05-06 4 views
1

파일 위치는 다음과 같습니다. yiiroot/framework/widjets/assets/gridview/jquery.yiigridview.js 내 요구 사항에서이 파일을 사용할 수 있도록이 파일의 한 줄을 변경해야합니다.yiiframework에서 jquery.yiigridview.js를 재정의하는 방법

//original code line 79,80 
       if (settings.ajaxUpdate.length > 0) { 
        $(document).on('click.yiiGridView', settings.updateSelector, function() { 

//I need to change it to : 

       if (settings.ajaxUpdate.length > 0) { 
        $(this).parent().on('click.yiiGridView', settings.updateSelector, function() { 

소스 코드 파일을 변경하지 않고 이것을 무시하는 올바른 방법은 무엇입니까?

답변

2

아래 jQuery's off method을 사용하는 것이 작업을 수행하는 또 다른 방법을 도시 한 바와 같이 수정 된 파일 폴더에있는 gridview에 baseScriptUrl 속성을 추가하고 경로에 그것을 설정합니다.

이미 jquery.yiigridview.js에 추가되는 이벤트 핸들러를 제거하고 on을 사용하여 새 처리기를 추가 할 수 있습니다 off 사용. (그리드 뷰를 가지고 뷰에서)이 같은

뭔가 :

<?php 
Yii::app()->clientScript->registerScript('myownhandlers', 
    " 
     $(document).off('click.yiiGridView', $.fn.yiiGridView.settings['your-grid-id'].updateSelector); // this will remove the jquery.yiigridview.js handler 

     // assign the new handler, instead of $(this) you have to use the id of the element you are interested in 
     $('#the-id-you-are-interested-in').parent().on('click.yiiGridView', settings.updateSelector, function() { 
     // your function's code, you'll have to write your function 
     }); 
    ", 
    CClientScript::POS_LOAD // this is important because the default is POS_READY, and the gridview is available only after load 
); 
?> 

읽기에 대한 the on method에 너무 코드의 더 나은 이해를 얻을 수 있습니다.

참고 : 이벤트 공간 즉 click.yiiGridView 실제로 내가 가지고 YII 버전에서, 올바른

관리법은 네임 스페이스가없고 그냥 click을, 그래서 무시하기 전에 확인하십시오.

+0

btw, 어떤 방식 으로든이 [중첩 된 격자에 관한 다른 질문] (http://stackoverflow.com/questions/10284068/yii-cgridview-ajaxupdate-property)과 관련이 있습니까? 이게 그 문제를 해결할 수 있을까요? –

+1

registerScript 다음에 "->"를 제거하십시오. – dzona

+0

@ dzona 저를 가리켜 주셔서 감사합니다. –

2

yiiroot/framework/zii/widgets/assets/gridview/ 폴더의 전체 내용을 클라이언트가 액세스 할 수있는 위치, 예를 들어 your_web_app_dir/gridview에 복사하고 원하는대로 수정하십시오.

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'model-grid', 
    'baseScriptUrl'=>Yii::app()->baseUrl.DIRECTORY_SEPARATOR.'gridview', 
    'dataProvider'=>$datatProvider, 
    'columns'=>array(
    .... 
    .... 
    ), 
    )); ?> 
+0

감사합니다. 변경해야하는 유일한 줄을 재정의하기 위해 jquery 코드를 사용하는 방법이 있기를 바랍니다. –

관련 문제