locked
Jqgrid Edit Dialog beforeInitData, beforeShowForm & afterShowForm code doen't reflect RRS feed

  • Question

  • User-893002196 posted

    Hi,

    I have Jqgrid, when the edit dialog form appear for the 1st times, the new code under beforeInitData, beforeshowform, aftershowform for edit Dialog doesn't work. I have to close the edit form & re-open then code under editDialog work.

    My editDialog code as below:-

    var updateDialog = {

    url: '@Url.Content("~/Home/AddItem/")',

    recreateForm: true,

    beforeInitData: function (formid) {

    needDisable = true;

    $("#pData").hide();

    $("#nData").hide();

    var list = $("#jqgITAsset");

    var ids = list.jqGrid('getGridParam', 'selarrrow');

    var count = ids.length;

    var id = "";

    for (var i = 0; i < count; i++) {

    id = id+","+ids[i];

    }

    //debugger;

    $.post('@Url.Content("~/Home/GetBulkEditFieldProperty")',

    { "varId": id.substring(1, id.length), "__RequestVerificationToken": '@GetAntiXsrfRequestToken()' },

    function (data3) {

    for (var j = 0; j < data3.length; j++) {

    if (j != data3.length) {

    $("#" + data3[j].field, formid).attr("readonly", data3[j].isBulkEditable == 1 ? false : "readonly");

    $("#" + data3[j].field, formid).attr("class", data3[j].isBulkEditable == 1 ? "FormElement ui-widget-content ui-corner-all" : "FormElement ui-widget-content-readonly ui-corner-all");

    if ($("#" + data3[j].field, formid).length > 0) {

    if ($("#" + data3[j].field, formid)[0].getAttribute("readonly") == "readonly" && data3[j].field.toLowerCase().indexOf("date") > -1) {

    $('#jqgITAsset').setColProp(data3[j].field, {

    editoptions: {

    dataInit: function (el) {

    if (data3[j]!== undefined && data3[j].isBulkEditable == 0) {

    $(el).datepicker("destroy");

    }

    }

    }

    });

    }

    }

    }

    }

    });

    },

    beforeShowForm: function (formid) {

    needDisable = true;

    $("#pData").hide();

    $("#nData").hide();

    var list = $("#jqgITAsset");

    var ids = list.jqGrid('getGridParam', 'selarrrow');

    var count = ids.length;

    var id = "";

    for (var i = 0; i < count; i++) {

    id = id+","+ids[i];

    }

    //debugger;

    $.post('@Url.Content("~/Home/GetBulkEditFieldProperty")',

    { "varId": id.substring(1, id.length), "__RequestVerificationToken": '@GetAntiXsrfRequestToken()' },

    function (data3) {

    for (var j = 0; j < data3.length; j++) {

    if (j != data3.length) {

    $("#" + data3[j].field, formid).attr("readonly", data3[j].isBulkEditable == 1 ? false : "readonly");

    $("#" + data3[j].field, formid).attr("class", data3[j].isBulkEditable == 1 ? "FormElement ui-widget-content ui-corner-all" : "FormElement ui-widget-content-readonly ui-corner-all");

    if ($("#" + data3[j].field, formid).length > 0) {

    if ($("#" + data3[j].field, formid)[0].getAttribute("readonly") == "readonly" && data3[j].field.toLowerCase().indexOf("date") > -1) {

    $('#jqgITAsset').setColProp(data3[j].field, {

    editoptions: {

    dataInit: function (el) {

    if (data3[j]!== undefined && data3[j].isBulkEditable == 0) {

    $(el).datepicker("destroy");

    }

    }

    }

    });

    }

    }

    }

    }

    });

    },

    afterShowForm: function (formid) {

    needDisable = true;

    $("#pData").hide();

    $("#nData").hide();

    var list = $("#jqgITAsset");

    var ids = list.jqGrid('getGridParam', 'selarrrow');

    var count = ids.length;

    var id = "";

    for (var i = 0; i < count; i++) {

    id = id+","+ids[i];

    }

    //debugger;

    $.post('@Url.Content("~/Home/GetBulkEditFieldProperty")',

    { "varId": id.substring(1, id.length), "__RequestVerificationToken": '@GetAntiXsrfRequestToken()' },

    function (data3) {

    for (var j = 0; j < data3.length; j++) {

    if (j != data3.length) {

    $("#" + data3[j].field, formid).attr("readonly", data3[j].isBulkEditable == 1 ? false : "readonly");

    $("#" + data3[j].field, formid).attr("class", data3[j].isBulkEditable == 1 ? "FormElement ui-widget-content ui-corner-all" : "FormElement ui-widget-content-readonly ui-corner-all");

    if ($("#" + data3[j].field, formid).length > 0) {

    if ($("#" + data3[j].field, formid)[0].getAttribute("readonly") == "readonly" && data3[j].field.toLowerCase().indexOf("date") > -1) {

    $('#jqgITAsset').setColProp(data3[j].field, {

    editoptions: {

    dataInit: function (el) {

    if (data3[j]!== undefined && data3[j].isBulkEditable == 0) {

    $(el).datepicker("destroy");

    }

    }

    }

    });

    }

    }

    }

    }

    });

    },

    left: "100",

    closeAfterAdd: true,

    closeAfterEdit: true,

    afterclickPgButtons: function (whichbutton, formid, rowid) {

    },

    modal: true,

    editData: { "__RequestVerificationToken": function () { return '@GetAntiXsrfRequestToken()' } },

    onclickSubmit: function (params) {

    if (confirm('Are you sure you want to update the selected record(s)?')) {

    var ajaxData = {};

    var list = $("#jqgITAsset");

    var selectedRow = list.getGridParam("selrow");

    rowData = list.getRowData(selectedRow);

    var list = $("#jqgITAsset");

    var ids = list.jqGrid('getGridParam', 'selarrrow');

    var count = ids.length;

     

    if (count > 1) {

    var idjoin = "";

    var ajaxData = { intnewID:ids.join(","), intId: rowData.RequisitionId, confirmstatus:'true'};

    return ajaxData;

    } else {

    ajaxData = { intnewID:0, intId: rowData.RequisitionId, confirmstatus: 'true' };

    return ajaxData;

    }

    } else {

    jQuery("#jqgITAsset").getGridParam("selrow") == null;

    ajaxData = { intnewID:0, confirmstatus: 'false' };

    return ajaxData;

    }

    },

    afterSubmit: function (response, postdata) {

    if (response.status == 200) {

    jQuery("#jqgITAsset").setGridParam({ search: true, postData: { "nit": postdata.RequisitionId } }).trigger('reloadGrid');

    return [true, ''];

    } else {

    return [false, 'error message'];

    }

    },

    resize: false,

    width: "1300",

    left: "80",

    };

    I already placed recreateForm: true, but unfortunately for the 1st pop up edit dialog doesn't reflect the rules placed under beforeInitData, beforeshowform, aftershowform

    Please advise.

    Thanks.

    Regards,

    Micheale

    Tuesday, June 16, 2020 12:59 PM

Answers

  • User-893002196 posted

    Hi All,

    Issue resolved. I move the portion code to section onSelectRow then issue resolved.

    onSelectRow: function (rowid) {
                        var list = $("#jqgITAsset");
                        var ids = list.jqGrid('getGridParam', 'selarrrow');
                        var count = ids.length;
                        var id = "";
                        for (var i = 0; i < count; i++) {
                            id = id+","+ids[i];
                        }
                        
                        //debugger;
                        $.post('@Url.Content("~/Home/GetBulkEditFieldProperty")',
                            { "varId": id.substring(1, id.length), "__RequestVerificationToken": '@GetAntiXsrfRequestToken()' },
                            function (data3) {
                                for (var j = 0; j < data3.length; j++) {
                                    if (j != data3.length) {
                                        if (data3[j].field.toLowerCase().indexOf("date") > -1) {
                                            $('#jqgITAsset').setColProp(data3[j].field, {
                                                editoptions: {
                                                    style: data3[j].isBulkEditable == 0 ? "FormElement ui-widget-content ui-corner-all" : "FormElement ui-widget-content-readonly ui-corner-all",
                                                    "readonly": data3[j].isBulkEditable == 0 ? false : "readonly",
                                                    dataInit: function (el) {
                                                        if (data3[j] !== undefined && data3[j].isBulkEditable == 0) {
                                                            $(el).datepicker("destroy");
                                                        }
                                                    }
                                                }
                                            });
                                        }                                    
                                    }
                                }
                            });
                    },

    Thanks.

    Regards,

    Micheale

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 17, 2020 2:09 AM