简体   繁体   English

第一次ajax调用后yiiGridView分页不起作用

[英]yiiGridView pagination is not working after first ajax call

I have one page there are four gridviews in one page. 我有一页,一页中有四个gridviews。 When i click on any pagination page button (ex : 1,2,3,4,5,6) It takes me to that page without any problem [via ajax]. 当我单击任何分页页面按钮(例如:1、2、3、4、5、6)时,[通过ajax]我可以毫无问题地转到该页面。 And replaces new html with old html. 并用旧的html替换新的html。 But now when i click on pagination button it just redirects to the url. 但是现在,当我单击分页按钮时,它仅重定向到URL。 It do not get loaded via ajax. 它不会通过ajax加载。 Whole page gets refreshed. 整个页面都会刷新。

It works when on click of one page button.If i initialize through console. 单击一页按钮时它可以工作。如果我通过控制台初始化。 Like when i put this and press enter in console then It will work for next page call. 就像当我把它放在控制台上按Enter时,它将适用于下一个页面调用。 And for again i have to initialize via console to make it work for next page button press. 再次,我必须通过控制台进行初始化,以使其可用于下一页按钮的按下。

        $('#answer-grid').yiiGridView({'ajaxUpdate':['answer-grid'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'table table-responsive','selectableRows':1,'pageVar':'saved_card_id_page'});

I try to add script in ajax loaded copntent but it did not worked. 我尝试在ajax加载的copntent中添加脚本,但没有成功。 Not event Alert got excuted. 不是事件警报受到谴责。

<script type='application/javascript'>

    alert("This is also not getting executed. When it comes from ajax content.")

</script>

I know may be they strips down the all content except the gridview div. 我知道可能是他们剥离了除gridview div之外的所有内容。 But the same thing works in other project. 但是同一件事在其他项目中也有效。

I use afterAjaxUpdate parameter did this. 我使用afterAjaxUpdate参数做到了这一点。

        'afterAjaxUpdate'=>"function(id, data){

             var newHtml = $('<div></div>');
             newHtml.append(data);

             var scriptExecute = newHtml.find('#scriptExecute');

             $('body').append(scriptExecute);

        }",

so now my script is getting executed as i append this to body. 所以现在我的脚本正在执行,因为我将其附加到正文中。 This was the scripts i append to the body as i can only do this way It is not proper way but it works.. 这是我附加到正文的脚本,因为我只能这样做,这不是正确的方法,但是可以。

<?php

$true = Yii::app()->request->isAjaxRequest;
if($true)
{

?>

<script type="application/javascript"  id="scriptExecute" >

        //alert("Execute this");

        jQuery('#share-grid').yiiGridView({'ajaxUpdate':['share-grid'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'table table-responsive','selectableRows':1,'pageVar':'CardShare_page','afterAjaxUpdate':function(id, data){

            var newHtml = $('<div></div>');
            newHtml.append(data);

            var scriptExecute = newHtml.find('#scriptExecute');


            $('body').append(scriptExecute);


        }});
        jQuery('#rate-grid').yiiGridView({'ajaxUpdate':['rate-grid'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'table table-responsive','selectableRows':1,'pageVar':'RatingLike_page','afterAjaxUpdate':function(id, data){

            var newHtml = $('<div></div>');
            newHtml.append(data);

            var scriptExecute = newHtml.find('#scriptExecute');

            $('body').append(scriptExecute);

        }});
        jQuery('#saved-card-grid').yiiGridView({'ajaxUpdate':['saved-card-grid'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'table table-responsive','selectableRows':1,'pageVar':'SavedCard_page','afterAjaxUpdate':function(id, data){

            var newHtml = $('<div></div>');
            newHtml.append(data);

            var scriptExecute = newHtml.find('#scriptExecute');

            $('body').append(scriptExecute);

        }});
        jQuery('#answer-grid').yiiGridView({'ajaxUpdate':['answer-grid'],'ajaxVar':'ajax','pagerClass':'pager','loadingClass':'grid-view-loading','filterClass':'filters','tableClass':'table table-responsive','selectableRows':1,'pageVar':'saved_card_id_page','afterAjaxUpdate':function(id, data){

            var newHtml = $('<div></div>');
            newHtml.append(data);

            var scriptExecute = newHtml.find('#scriptExecute');

            $('body').append(scriptExecute);

        }});

</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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