Can I refresh a Yii CGridView from js?

18,445

Execute $.fn.yiiGridView.update("<id of CGridView>");

Share:
18,445
Brian Dunn
Author by

Brian Dunn

Updated on June 04, 2022

Comments

  • Brian Dunn
    Brian Dunn almost 2 years

    When a "Create" modal dialog is submitted via XHR Then the rows in a Yii CGridView should be refreshed.

    I've tried to achieve this by rendering the new gridview in the XHR "create" action and then inserting it into the page via $("#list").html(response), but rendering a CGridView causes jQuery <script> include tags to be registered for inclusion, and so when I introduce those tags into the page they reload jQuery, which wipes out my live event handlers, so a bunch of stuff breaks.

    Which has me thinking, "the GridView knows how to refresh itself. heck, it does all the time on sort or page."

    So I can click a sort button in the GridView from js, but thats less than Ideal. I'd prefer to say

    $("#list").gridview('reload') or $.fn.gridview.reload("#list") or some such sense.

    Or do the way cool thing that is soo much simpler that you thought of just now.