1

I am using the Kendo TreeList. I have a data structure in the database using an Adjacency List data structure using Django TreeBeard. For the treelist, since the data is nested, I create flat objects and put them into an array. This works, fine but the treelist doesn't refresh with the data.

The object structure is the same as the one for the parent but the children don't show.

Here is my code.

JSON: PARENT NODE

{"id": 26, "tgtWeight": 0.0, "currWeight": 0.0, "hasChildnode": true, "ext_model_id": 8, "parent": null, "SSM": {"id": 8, "securitySelectionModelName": "ssm8", "userCreatedModel": "[{\"classificationName\":\"ssm8\",\"id\":8,\"hasChildNode\":true,\"child\":[{\"classificationName\":\"MBS\",\"id\":14,\"hasChildNode\":true,\"child\":[{\"classificationName\":\"Common Stock\",\"id\":15,\"hasChildNode\":false}]}]}]", "classificationNames": []}, "classificationNameNode": null}

JSON CHILD NODE

[{"id": 27, "tgtWeight": 0.0, "currWeight": 0.0, "hasChildnode": true, "ext_model_id": 14, "parent": {"id": 26, "tgtWeight": 0.0, "currWeight": 0.0, "hasChildnode": true, "ext_model_id": 8, "parent": null, "SSM": 8, "classificationNameNode": null}, "SSM": {"id": 8, "securitySelectionModelName": "ssm8", "userCreatedModel": "[{\"classificationName\":\"ssm8\",\"id\":8,\"hasChildNode\":true,\"child\":[{\"classificationName\":\"MBS\",\"id\":14,\"hasChildNode\":true,\"child\":[{\"classificationName\":\"Common Stock\",\"id\":15,\"hasChildNode\":false}]}]}]", "classificationNames": []}, "classificationNameNode": {"id": 14, "classificationLevel": 2, "classificationName": "MBS", "hasChildNode": false, "parent": 2}}]

JAVASCRIPT

 $(document).ready(function () {
    var id = {{ id }};

    var dataSource = new kendo.data.TreeListDataSource({
        transport: {
            read: {
                url: "../getModelTargetWeights?SSM_id="+id,
                dataType: "json"
            }
        },
        schema: {
            parse: function(response) {
                NodeArray=[];
                if (response.length == undefined) {

                var node = {
                    id: response.id,
                    currWeight: response.currWeight,
                    tgtWeight: response.tgtWeight,
                    hasChildren: response.hasChildnode,
                    parentId: response.parent,
                    ext_model_id: response.ext_model_id,
                    securitySelectionModelName: response.SSM.securitySelectionModelName,
                    classificationNameNode: response.classificationNameNode
                };
                     NodeArray.push(node);
            } else {
                    for (var i=0; i < response.length; i++){
                        var node = {
                            id: response[i].id,
                            currWeight: response[i].currWeight,
                            tgtWeight: response[i].tgtWeight,
                            hasChildren: response[i].hasChildnode,
                            parentId: response[i].parent.ext_model_id,
                            ext_model_id: response[i].ext_model_id,
                            securitySelectionModelName: response[i].SSM.securitySelectionModelName,
                            classificationNameNode: response[i].classificationNameNode.classificationName
                        }
                        NodeArray.push(node);
                    }
            }

                return NodeArray;
           },
           model: {
                id: "id",
                parentId: "parentId",
                fields: {
                           parentId: { field: "parentId", nullable: true },
                           securitySelectionModelName: "securitySelectionModelName",
                           classificationNameNode: "classificationNameNode",
                           tgtWeight: { field: "tgtWeight", nullable: true },
                           hasChildren: { type: "boolean", field: "hasChildren" }
                }
            }
         }
    });

   $("#treeList").kendoTreeList({
        dataSource: dataSource,
        editable: true,
        height: 540,
        columns: [
                    { field: "securitySelectionModelName", title: "Model Name" },
                    { field: "classificationNameNode", title: "Classification" },
                    { field: "tgtWeight", title: "Target" }
         ],
   });
     dataSource.read();
    });
</script>
Axwack
  • 569
  • 1
  • 8
  • 26

0 Answers0