How to define a Model for a kendoTreeList?

1 Answer 40 Views
TreeList
George
Top achievements
Rank 3
Bronze
Bronze
Iron
George asked on 18 Jul 2024, 08:23 PM | edited on 18 Jul 2024, 08:29 PM

Hi,

I am trying to define a Model for my kendoTreeList.

Normally I would define a Model like:


var Product = kendo.data.Model.define({
    id: "ProductID", // Defines the field to be used as the identifier.
    fields: {
        // Define the fields of the model and their data types.
        ProductID: { type: "number" },
        ProductName: { type: "string" },
        QuantityPerUnit: { type: "string" },
        UnitPrice: { type: "number" },
        UnitsInStock: { type: "number" },
        Discontinued: { type: "boolean" }
    }
});

 

But with the TreeList  you normally have to define the Model like this with a parentId:

                            model: {
                                id: "EmployeeId",
                                parentId: "SupervisorId",
                                fields: {
                                    SupervisorId: { field: "SuperviorId", nullable: true },// this is the parent.
                                    EmployeeId: { field: "EmployeeId", type: "number" }, 
                                },
                                expanded: true
                            }


I don't think kendo.data.Model.define works for this type of model  because it doesnt have some of the properties like parentId or expanded. Is there something I can substitute it with?

What I am trying to do is create a class of Models and I can slide the Model definition in like:


    $("#reportsTreeList").kendoTreeList({

        dataSource:
        {
            data: reports,
            schema: {
                model: Models.TREELISTMODEL
            }
        },
        height: "auto",

OR:


var ds = new kendo.data.DataSource({ data: reportsList, schema: { model: Models.TREELISTMODEL }});

this approach seems to work with a kendo spreadsheet or a grid... but TreeView  seems to break.

Thanks again for your help and patience!

George

1 Answer, 1 is accepted

Sort by
0
Accepted
George
Top achievements
Rank 3
Bronze
Bronze
Iron
answered on 18 Jul 2024, 08:41 PM

Ooof! Answered my own question. There is a TreeListModel.

API Reference for Kendo Data TreeListModel - Kendo UI for jQuery (telerik.com)

You can define / initialize it in a class it like this:


class Models {
    static TREELISTMODEL = kendo.data.TreeListModel.define({

        id: "employeeId",
        parentId: "supervisorId",
        fields: {
            supervisorId: { field: "supervisorId", nullable: true },// this is the parent.
            employeeId: { field: "employeeId", type: "number" },
        },
        expanded: true

    });
}


...and so far it seems to work.

 

George

Tags
TreeList
Asked by
George
Top achievements
Rank 3
Bronze
Bronze
Iron
Answers by
George
Top achievements
Rank 3
Bronze
Bronze
Iron
Share this question
or