complex field with kendoGrid

3 posts, 1 answers
  1. nessrine
    nessrine avatar
    2 posts
    Member since:
    Nov 2010

    Posted 28 Nov 2012 Link to this post

    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. Answer
    Daniel
    Admin
    Daniel avatar
    2224 posts

    Posted 30 Nov 2012 Link to this post

    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!
  3. nessrine
    nessrine avatar
    2 posts
    Member since:
    Nov 2010

    Posted 19 Dec 2012 Link to this post

    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");
                              
Back to Top