开发者

Fire an event after a local delete jqgrid

So what I am trying to do is fire an event AFTER a local delete has been done on the jqgrid. The reason for this is because I am dealing with a global save on the website so I am not posting directly to the server. I am storing the data in JSON form within a hidden element on the page so when the user finally saves the element value is grabbed and sent to the server along with all the other data.

The issue I am having is that when I delete a row from the jqgrid I am not able to update the hidden element with the change, so if the user saves after that it is like the remove never happened.

      $("#translationMappingGrid").jqGrid({
    data: mydata, 
    datatype: "local", 
    mtype: 'GET',
    colNames:['From','To', 'Type'],
    colModel :[ 
        {name:'from',index:'from', width:180, align:"left",sorttype:"float", editable: true, editrules:{custom:true, custom_func:validateIPGridInput}}, 
        {name:'to',index:'to', width:180, align:"left",sorttype:"float", editable: true, editrules:{custom:true, custom_func:validateIPGridInput}}, 
        {name:'type',index:'type', width:200,align:"left",sorttype:"float", editable: true, 
            edittype:"select", formatter:'select', editoptions:{
                value:"0:Never Translate;1:Always Translate;2:Only If Source;3:Only If Destination"}
        }, 
    ],
    pager: '#pager',
    rowNum:10,
    rowList:[10,20,30],
    sortname: 'invid',
    sortorder: 'desc',
    viewrecords: true,
    gridview: true,
    caption: 'Mapping',
    editurl: 'probe.sysinfo.ajax',
    url:'clientArray',
    onSelectRow: function(id){ 
            jQuery('#translationMappingGrid').jqGrid('restoreRow',lastsel2); 
            //below are the parameters for edit row, the function is called after a successful edit has been d开发者_Go百科one
            //jQuery("#grid_id").jqGrid('editRow',rowid, keys, oneditfunc, succesfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc);
            jQuery('#translationMappingGrid').jqGrid('editRow',id,true,"","","","",function () {
                setTranslationMappingJSON(getGridDataJSONString(this));
                window.parent.document.getElementById('notificationDiv').style.display= "";
                }); 

            lastsel2=id; 
    },
    afterInsertRow: function(rowid, rowdata, rowelem ){
        //alert("after insert row");
        setTranslationMappingJSON(getGridDataJSONString(this));
        window.parent.document.getElementById('notificationDiv').style.display= "";
    }


  });

  //adds buttons to jqgrid nav bar
  jQuery("#translationMappingGrid").navGrid('#pager',{
        edit:false,add:true,del:true,search:false,refresh:true
        }, {
            closeAfterAdd:true,
            closeAfterEdit: true
        },
        {
            closeAfterAdd:true,
            closeAfterEdit: true,
            afterSubmit: function(response, postdata) {
                alert("after complete row");
                setTranslationMappingJSON(getGridDataJSONString(this));
                window.parent.document.getElementById('notificationDiv').style.display= "";
                return [true,""];
            }
        });

As indicated in the code above I am successfully updating the hidden element with the changes on both add and edit (inline) via afterrestorefunc, but this is not working for delete.

I have tried using afterSubmit in the code above, but this is not working either. I have been working on this for a few days now and have come to the conclusion that I might have to write my own custom code for the delete button entirely, but I am hoping this is not the case.


The OP wrote in an edit:

So it appears as though I was staring at the issue for too long and was missing the obvious....lucky me. I found out two things:

  1. Using afterSubmit was the wrong thing to use, instead I should be using afterComplete.

  2. I had tried using afterComplete before trying afterSubmit and the reason it was not working it because I am putting them both within the "add" parameters and NOT the delete. Once again, I feel pretty awesome for that one :)

Well now that I have figured that out here is the code snippet that saved my life:

    jQuery("#translationMappingGrid").navGrid('#pager',{
    edit:false,add:true,del:true,search:false,refresh:true
    }, {
        closeAfterAdd:true,
        closeAfterEdit: true
    },
    {
        closeAfterAdd:true,
        closeAfterEdit: true
    },{
        afterComplete:
            function () {
                //saves the changed JSON string to the hidden element
                setTranslationMappingJSON(getGridDataJSONString(jQuery('#translationMappingGrid')));
                window.parent.document.getElementById('notificationDiv').style.display= "";
            }                       
    });

This is tested and the function is called after the delete has been performed and saves the local changes to my hidden element.

For anyone who is curious about what the format is:

          /* The following is the setup 
        navGrid(<name>, {<buttons, true/false},
        {
        <edit parameters>
        },
        {
        <add parameters>
        },
        {
        <delete parameters>
        }  
      */

Thanks for everyone who might have started working on this, and definitely thanks to the developers of jqgrid. Best javascript grid I have ever worked with!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜