I am using 2013 vol 1, with MVC4 and Visual Studio 2012.
I've had a look at the sample posted here http://es.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
I'm not sure what is the problem in your code. That's why I'm attaching my sample for you to see.
Also the igCombo editor provider doesn't work well with complex property so you'll have to use unbound column and process the data on the server accordingly.
Martin PavlovInfragistics, Inc.
Hi Martin,
I have tried to integrate your code into my page, but I get the following error...
I have uploaded my basic sample grid project, perhaps you can spot where I am going wrong? I don't see anything wrong in the code as such.You can download it here... http://meltdown.co.za/combo/InfragisticsMvcApp1.zipThank you very muchGreg
Hi Greg,
The error appeared because you have 2 elements in the Updating column settings array. In my sample I was referencing the 0 index, while in your sample you should reference the 1st index.
Also the igCombo didn't want to drop-down, because you were referencing only the js file, so the css file was missing thus some styles were not available.
You can include the igCombo by list it in the Loader.Resources("igCombo") method.
I'm attaching the corrected Index.cshtml.
Best regards,Martin PavlovInfragistics, Inc.
Thank you for the excellent support, this has made my life so much easier.