is there anyway to have multiple columns in jqgrid, read the same source data for dropdowns?

前端 未结 1 1068
再見小時候
再見小時候 2020-12-12 08:20

I have a case where i have multiple columns in jqGrid that source the same list to populate the dropdown.

   { name: \"Manager\", index: \"Manager\", width:          


        
相关标签:
1条回答
  • 2020-12-12 09:04

    Any implementation of what you want will mean some kind of caching of the data for "/Person/GetSelectData". One way which I would prefer myself is the usage of value instead of dataUrl. The list of select values can be included in the main response to the server which fill the grid. In the case the action used in url can returns additional data. You can use the returned data inside of value defined as a function or you can set the value inside of beforeProcessing alternatively. To make my suggestion more clear I explain it on an example.

    The first way: usage value as function. One can include the data which you returns typically in "/Person/GetSelectData" inside of main JSON response. For example you can use userdata (or any other extensions of the input data):

    {
        "rows": [
            ...
        ],
        "userdata": {
            "Persons": "Bill:Bill;Oleg:Oleg;Leora:Leora"
        }
    }
    

    Then one could use

    beforeProcessing: function (data) {
        var $self = $(this), userData = data.userdata, persons, selectOptions;
        if (userData && userData.Persons) {
            persons = userData.Persons;
            selectOptions = {
                searchoptions: { value: ":All;" + persons }, // for toolbar search
                stype: "select",
                editoptions: { value: persons },
                edittype: "select"
            };
            $self.jqGrid("setColProp", "Manager", selectOptions);
            $self.jqGrid("setColProp", "Delegate", selectOptions);
        }
    }
    

    By the way one can even use formatter: "select" for "Manager" and "Delegate" columns. It allows to use ids instead of names. For example

    "Persons": "3:Bill;1:Oleg;2:Leora"
    

    One should add formatter: "select" to selectOptions too. It allows to use ids 3, 1 and 2 inside of the main data (rows part of JSON data). The standard way with the usage of dataUrl don't allow to use formatter: "select".

    I recommend you to read the answer, this one and this one for more information about usage beforeProcessing for dynamic modification of the grid.

    0 讨论(0)
提交回复
热议问题