Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI with ASP.NET MVC3 default values when adding row to grid

I am converting an existing app from Telerik MVC extensions to the newer KendoUI product. I am using the grid control. How do I specify the default values for the columns when adding a new row to the grid?

With the old Telerik MVC extensions, I did the following:

.Editable(editing=>editing.Mode(GridEditMode.InCell).DefaultDataItem(Model.defaultItem))

The defaultItem of my model was my default for added rows. So how do I do this with Kendo?

like image 226
carlg Avatar asked Sep 13 '12 12:09

carlg


People also ask

How to work on Kendo UI grid with MVC?

This article will show, how to work on Kendo UI Grid with ASP.NET MVC. Create a new ASP.NET MVC project . Download Kendo UI for ASP.NET MVC here. Install the TelerikUI for ASP.NET MVC Setup 2016, as shown in the figures, given below: The installation is straight forward. Just choose the required products.

What's new to Kendo UI for jQuery?

New to Kendo UI for jQuery ? Download free 30-day trial The Grid enables you to handle the appearance of its rows by using the id of the data item, adding custom rows, utilizing row templates, and disabling the hover effect. Make sure the ID field is defined in the model configuration of the data source of the Grid.

How to get the default value of a Kendo UI dropdownlist?

The Kendo UI Model field default value can be set to a JavaScript function. In this function, you may obtain the Kendo UI DropDownList instance and its value () and return it. Let me know if you need more help.

What is row hovering in Kendo UI?

For more information, refer to the article on row templates. As of the Kendo UI Q1 2016 release, all Kendo UI themes feature styles for row hovering. Hover is a UI state which provides better visualization across long table rows and when the Grid is in editing mode.


1 Answers

Yo yo yo mate,

You need to specify default value for each of the fields via the dataSource model configuration

Here is an example you can use ;)

@(Html.Kendo()
.Grid<TestModel>()
.Name("SomeOtherGridName")
.DataSource(ds => ds.Ajax().Read("test", "test").Model(
    x => {
        x.Field(c => c.Val1).DefaultValue(5);
        x.Field(c => c.Val2).DefaultValue("cool!");
    }
 ))
.Columns(columns =>
{
    columns.Bound(c => c.Val1);
    columns.Bound(c => c.Val2);
})
)
like image 50
Petur Subev Avatar answered Oct 11 '22 21:10

Petur Subev