This is a migrated thread and some comments may be shown as answers.

MVC Grid with Client Side functionality on Model Property

2 Answers 644 Views
Grid
This is a migrated thread and some comments may be shown as answers.
GCS
Top achievements
Rank 1
GCS asked on 08 Mar 2016, 06:25 PM

Hello,

 I have a model defined as 

public class Parent
{
        public List<Child> Children { get; set; }  
}

public class Child
{
    property int Id { get; set;}
    property string Name {get; set;}
    property int  Age {get; set;}
}

My goal is to have a grid on my main page whereas the model is the parent and the grid is used to populate the Children list. I do not want the grid to invoke any server method. It should just populate the  Children list. When the parent is saved, I am intending that its Children list will contain the items added within the Parent's POST operation. 

I can create the grid, but I can't seem to get it to add items. When I add the toolBar.Create() option, I get the following error; 

"The Insert data binding setting is required by the insert command. Please specify the Insert action or url in the DataBinding configuration."

But I don't want any insert action to occur on the server. I just want the grid to populate the Children list on the client. 

How can I do this? 


 

2 Answers, 1 is accepted

Sort by
0
GCS
Top achievements
Rank 1
answered on 08 Mar 2016, 06:28 PM

Forgot to post my grid, it looks something like: 

 

                    @(Html.Kendo().Grid(Model.Children)
                        .Name("ChildrenGrid")
                        .Columns(columns =>
                        {
                            columns.Bound(l => l.Name);
                            columns.Bound(l => l.Age); 
                        })
                        .ToolBar(toolBar =>
                        {
                            toolBar.Create();
                        })
                        .Sortable()
                        .Scrollable()
                        .DataSource(dataSource => dataSource
                            .Ajax()
                            .Batch(true)
                            .ServerOperation(false)
                            .Events(events => events.Error("error_handler"))
                             .Model(model =>
                             {
                                 model.Id(l => l.Id);
                                 model.Field(l => l.Id).Editable(false);
                             })
                         )
                    )

0
Nikolay Rusev
Telerik team
answered on 10 Mar 2016, 10:07 AM

Hello Dave,

 

You could handle detailInit event and initialize, client-side with JavaScript, the detail template widget. In the context of the event you have reference to the parent row data item from which you can get the children collection.

 

Regards,
Nikolay Rusev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
GCS
Top achievements
Rank 1
Answers by
GCS
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or