This example demonstrates how to create a column editor, bind it to a data source, and configure editor callback requirements.
Use the MVCxGridViewColumn.EditorProperties method to define an editor at a column level.
settings.Columns.Add(columnCountry => {
columnCountry.Caption = "CountryID";
columnCountry.FieldName = "CountryID";
columnCountry.ColumnType = MVCxGridViewColumnType.ComboBox;
columnCountry.EditorProperties().ComboBox(p => {
p.CallbackRouteValues = new { Controller = "Home", Action = "CountryComboBox" };
p.ValueField = "CountryID";
p.TextField = "CountryName";
p.ValueType = typeof(int);
p.CallbackPageSize = 20;
p.DropDownStyle = DropDownStyle.DropDown;
p.BindList(E4425.Models.DataProvider.GetCountries());
});
});
Use the MVCxColumnComboBoxProperties class to specify editor settings. Call the BindList method to bind the column to a data source.
public static MVCxColumnComboBoxProperties CreateComboBoxColumnProperties() {
MVCxColumnComboBoxProperties p = new MVCxColumnComboBoxProperties();
p.CallbackRouteValues = new { Controller = "Home", Action = "CountryComboBox" };
p.ValueField = "CountryID";
p.TextField = "CountryName";
p.ValueType = typeof(int);
p.CallbackPageSize = 20;
p.DropDownStyle = DropDownStyle.DropDown;
p.BindList(E4425.Models.DataProvider.GetCountries());
return p;
}
Call the GetComboBoxCallbackResult method to handle the editor's callback on the server.
public ActionResult CountryComboBox() {
MVCxColumnComboBoxProperties p = E4425.Helpers.CallbackComboBoxHelper.CreateComboBoxColumnProperties();
return GridViewExtension.GetComboBoxCallbackResult(p);
}