I am using 2013 vol 1, with MVC4 and Visual Studio 2012.
I've had a look at the sample posted here http://ko.infragistics.com/products/jquery/sample/grid/editing-combo-editor on how to add a combo to a grid.
I'd prefer to be able to populate the combo from a datasource in my repository without having a whole bunch of jQuery on the page to do so.
What is the easiest way to set the datasource of each combo in my grid to the data returned by a method in my data repository?
My repository looks something like this...
public static class VisaTypeRepository
{
public static List<EditableVisaType> GetAllRecords()
{ var db = new WorkawayDb(); var visaTypes = (from v in db.visatypes where v.deleted == false select new EditableVisaType { id = v.id, name = v.name, fromdate = v.fromdate, todate = v.todate, qualification = v.qualification, deleted = v.deleted }).ToList(); return visaTypes; }
Thanks
Hello Greg,
You can bind the combo server-side by configuring combo editor type in the Updating column settings and use one of the View Model/ViewData/ViewBag properties to pass the data to the combo.
Here is an example code:
.Features(feature =>{ feature.Updating().ColumnSettings(cs => cs.ColumnSetting() .ColumnKey("Name") .EditorType(ColumnEditorType.Combo) .ComboEditorOptions(a=> a.ValueKey("ID").TextKey("FirstName").DataSource(Model)));})
Hope this helps,
Martin Pavlov
Infragistics, Inc.
Hi Martin, thank you for the quick response.
I have tried to do what you instructed, yet I am not sure how to instruct the grid to do as I want.My VisaType class has a reference to a 'Qualification' complex type. So what I'm trying to do when showing the list of VisaTypes in the grid, is allow a dropdown for the Qualification to be edited.The Qualification class has an id and a name column.Here is the gird in my view...
@(Html.Infragistics().Grid(Model.AsQueryable()).ID("grid1").PrimaryKey("id") .Columns(column => { column.For(x => x.id).HeaderText("ID").Width("100px").Hidden(true); column.For(x => x.name).HeaderText("Name").Width("250px"); column.For(x => x.qualification).HeaderText("Qualification").Width("250px"); }) .AutoGenerateColumns(false) .Features(features => { features.Updating().EditMode(GridEditMode.Row).EnableAddRow(true).StartEditTriggers(GridStartEditTriggers.DblClick) .ColumnSettings(settings => { settings.ColumnSetting().ColumnKey("fromdate").EditorType(ColumnEditorType.DatePicker); settings.ColumnSetting().ColumnKey("qualification").EditorType(ColumnEditorType.Combo).ComboEditorOptions(a => a.ValueKey("id").TextKey("name").DataSource(ViewData["qualifications"])); }); }) .DataSourceUrl(Url.Action("GetData")) .UpdateUrl(Url.Action("EditingSaveChanges")) .DataBind() .Render())
-----------------
In my controller I have set ViewData["qualifications"] like so...
public ActionResult Index() { ViewData["qualifications"] = Qualification.GetQualifications().AsQueryable(); var ds = VisaTypeRepository.GetAllRecords(); return View(ds); }
[GridDataSourceAction] public ActionResult GetData() { ViewData["qualifications"] = Qualification.GetQualifications().AsQueryable(); var ds = VisaTypeRepository.GetAllRecords().AsQueryable(); return View("Index", ds); }--------------Yet no matter what I try, the combo box does not populate.Thanks