简体   繁体   中英

JqGrid tables reloading after editing and saving any row

I have 4 jqGrid tables in a php file and passsing different json array for the each grid tables.The data which i am displaying on grid are from 1 table with different sql conditions.

I am using inline editing functionality for all the grids and when i edit and save the row from table1, i want all the grids should get refresh so that if the row which was previously edited is exists in next tables that should get vanished automatically. I want to reload the all the grid tables after editing any row in any table. I have written the following code:

<table id="jqgrid"></table>
<div id="pjqgrid"></div>

<table id="jqgrid1"></table>
<div id="pjqgrid1"></div>

<table id="jqgrid2"></table>
<div id="pjqgrid2"></div>

<table id="jqgrid3"></table>
<div id="pjqgrid3"></div>

<script>
pageSetUp();
var myEditOptions = {
    keys: true,
    successfunc: function (response) {
       // alert(JSON.stringify(response)); 
        var msg=response.responseText;
        var n =msg.search("Updated");
        //alert(n);
        if(n>=0)
        {
            $(".inner").html("<div class='alert alert-success fade in'>     <button class='close' data-dismiss='alert'>X</button><i class='fa-fw fa fa-thumbs-up'></i>  "+msg+" </div>");
        } 
        else
        {
            $(".inner").html("<div class='alert alert-danger fade in'><button class='close' data-dismiss='alert'>X</button><i class='fa-fw fa fa-thumbs-down'></i>  "+msg+" </div>");      
        }
        $("#jqgrid").trigger('reloadGrid');
        $("#jqgrid1").trigger('reloadGrid');
        $("#jqgrid2").trigger('reloadGrid');
        $("#jqgrid3").trigger('reloadGrid');
        jQuery("#jqgrid").jqGrid('resetSelection');
        jQuery("#jqgrid1").jqGrid('resetSelection');
        jQuery("#jqgrid2").jqGrid('resetSelection');
        jQuery("#jqgrid3").jqGrid('resetSelection');
        return true;     
    },
    errorfunc: function (rowid,response) {
        //alert(rowid);
    },
    afterrestorefunc:function (rowid,response) {
        jQuery("#jqgrid").jqGrid('resetSelection');
    }

};
</script>

It would you recommend to use aftersavefunc instead of successfunc for reloading of the grids. Moreover you should place .trigger("reloadGrid") inside of setTimeout . It will allows to finish processing of editing before starting reloading:

var myEditOptions = {
    keys: true,
    aftersavefunc: function () {
        setTimeout(function () {
            $("#jqgrid,#jqgrid1,#jqgrid2,#jqgrid3").trigger("reloadGrid");
        }, 50);
    },
    ...
};

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