Want to run the rules in editoptions of ColModel w

2019-08-17 14:29发布

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

标签: free-jqgrid
1条回答
我命由我不由天
2楼-- · 2019-08-17 14:39

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.

查看更多
登录 后发表回答