views:

63

answers:

0

Hi,

This is quite strange. here is the issue:

Some Info:

  1. I'm using a multi-select jqgrid.

  2. I have my own delete button to delete multiple orders

The problem:

When i press the delete button on the pager of my jqgrid, the records are deleted from the database but JqGrid shows some records (4-5). On refreshing the grid, correct numbers of records are shown.

Here is the code:

  function delorder() {

    var amg = $("#horder").getGridParam('selarrrow');
    var cont = amg.length;
    if (amg.length > 0) {
        if (confirm('Delete Selected Order(s)?')) {

            for (var i = 0; i < amg.length; i++) {

                var ret = $("#horder").getRowData(amg[i]);
                orparam.oid = ret.oid;
                $.ajax({
                    type: "POST",
                    url: "Orders.aspx/DelOrder",
                    data: "{'oid': '" + parseInt(orparam.oid) + "'}",
                    contentType: "application/json; charset=utf-8",
                    cache: true,
                    dataType: "json",
                    success: function (response) {
                        if (response.d == "true") {
                            delflag = 3;

                            //$("#horder").clearGridData();
                            //loadordergrid();                                  
                        }
                        else
                        { alert('Not All Orders were Deleted!'); $("#horder").clearGridData(); loadordergrid(); }
                    },
                    error: function () {
                        alert('Sever Error Occured');
                    }

                });
            }
        }
    }
    else {
        alert('Please Select Atleast One Order To Delete');
    }
    if (delflag == 3) {

        $('#horder').jqGrid('GridUnload');
        loadgrid(); 
        alert('Orders Deleted!!!');
    }
}

A few things to be noted:

  1. Delete Query is working fine in my web service. there is no problem with that.

  2. Debugging showed that it went to the if which has delflag==3 and then went back to the ajax call's success function .... strange !!!!!!

  3. I have tried clearing the grid using clearGridData() but that did not work too