mardi 26 juin 2018

Kendo TreeList with checkboxes on ASPNET Mvc

I'm using Kendo (and I've almost never used it before) in an ASPNET Mvc application and I need to create a TreeList with checkboxes: checking a father should check all children and unchecking a child should uncheck the father (and the grandfather, and so on). The tree in itself works well: I've added a column with custom template and I'm using (successfully) the onClick event to get the value of the checkbox, but I can't figure out how to "bind" that value to the node of the tree (to reach every child and check it).

Here the code:

@(Html.Kendo().TreeList<TreeElem>()
  .Name("treelist")
  .Columns(col =>{                                                                
     col.Add().Field(f => f.NodeDescription).Title("TREE LIST");
     col.Add().Template("<input type='checkbox' data-bind='checked: checked' onClick='onCheck(event)'/>").Width(55);
   })
   .DataSource(source => source.Read(read => read.Action("GetData", "TreeController"))
   .Model(m => {                                                                                                
             m.Id(f => f.NodeId); 
             m.ParentId(f => f.ParentId);
             m.Field(f => f.NodeDescription);
       })
    )
)

In the javascript:

function onCheck(e) {
  console.log(e.target.checked); //print true/false according to the checkbox
  console.log($("#treelist").data('kendoTreeList').dataSource.data()); //print the complete node list 
  //Other stuffs
}

I would like to get the right node from data() (or view()) according to the checkbox selected. Every node has references to his children and father, so the recursive function should be easy after that. I've looked for and tried a lot of solutions but with almost no result, any idea? Thanks




Aucun commentaire:

Enregistrer un commentaire