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: 120, editable: true, edittype: "select", editoptions: { dataUrl: "/Person/GetSelectData" }, editrules: { required: false} },
{ name: "Delegate", index: "Delegate", width: 120, editable: true, edittype: "select", editoptions: { dataUrl: "/Person/GetSelectData" }, editrules: { required: false} },
I wanted to see if there is a way to have tihs work above without two seperate ajax calls to the same action just to get the same list of data:
dataUrl: "/Person/GetSelectData"
so I can call it once and have the list of items linked to both columns? Is that possible in jqGrid?
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 ofvalue
instead ofdataUrl
. 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 inurl
can returns additional data. You can use the returned data inside ofvalue
defined as a function or you can set thevalue
inside ofbeforeProcessing
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 useuserdata
(or any other extensions of the input data):Then one could use
By the way one can even use
formatter: "select"
for "Manager" and "Delegate" columns. It allows to use ids instead of names. For exampleOne should add
formatter: "select"
toselectOptions
too. It allows to use ids3
,1
and2
inside of the main data (rows
part of JSON data). The standard way with the usage ofdataUrl
don't allow to useformatter: "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.