I am using the open source jqGrid plugin with EF4 and ASP.NET web forms. I need to set an input element in a row string of an editable grid based on the value of a column from the database. For example, the first line may contain DDL, the second line may contain a flag, etc.
I am trying to achieve this using custom_element
and custom_values
, for example:
$("#grid1").jqGrid({ url: 'Default.aspx/getGridData', datatype: 'json', ... colModel: [ ... //contains the input type ('select', etc.) { name: 'InputType', hidden:true }, ... //may contain a string of select options ('<option>Option1</option>'...) { name: 'Input', editable:true, edittype:'custom', editoptions:{ custom_element: /* want cell value from InputType column here */ , custom_value: /* want cell value from Input column here */ } }, ... ] });
jqGrid docs say that I can call custom functions to set custom_element
and custom_values
, but I don't see how I can capture the values โโof columns and pass them to my custom functions.
To set custom_values
I noticed a nice Oleg solution using the list:
parameter, but it seems that an additional Ajax call was involved. I want to avoid this, since I already have all the data that I need from the initial Ajax call for the grid.
In general, I need to do the following in inline editing mode:
- dynamically assign an input type from a DB value
- dynamically assign input values โโ(for DDL or checkboxes) from a DB string
I am also open to skipping using custom_element
and custom_values
, but then I still encounter the same problem of dynamically setting edittype
and editoptions:{value:}
parameters.
Any ideas on how to do this? Is there any other approach I should take?
UPDATE : Thank you for your efforts to help me. Upon request, here is a shortened example of my JSON response:
{"d":[ {"Input":null,"InputType":"select"}, {"Input":"From downtown, proceed west on Interstate 70.", "InputType":"text"} ]}
With this data, I want to show an empty selection in one line and a filled text field in the next line. Both will be editable.
SOLUTION I returned to this problem to find a solution that does not involve the use of custom_element
and custom_values
. Here is my solution (based on the accepted answer below) on changing edittype
and editoptions
:
loadComplete: function () { var rowIds = $("#grid1").jqGrid('getDataIDs'); $.each(rowIds, function (i, row) { var rowData = $("#grid1").getRowData(row); if (rowData.InputType == 'select') { $("#grid1").jqGrid('restoreRow', row); var cm = $("#grid1").jqGrid('getColProp', 'Input'); cm.edittype = 'select'; cm.editoptions = { value: "1:A; 2:B; 3:C" }; $("#grid1").jqGrid('editRow', row); cm.edittype = 'text'; cm.editoptions = null; } }); }
Nota Bene : One important thing for me was to return editoptions
back to null
after calling editrow
. In addition, as Oleg noted in the comments, avoiding the use of custom elements allows me to enter the inputs of the date picker without any problems. This was important for my application, so I eventually agreed with Oleg's answer, but I still supported Walter's answer. If this is a bad form, I sincerely apologize. I just wanted to reward the solution that worked best for me.