I am using jqgrid in asp.net MVC5 with Entity Framework. For one of the columns I require it to be populated via database as a dropdown.
$("#grid").jqGrid({
colNames: ['Id', 'Date', 'PersonelID', 'OnCallType', 'Comments'],
colModel: [
{ key: true, hidden: true, name: 'Id', index: 'Id', editable: true },
{ key: false, name: 'Date', index: 'Date', editable: true, formatter: 'date', formatoptions: { newformat: 'm/d/Y' }, sortable: true },
{ key: false, name: 'PersonelID', index: 'PersonelID', editable: true, edittype: 'select', editoptions: { dataUrl: '/Que/GetPersonnel' } },
{ key: false, name: 'OnCallType', index: 'OnCallType', editable: true, edittype: 'select', editoptions: { dataUrl: '/Que/GetCallType' } },
{ key: false, name: 'Comments', index: 'Comments', editable: true }, ]
});
what should i use in EditOptions to fetch value from database.
I tried using dataurl, but I couldnt get the code to work:-
public string GetPersonnel()
{
string final=string.Empty;
var query= new SelectList(db.PersonnelLocals.Where(o => o.QueLoc == true), "Index", "Text");
foreach (var item in query)
{
string newItem=item.Value.ToString()+":"+item.Text.ToString();
final = final + newItem + ",";
}
return final;
}
If there is any better method than using dataurl. Any help is greatly appreciated.