5 Answers, 1 is accepted
0

carlg
Top achievements
Rank 1
answered on 13 Sep 2012, 02:47 PM
If anyone is following this thread. It is my understanding that Telerik did not build this functionality into Kendo.
Not sure why they would take away functionality, but it seems as if they did.
Not sure why they would take away functionality, but it seems as if they did.
0
Hello carlg,
Rosen
the Telerik team
Although, the DefaultDataItem has been removed the default values can be set through DataSource Model definition. Please refer to this help article for more details.
Regards,Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Arun
Top achievements
Rank 1
answered on 26 Sep 2012, 04:53 PM
"this help article" link does not work. could you show steps to set default value?
0

carlg
Top achievements
Rank 1
answered on 26 Sep 2012, 05:22 PM
Arun,
Just set your default values like this:
Just set your default values like this:
.DataSource(dataSource => dataSource.Ajax()
.Batch(true)
.ServerOperation(false)
.Model(model =>
{
model.Id(p => p.Id);
model.Field(c => c.name).DefaultValue(Model.defaultObject.Name);
})
0

Dimitrij
Top achievements
Rank 1
answered on 09 Jun 2015, 06:00 AM
It's a bummer that there's no adequate replacement for DefaultDataItem(), since I don't want to set the DefaultValue() for every field manually.
For everybody who's interested, I wrote an extension method that accomplishes the core functionality of DefaultDataItem(). It reads every property of a default item and sets the Field() and DefaultValue() in the data source model definition:
/// <summary>
/// Extensions of the DataSourceModelDescriptorFactory class.
/// </summary>
public
static
class
DataSourceModelDescriptorFactoryExtensions
{
/// <summary>
/// Sets a default data item.
/// </summary>
/// <typeparam name="TModel">The model entity type.</typeparam>
/// <param name="dataSourceModelBuilder">The data source model builder.</param>
/// <param name="defaultDataItem">The default data item that should be used.</param>
/// <returns>The extended data source model builder.</returns>
public
static
DataSourceModelDescriptorFactory<TModel> DefaultDataItem<TModel>(
this
DataSourceModelDescriptorFactory<TModel> dataSourceModelBuilder,
TModel defaultDataItem) where TModel :
class
{
// for every property of the entity => set the corresponding field default value
var propertyInfos =
typeof
(TModel).GetProperties();
foreach
(var propertyInfo
in
propertyInfos)
{
dataSourceModelBuilder.Field(propertyInfo.Name, propertyInfo.PropertyType).DefaultValue(propertyInfo.GetValue(defaultDataItem));
}
return
dataSourceModelBuilder;
}
}
Use it like this:
@(Html.Kendo().Grid<MyEntity>()
...
.DataSource(ds => ds
...
.Model(model =>
{
model.Id(n => n.Id);
model.DefaultDataItem(myDefaultEntity);
}
)
)
HIH,
Dimitrij