Hello,
I hope this is a simple question, can someone show me how to define default values for an MVC igGrid. Here's a snippet of my code:
.Features(feature => { feature.Updating().ColumnSettings(cs => { cs.ColumnSetting().ColumnKey("ActvtyKey").ReadOnly(true); cs.ColumnSetting().ColumnKey("ActvtyNm").Required(true).TextEditorOptions(o => o.ValidatorOptions(vo => vo.MinLength(2).KeepFocus(ValidatorKeepFocus.Never))); cs.ColumnSetting().ColumnKey("TrackngMetrcTxt").EditorType(ColumnEditorType.Text).Required(false); cs.ColumnSetting().ColumnKey("OngngStatsFlg").EditorType(ColumnEditorType.Combo).Required(false).ComboEditorOptions(co => co.DataSource(ViewBag.StatusText).ValueKey("FlagKey").TextKey("Status").Mode(ComboMode.DropDown)); }) .HorizontalMoveOnEnter(true) .ExcelNavigationMode(true) .EditMode(GridEditMode.Row); })
Can you please show how to set a default value for the text and combo editor please. Thank you.
Hello.
Thank you for contacting us.
About your question by saying default value you mean when the Grid initialize the editor to be already bind and to show values, right? You will need to set Value option in order to show some value by default like it is shown in the online sample below or to have a dataSource which the editor will use and when the value exists in the dataSource it will be automatically selected:
Code snippet:
{ columnKey: "Country", editorType: "combo", editorOptions: { dataSource: countries }},
...
http://igniteui.com/grid/editing-api-events
Let me know if I may be of further assistance.
No, that's not correct and not what I'm asking for. I have an MVC Grid with a comboeditor that is databound to a table lookup (this is very similar to the Basic Editor example):
cs.ColumnSetting().ColumnKey("OngngStatsFlg").EditorType(ColumnEditorType.Combo).Required(false).ComboEditorOptions(co => co.DataSource(ViewBag.StatusText).ValueKey("FlagKey").TextKey("Status").Mode(ComboMode.DropDown));
What I need is when the user clicks Add New Row, a default value is set. Being that this is bound to a lookup, the new row sets the comboeditor to null and if the user saves that row (this must be an optional field), the record breaks because there is no lookup for a null value.
So what I need is to set the default value for when the user adds a new row. I need an example for an MVC wrapper, not javascript as you pointed out above, for both a text box and combo editor. Thank you.
I hope that now I am understanding your requirements correctly. You want to set default text to text and combo editor and this is achievable by using the option DefaultValue. Below you can find a working sample which is showing exactly this behavior. I hope that you will find it helpful. As you can see from the sample I have text and combo editors and when I try to add new row default values appears for both of them. If you want you can use Validator options as it is shown in the sample. Of course when DefaultValue is set there is no need to use RequiredValidaror.
@(Html.Infragistics().Grid(Model.Customers.AsQueryable()) .ID("grid") .Width("400px") .PrimaryKey("ID") .Features(feature => { feature.Selection() .Mode(SelectionMode.Row) .MultipleSelection(true); feature.RowSelectors() .EnableCheckBoxes(true) .EnableRowNumbering(true); feature.Updating().ColumnSettings(cs => { cs.ColumnSetting().ColumnKey("ID").ReadOnly(true); cs.ColumnSetting().ColumnKey("Name").Required(true) .DefaultValue("Some Name") .TextEditorOptions(o => o .ValidatorOptions(vo => vo .MinLength(2) .KeepFocus(ValidatorKeepFocus.Never))); cs.ColumnSetting().ColumnKey("IsActive") .DefaultValue("false") .EditorType(ColumnEditorType.Combo) .Required(true) .ComboEditorOptions(co => co .DataSource(new[] { new { IsActive = true }, new { IsActive = false } }) .ValueKey("IsActive") .TextKey("IsActive") .Mode(ComboMode.DropDown) .EnableClearButton(true)); }); }) .DataBind() .Render() )
Thank you for this and for the example project. I have seen in other forum discussions the DefaultValue property in the MVC wrapper but my Infragistics.Web.MVC component must be an older version as it did not have it. Looking at your sample project, it appears to have a newer version which fixed the issue. Thank you, I'm able to set the default value now.
I am glad that everything is okay now.