Rick
Rick

Reputation: 35

kendo Treelist keeps telling no records to Display

I´m intending to use some kendo controls from telerik and I started playing with the Treelist control. I´m doing this with Visual Studio 2013 VB or C#.

The plan is to create a webservice that sends some (serialized) data and the user has to manually press a button which is linked to a $Ajax request that POSTS for the data. That data should be passed to the treelist.

But whatever I try it keeps telling me: No Records to Display

Questions:

1 Why is the sample I provided not working. I copied almost literally one of the demo´s.

2 Do you need a seprate datasource or can you put the data direct in the treelist as well?

Thanks in advance.

Rick (NL)

Sample:

`<script type="text/javascript">
 $(document).ready(function () {
      var dataSource = new kendo.data.TreeListDataSource({
         data: [
             { "Item": "Item0", "id": 0, "ParentId": null },
             { "Item": "Item1", "id": 1, "ParentId": 0 },
             { "Item": "Item2", "id": 2, "ParentId": 1 },
             { "Item": "Item3", "id": 3, "ParentId": 1 },
             { "Item": "Item4", "id": 4, "ParentId": null },
             { "Item": "Item5", "id": 5, "ParentId": null },
             { "Item": "Item6", "id": 6, "ParentId": 5 },
             { "Item": "Item7", "id": 7, "ParentId": 5 },
             { "Item": "Item8", "id": 8, "ParentId": 7 },
             { "Item": "Item9", "id": 9, "ParentId": 7 }
         ],
         schema: {
             model: {
                 id: "id",
                 expanded: true
             }
         }
     });

     $("#treelist").kendoTreeList({
         dataSource: dataSource,
         height: 540,
         columns: [
             { field: "Item" },
             { field: "id" },
             { field: "ParentId" }
         ]
     });
 });

</script>

Upvotes: 3

Views: 6922

Answers (5)

Matthew
Matthew

Reputation: 500

Lets not forget the 'parentId' field on the model definition. We don't have to change the JSON properties that way (ParentId needs describing in fields as well though):

var dataSource = new kendo.data.TreeListDataSource({
        data: [
            { Id: 1, Name: "test", ParentId: null },
            { Id: 2, Name: "test 2", ParentId: 1 }
        ],
        schema: {
            model: {
                id: "Id",
                parentId: "ParentId",
                fields: {
                    Name: { field: "Name", type: "string" },
                    StoreCount: { field: "StoreCount", type: "number" },
                    ParentId: { field: "ParentId", nullable: true }
                },
                expanded: true
            }
        }
    });

Upvotes: 2

nitech
nitech

Reputation: 1832

@user4659712 yes, you can define the schema. parentId can be anything as long as you tell through the schema:

     vm.treeListDataSource = new kendo.data.TreeListDataSource({
         data: organizations,
         schema: {
             model: {
                 id: "Id",
                 fields: {
                     Id: { type: "number", nullable: false },
                     parentId: { field: "OverliggendeId", nullable: true }
                 },
                 expanded: true
             }
         },
         pageSize: 20
     });

Upvotes: 6

user4659712
user4659712

Reputation:

Does anyone know if you can specify a database column with a different name to be the parentid? For example, my table has node_id and parent_node_id.

Upvotes: 1

bob.mazzo
bob.mazzo

Reputation: 5627

parentId also needs to be null if it's the top-level record. That really tripped me up.

Upvotes: 13

David Shorthose
David Shorthose

Reputation: 4497

This is down to a simple typo the "ParentId" needs to be parentId (note lowercase p).

see this dojo for a working version.

http://dojo.telerik.com/uWaSO

I've fallen foul of this before.

Upvotes: 3

Related Questions