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

HierarchicalDataSource to flat data into a grid

1 Answer 397 Views
Hierarchical Data Source
This is a migrated thread and some comments may be shown as answers.
aa aa
Top achievements
Rank 1
aa aa asked on 08 May 2013, 09:40 AM
i'm trying to bind a grid with hireachical data from server
i read the by  entityframework and the output on the client is the follow:
{"GetDocumentsResult":[{"AnnoEsercizio":2013,"BatchID":636614,"CustomerDocumentTypeID":401,"Data":"\/Date(1366236000000+0200)\/","FileExtension":".jpg","FollowUp":{"Fk_ID_ressol":11,"FollowUp1":"\/Date(1367877600000+0200)\/","FollowUp2":null,"FollowUp3":null,"Id":4,"Note":null},"Frequenza":"MENSILE","Id":4,"Nota":null,"ObjectID":"1","PathBuildingRuleID":9,"Piva":"xdfdff","RagioneSociale":"Kellner","RepositoryRegistrationDate":"\/Date(1358463600000+0100)\/","Stato":"OK"},{"AnnoEsercizio":2013,"BatchID":636614,"CustomerDocumentTypeID":401,"Data":"\/Date(1361142000000+0100)\/","FileExtension":".jpg","FollowUp":null,"Frequenza":"MENSILE","Id":5,"Nota":null,"ObjectID":"2","PathBuildingRuleID":9,"Piva":"xdfdff","RagioneSociale":"Kellner","RepositoryRegistrationDate":"\/Date(1366236000000+0200)\/","Stato":"OK"},{"AnnoEsercizio":2013,"BatchID":636614,"CustomerDocumentTypeID":401,"Data":"\/Date(1363561200000+0100)\/","FileExtension":".jpg","FollowUp":null,"Frequenza":"MENSILE","Id":6,"Nota":null,"ObjectID":"3","PathBuildingRuleID":9,"Piva":"xdfdff","RagioneSociale":"Kellner","RepositoryRegistrationDate":"\/Date(1366236000000+0200)\/","Stato":"OK"},{"AnnoEsercizio":2013,"BatchID":636614,"CustomerDocumentTypeID":401,"Data":"\/Date(1366236000000+0200)\/","FileExtension":".jpg","FollowUp":null,"Frequenza":"MENSILE","Id":7,"Nota":null,"ObjectID":"4","PathBuildingRuleID":9,"Piva":"xdfdff","RagioneSociale":"Kellner","RepositoryRegistrationDate":"\/Date(1366236000000+0200)\/","Stato":"DA VERIFICARE"},{"AnnoEsercizio":2013,"BatchID":636614,"CustomerDocumentTypeID":401,"Data":"\/Date(1357081200000+0100)\/","FileExtension":".jpg","FollowUp":null,"Frequenza":"TRIMESTRALE","Id":11,"Nota":null,"ObjectID":"6","PathBuildingRuleID":9,"Piva":"12345678901","RagioneSociale":"Alessio","RepositoryRegistrationDate":"\/Date(1366236000000+0200)\/","Stato":"OK"}]}



there is a child collection (named "FollowUp" and has got an only one row) in this json output
the field "FollowUp" contains several properties:   FollowUp":{"Fk_ID_ressol":11,"FollowUp1":"\/Date(1367877600000+0200)\/","FollowUp2":null,"FollowUp3":null,"Id":4,"Note":null}

in my javascript i've tried to do the following:

---hirearchicaldatasource-----
Master._resSolDataSource = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                beforeSend: function (xhr, s) {
                    s.data = JSON.stringify(Master._filter);
                },
                type: "POST",
                url: _rootUrl + 'wcf/ResponsabilitaSolidaleService.svc/getdocuments',
                contentType: "application/json; charset=utf-8",
                dataType: "json"
            }
        },
        schema: {
            data: "GetDocumentsResult",
            model: {
                id: "Id",
                fields: {
                    Id: { type: "number" },
                    Piva: { type: "string" },
                    RagioneSociale: { type: "string" },
                    Data: { type: "date" },
                    AnnoEsercizio: { type: "number" },
                    Frequenza: { type: "string" },
                    Stato: { type: "string" }
                },
                children: "FollowUp"
            }
        },
        group: { field: "RagioneSociale", dir: "asc" }
 
    });
 
------and in the grid-----
 
$("#adminGrid").kendoGrid({
        ........,
    ...other code....,
    .....,
        columns: [{
            field: "Id",
            hidden: true  
        }, {
            field: "Piva",
            title: "Partiva IVA"
        }, {
            field: "RagioneSociale",
            title: "Ragione Sociale"
        }, {
            field: "Data",
            format: "{0:dd/MM/yyyy}"
        }, {
            field: "AnnoEsercizio",
            title: "Anno esercizio"
        }, {
            field: "Frequenza"
        }, {
            field: "Stato"
        }, {
            command: [
                {
                    name: "download",
                    click: Master.download
                },
                {
                    name: "followup",
                    click: Master.followup
                }
            ],
            title: " "
        }, {
            field: "FollowUp[0].FollowUp1",       //<--FollowUp seems to be null
            title: "fu1 child"
        }]
 
    });



give exception here because the parameter "data.FollowUp.FollowUp1" doesn't exist because data.FollowUp is null

(code generated by visuatudio debugger from kendo.web.min.js)
function anonymous(data) {
var o,e=kendo.htmlEncode;with(data){o='<tr data-uid="'+(data.uid)+'" role=\'row\'><td class="k-group-cell"> </td><td style="display:none" role=\'gridcell\'>'+e(data.Id==null?'':data.Id)+'</td><td  role=\'gridcell\'>'+e(data.Piva==null?'':data.Piva)+'</td><td  role=\'gridcell\'>'+e(data.RagioneSociale==null?'':data.RagioneSociale)+'</td><td  role=\'gridcell\'>'+e(kendo.format("{0:dd/MM/yyyy}",data.Data==null?'':data.Data))+'</td><td  role=\'gridcell\'>'+e(data.AnnoEsercizio==null?'':data.AnnoEsercizio)+'</td><td  role=\'gridcell\'>'+e(data.Frequenza==null?'':data.Frequenza)+'</td><td  role=\'gridcell\'>'+e(data.Stato==null?'':data.Stato)+'</td><td  role=\'gridcell\'><a class="k-button k-button-icontext k-grid-download"  href="#"><span class=" "></span>download</a><a class="k-button k-button-icontext k-grid-followup"  href="#"><span class=" "></span>followup</a></td><td  role=\'gridcell\'>'+e(data.FollowUp.FollowUp1==null?'':data.FollowUp.FollowUp1)+'</td></tr>';}return o;
}


it looks like that this datasource doesn't expose the property "FollowUp" at all!
could you help me to understand, please!
Alessio.

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 10 May 2013, 07:27 AM
In the sample data, the FollowUp field is not an array -- you should be able to access the FollowUp1 field through the expression FollowUp.FollowUp1.

Please note that the grid does not support binding to the full depth of the HierarchicalDataSource at this time; it binds only to the root level. If you need to show hierarchical data, see the hierarchical binding example.

Kind regards,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Hierarchical Data Source
Asked by
aa aa
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or