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

How to use Grid with complex object and post Grid data with other model's fields?

6 Answers 574 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Damon
Top achievements
Rank 1
Damon asked on 22 Jul 2015, 05:53 AM
I made a demo project with two entity types: TestModel1 and TestModel2. TestModel1 has a collection property called TestModel2s, which is ICollection<TestModel2>.
Then I use TestModel1 as MVC model type, and I want to bind TestModel2s to a Grid, while editing TestModel1's properties with the grid in the same form. I tried several times to post to the server, the TestModel2s properties was always null.

Is there any simple way to go through this small problem? I think this complex object is not complex at all. Please refer to the home index.cshtml page, that is a simple demo. Attachments are size limited, so the attached demo project hasn't include the kendo's files.
My further requirement is to edit a ICollection<T> property in a column, how can I bind the ICollection<TestModel1> to a Grid and edit ICollection<TestModel2> (field m=>m.TestModel2s) ?

Anxious waiting it.

6 Answers, 1 is accepted

Sort by
0
Accepted
Boyan Dimitrov
Telerik team
answered on 23 Jul 2015, 02:38 PM

Hello Damon,

 

I believe that our Submit form containing grid along with other input elements code library is what you are looking for. This code library shows an approach how to submit a form which contains a Grid and other input elements to the server. 

 

Regards,
Boyan Dimitrov
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
0
Damon
Top achievements
Rank 1
answered on 23 Jul 2015, 06:44 PM

Hi Boyan,

I tried Submit form containing grid along with other input elements code, but when I clicked "Add" button, the Firefox browser warned me that "ReferenceError: index is not defined", the same as Opera with Webkit engine.

What's wrong with this column bound?

columns.Bound(m => m.Name)
                .ClientTemplate("#= Name #" +
                    "<input type='hidden' name='Products[#=index(data)#].Name' value='#= Name #' />"
                  );

0
Damon
Top achievements
Rank 1
answered on 23 Jul 2015, 07:22 PM

Sorry Boyan,

I haven't seen that there was a <script/> block at the bottom of .cshtml file.

I tried to make that function more flexible like this:

<script>

    function index(dataItem) {
        var data = $("#TestModel2s").data("kendoGrid").dataSource.data();

        return data.indexOf(dataItem);
    }

    function indexOfGridRow(dataItem, collectionName) {
        var data = $("#" + collectionName).data("kendoGrid").dataSource.data();

        return data.indexOf(dataItem);
    }

</script>

 

Then I used indexOfGridRow instead of index in the Index.cshtml, it worked.

Well done, thanks.

0
Damon
Top achievements
Rank 1
answered on 24 Jul 2015, 09:08 AM

Hello Boyan,

I've replied at the forum and marked your reply as the answer, and I was trying to give a better JS approach to achieve the goal.

I'll keep watching the thread.
0
Manikanth
Top achievements
Rank 1
answered on 27 Mar 2019, 12:51 AM
Hi Boyan,how does validation works if the grid is in popup along with text fields.Because when am trying to update the popup by only changing the grid values.The update button is not triggering.There should be a complete demo on this.
0
Boyan Dimitrov
Telerik team
answered on 28 Mar 2019, 06:40 PM
Hello,

Could you please try the this link since this project should be a bit newer compared to the one in my link. The validation should work as expected since the validation itself does nothing to do with the client template. Basically when a field is updated and it passed the validation the client template (the value for the hidden input should be updated). 

Regards,
Boyan Dimitrov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Damon
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Damon
Top achievements
Rank 1
Manikanth
Top achievements
Rank 1
Share this question
or