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

Grid Column.Bound(array[])

7 Answers 1864 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gusev
Top achievements
Rank 1
Gusev asked on 04 Apr 2013, 05:26 AM
Hello!!!
I have a question!
I use this example:http://www.kendoui.com/code-library/mvc/grid/binding-to-datatable.aspx
Please show on this example how to edit object (row)

and next:
I have Model:
public class ShrinkCoeffModel
    {
        [Display(Name = "thickness")]
        public virtual int Thickness { get; set; }
          
        [Display(Name = "wett")]
        public virtual string[] Wetness { get; set; }
  
        [Display(Name = "coeff")]
        public virtual decimal[] Coeff { get; set; }
    }
and Grid:
@(
 Html.Kendo().Grid(Model)
                .Name("ShrinkCoeff")
                .ToolBar(commands =>
                {
                    commands.Create();
                })
                .Columns(columns =>
                {
                    columns.Bound(o => o.Thickness);
                    for (int i = 0; i < Model.FirstOrDefault().Wetness.Count(); i++)
                    {
                    columns.Bound(o => o.Wetness[i]);
                          
                    }
                    columns.Command(command =>
                    {
                        command.Edit();
                        command.Destroy();
                    }).Width(210).Title("Действия");
                })
                .Editable(editable => editable.TemplateName("Item").Mode(GridEditMode.PopUp))
                .DataSource(dataBinding => dataBinding
                    .Server()
                                                    .Model(model => model.Id(o => o.Thickness))
                                                        .Update("Edit", "ShrinkCoeff")
                                                        .Create("Create", "ShrinkCoeff")
                                                        .Destroy("Delete", "ShrinkCoeff"))
                .Pageable()
                .Sortable()
                .Selectable()
)
Why Grid dosn't want work with array(
How I can this do?
for (int i = 0; i < Model.FirstOrDefault().Wetness.Count(); i++)
                    {
                    columns.Bound(o => o.Wetness[i]);
                           
                    }

7 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 05 Apr 2013, 12:36 PM
Hi Gusev,

 
Basically the grid columns can be bound only to the object properties - in current case it seems that you are trying to bind the column to the values of given property which is invalid configuration. Please check the example below of rendering the given property values in current column using ClientTemplate:

e.g.:

columns.Bound(p => p.Wetness).ClientTemplate("#=generateTemplate(Wetness)#");

function generateTemplate(Wetness) {
    var template = "<ul>";
    for (var i = 0; i < Wetness.length; i++) {
        template = template + "<li>" + Wetness[i] + "</li>";
    }
 
    return template + "</ul>";
}
Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gusev
Top achievements
Rank 1
answered on 05 Apr 2013, 12:57 PM
I made as written, but nothing to changed

columns.Bound(p => p.Wetness).ClientTemplate("#=generateTemplate(Wetness)#");
 
<script type="text/javascript">
    function generateTemplate(Wetness) {
        var template = "<ul>";
        for (var i = 0; i < Wetness.length; i++) {
            template = template + "<li>" + Wetness[i] + "</li>";
        }
        return template + "</ul>";
    }
</script>
0
Vladimir Iliev
Telerik team
answered on 08 Apr 2013, 05:26 AM
Hi Gusev,

Could you please provide runable project where the issue is reproduced? This would help us pinpoint the exact reason for this behavior.

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gusev
Top achievements
Rank 1
answered on 08 Apr 2013, 08:03 AM
Hello!
I corrected the error! ( .Server was instead.Ajax )
And now I want know, how I can edit any object?
I need EditorTemplates? (Need I use Mode.PopUp with template?) 
And If I click UpdateButton in CustomPopUp Window, will come my Wetness to Controller (method Edit)? or only Thickness will come to Controller and Wetness will be equal to null
0
Vladimir Iliev
Telerik team
answered on 09 Apr 2013, 02:08 PM
Hi Gusev,

 
I would suggest to check the "Using Multiselect in Grid" demo in the CodeLibrary which demonstrates how to use the MultiSelect widget as EditorTemplate in a InLine editable Grid. 
The Grid is bound to the Employees collection of the Northwind database and the ComboBox allows you to edit the Territories navigation property generated by the Entity Framework ORM.

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gusev
Top achievements
Rank 1
answered on 10 Apr 2013, 09:11 AM
this is very good idea!!!
thanks!

but I have a small problem )
I have this: first.png
And editMode: second.png

I want :

first Wetness     first Coeff
second Wetness   second Coeff 
.....                            ......

how to display  also to and edit
how I can this do?

sorry for bad my english
0
Vladimir Iliev
Telerik team
answered on 10 Apr 2013, 11:42 AM
Hi Gusev,


As this thread is out of the original topic of this support conversation may I kindly ask you to open a new support thread for it (please attach current grid code and the editor template)? In this way you can be sure that your query will reach the corresponding staff member in time and will be answered faster and accurately.


Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Gusev
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Gusev
Top achievements
Rank 1
Share this question
or