jqGrid Custom Edit Dialog

后端 未结 3 1869
轮回少年
轮回少年 2021-02-08 13:24

I am working to an application that uses jqGrid. The problem is that the edit dialog that should appear at row edit must have a specific layout. So I would prefer to load it via

3条回答
  •  余生分开走
    2021-02-08 13:55

    My edit dialog had too many fields and so became too high, so I had to put the fields side by side in 2 columns. I did it as follows:

    I tried various ways, using wrap(), etc, but found that the values are not posted to the server if you modify the original table structure. So I just cloned the tr elements, put them in new tables, and hid the old ones. I did not hide the whole table, so that the validation will still be visible. I put an onchange on the cloned elements to update the old ones. This works great. Parameter tableName is your jqgrid element id.

    var splitFormatted = false;
    function SplitFormatForm(tableName, add) {
      if (!splitFormatted) {
        splitFormatted = true;
        $("#FrmGrid_" + tableName).append('
    '); var cc = $("#TblGrid_" + tableName + "> tbody").children("tr").length; var s = (cc / 2) - 1; var x = $("#TblGrid_" + tableName + "> tbody").children("tr"); var i = 0; x.each(function (index) { var e = $(this).clone(); var oldID = e.attr("id") + ""; var newID = oldID; if (oldID.substring(0, 3) === "tr_") { newID = "clone_" + oldID; $(this).css("display", "none"); e.change(function () { $("#" + oldID + " > .DataTD > .FormElement").val($("#" + newID + " > .DataTD > .FormElement").val()); }); e.attr("id", newID); if (i++ < s) { $("#TblGrid_" + tableName + "_A").append(e); } else { $("#TblGrid_" + tableName + "_B").append(e); } } }); //This hack makes the popup work the first time too $(".ui-icon-closethick").trigger('click'); var sel_id = "'new'"; if (!add) { sel_id = jQuery('#'+tableName).jqGrid('getGridParam', 'selrow'); } jQuery('#'+tableName).jqGrid('editGridRow', sel_id, { closeAfterAdd: true, width: 800, afterSubmit: function (response, postdata) { return [response.responseText == 'OK', response.responseText]; } }); }}

    Call this code in your editOptions as follows:

    afterShowForm: function () { SplitFormatForm("SiteAccountsGrid", false); }
    

    提交回复
    热议问题