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

complex field with kendoGrid

2 Answers 287 Views
Grid
This is a migrated thread and some comments may be shown as answers.
nessrine
Top achievements
Rank 1
nessrine asked on 28 Nov 2012, 04:20 PM
Hi,

I need your help to declare kendogrid which contains a complex field:Specifically ,i have a relation 1-to-1 between table RapportView and table Delegue.I hope to put the "ID"and "Gamme" of table delegue in the same row as rows of RapportView .
My data has type as json like this:
[{ "Cycle":"2008",
"DateDebut":"\/Date(1202684400000+0100)\/",
"DateFin":"\/Date(1203202800000+0100)\/"
,
"Delegue":{"Gamme":"BU 1A","ID":13,"Matricule":"033","Nom":"S","Prenom"
:"Sa","Role":null}
},
{

"Cycle":"2008",
"DateDebut":"
\/Date(1203289200000+0100)\/",
"DateFin":"\/Date(1203807600000+0100)\/",

 "Delegue":{"Gamme":"BU 1A","ID":13,"Matricule":"033","Nom":"S","Prenom":"Sa","Role":null}
}]
i hope that my problem is clear.Thanks for yr help.

2 Answers, 1 is accepted

Sort by
1
Accepted
Daniel
Telerik team
answered on 30 Nov 2012, 03:58 PM
Hello,

Showing the complex field can be achieved either by binding the column directly to the column:

columns.Bound(o => o.Delegue.Gamme);
or by using a template:
columns.Template(o => {}).ClientTemplate("#= Delegue.Gamme#");
In both case if the object can be null you should use conditional logic in the template:
columns.Bound(o => o.Delegue.Gamme).ClientTemplate("#= data.Delegue ? Delegue.Gamme : ''#");
Note that the DataSource schema supports only a single level so in order for it to work correctly in all scenarios, you should use a flattened view model.

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
nessrine
Top achievements
Rank 1
answered on 19 Dec 2012, 05:02 PM
thank y so much for your response.it makes me inspired.
so the response is:
var grid = $("#jqxgrid").kendoGrid({
                dataSource: {
                    data: jsondata,
                    schema: {
                        model: {
                            fields: {
...}
}
}
},
 columns: [ { field: "Gamme", width: 150, title: "Gamme", template: "#= data.Delegue ? Delegue.Gamme :' ' ''#" } ,{ field: "...},{ field: " "}]
            }).data("kendoGrid");
                          
Tags
Grid
Asked by
nessrine
Top achievements
Rank 1
Answers by
Daniel
Telerik team
nessrine
Top achievements
Rank 1
Share this question
or