Suppose I have an enum that I'd like to use in a Grid, using the _underlying value_ as the cell value:
public enum Currency : int {
USD = 0,
GBP = 1
}
The editor is thus something similar to:
@(Html.Kendo().DropDownListFor(m => m)
.BindTo(Enum.GetValues(typeof(Currency)).Cast<Currency>().Select(v => {
return new DropDownListItem()
{
Text = v.DisplayName(),
Value = ((int)v).ToString(),
Selected = v == Model,
};
}).ToList()))
If I don't include an entry in the data source model for the field, the field defaults as expected to 0.
However, if I include the following entry in the data source model, Kendo attempts to default the value to "usd":
model.Field(d => d.Currency).DefaultValue((int) Currency.USD);
This isn't a problem for this case, as I can just leave off the model configuration. However, it becomes a problem if I change the type of the column to Nullable<Currency> because there is no way to default the value to 0. Not configuring the model attempts to use null (which causes Kendo grid to throw an exception), and attempting to configure the model uses "usd", which is invalid.
I have attempted manually setting the schema using JS:
$(document).ready(function () {
$("#MyGrid").data("kendoGrid").dataSource.options.schema.model.fields.Currency.defaultValue = 0;
}
However when I add a new column, the grid still attempts to use "usd" as the default value.
Please advise how to set the default value to 0 for a column type of Nullable<Currency>.
public enum Currency : int {
USD = 0,
GBP = 1
}
The editor is thus something similar to:
@(Html.Kendo().DropDownListFor(m => m)
.BindTo(Enum.GetValues(typeof(Currency)).Cast<Currency>().Select(v => {
return new DropDownListItem()
{
Text = v.DisplayName(),
Value = ((int)v).ToString(),
Selected = v == Model,
};
}).ToList()))
If I don't include an entry in the data source model for the field, the field defaults as expected to 0.
However, if I include the following entry in the data source model, Kendo attempts to default the value to "usd":
model.Field(d => d.Currency).DefaultValue((int) Currency.USD);
This isn't a problem for this case, as I can just leave off the model configuration. However, it becomes a problem if I change the type of the column to Nullable<Currency> because there is no way to default the value to 0. Not configuring the model attempts to use null (which causes Kendo grid to throw an exception), and attempting to configure the model uses "usd", which is invalid.
I have attempted manually setting the schema using JS:
$(document).ready(function () {
$("#MyGrid").data("kendoGrid").dataSource.options.schema.model.fields.Currency.defaultValue = 0;
}
However when I add a new column, the grid still attempts to use "usd" as the default value.
Please advise how to set the default value to 0 for a column type of Nullable<Currency>.