jqueryjqgridstruts2-jquerystruts2-jquery-pluginstruts2-jquery-grid

Struts2 Jquery jqGrid beforeShowForm Example


I'm looking for a way to use the beforeShowForm event when opening the edit dialog on a struts2-jquery grid. I want to be able to add custom fields to the edit dialog.

<sjg:grid
        altRows="false"
        id="gridtable"
        dataType="json"
        editurl="%{editurl}"
        filter="true"
        filterOptions="{stringResult:true}"
        gridModel="gridModel"
        height="600"
        href="%{remoteurl}"         
        loadonce="true"
        navigator="true"
        navigatorAdd="%{editPermission}"
        navigatorAddOptions="{reloadAfterSubmit:true,addCaption:'Add Record'}" 
        navigatorDelete="false"
        navigatorEdit="%{editPermission}"
        navigatorRefresh="true"
        navigatorSearch="false"
        onCompleteTopics="loadComplete"
        onSelectRowTopics="rowselect"
        pager="true"
        pagerButtons="true"
        rowList="25,50,100"
        rowNum="25"
        rownumbers="true"
    >

However, I'm having issues understanding how to utilize the beforeShowForm event with the sjg tag. I've search for the solution for days, but all of them seem to be only when using regular jqGrid and not the sjg tag specifically. Most examples seem to reference the jqGrid wiki, but again I don't understand the way to access that event. Can someone please give me an example of assigning a function to beforeShowForm on the edit button within the sjg tag?

Thanks


Solution

  • I don't use struts2 myself. I suppose that the id of the grid is "gridtable". I suggest you to use jQuery events instead of callbacks. You need just to use jQuery.bind. The most callbacks have the corresponding jQuery events which exist in jqGrid starting with version 4.3.2. The most difference of the usage of jQuery events is adding of additional first parameter which gives you not so much information in our case. You can use for example

    $("#gridtable").bind("jqGridAddEditBeforeShowForm", function (e, $form, oper) {
        alert("In jqGridAddEditBeforeShowForm");
    });
    

    In the way you can transform the most other solutions which you will find in the usage of jQuery events.