Want to run the rules in editoptions of ColModel when a field changes on form edit

亡梦爱人 提交于 2019-12-11 17:41:42

问题


I have a free JqGrid setup in such a way such that onclick of the row, editgridrow is called and the form loads. Now when the user changes the value of a certain field on the form, I want to be able to show/hide other fields depending upon what was defined in the editable parameter of the colModel.

I have defined the dataEvents in the cmTemplate part of the grid, so that any change any where on the form will trigger the event. I have also gotten to the colModel. What I am unsure of is how to apply the rule inside of the ColModel to that particular row being edited.

        cmTemplate: { 
                      align: "center", 
                      autoResizable: true,
                      editrules: {edithidden: true},
                      editoptions:{
                            dataEvents: [
                                         {
                                             type: 'change',
                                             fn: function(e) {
                                                var form = $(e.target).closest('form.FormGrid');
                                                handleEvent(e.target.id,e.target.value,form[0],$(newTable).jqGrid())

                                             }
                                         }
                             ]

                     }
                },



        function handleEvent(eventSource,eventSourceValue,form,grid)
        {

             var targets = eventSources[eventSource];
             if(targets != null)
             {
                var colModel = grid.getGridParam("colModel");

                for(var i=0; i<targets.length;i++)
                {
                    for(var z=0; z<colModel.length;z++)
                    {   
                        if(colModel[z]["name"] == targets[i])
                        {

                            if(colModel[z]["edittype"] == "select")
                            {
                                var dropdownName = "drp"+targets[i].replace("-","_");

                                var newOptions = buildOptions(eval(dropdownName),eventSourceValue);

                                $("select#"+targets[i]+".FormElement", form).html(newOptions)
                            }
                            break;
                        }
                    }
                }   
            }





        }

I have already handled other dropdown changes in the handle event BUT I also need to be able to handle all other changes to the form , for example showing fields etc but I do not want to write duplicate code again and want to access the editOptions of the colModel and trigger the change to the form


回答1:


First option is to use the event beforeInitData (the event is defined within editGridRow - see docs) here you can change the type and your columns will show and hide in the form depending on your conditions

Second option in your case is to define custom button in navigator and call editGridRow to edit a row and before edit the row you can change the status of the variables as you want. See how to use custom button add here

I should note that the above recommendations are based on supported product Guriddo jqGrid , since you use not supported free-jqGrid you should take this in care when try these.



来源:https://stackoverflow.com/questions/56971942/want-to-run-the-rules-in-editoptions-of-colmodel-when-a-field-changes-on-form-ed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!