javascriptjqueryasp.net-mvcjquery-uidevexpress

How to hide the checkboxes of the parent node in the dxTreeList?


I need to hide the parent node's checkbox (Boolean cell) in the tree List. I use DevExpress with jQuery. I am new to this tech. Kindly anyone help me out to solve this problem with efficient way.

I have searched for the solutions through the internet. If I implement them, I have to restructure my saving mechanism of the dxTreeList. I used the built-in checkbox (Boolean cell), but the resources say to use the cell template with custom checkbox.

My code implementation:

dataSource: dataForControls,
id: "id",
parentId: "parentId",
editing: {
   mode: "batch",
   allowAdding: false,
   allowUpdating: true,
   allowDeleting: false,
},
columns: [
   { dataField: "pageName", caption: "Page / Control", allowEditing: false },
   { dataField: "pageAccess", caption: "Has Access", allowEditing: true, dataType: "boolean",
}
]

I need to hide the checkbox of the parent node.


Solution

  • You can use cellTemplate option to achieve your goal. do it like below:

    $("#treeList").dxTreeList({
      dataSource: dataForControls,
      keyExpr: "id",
      parentIdExpr: "parentId",
      editing: {
        mode: "batch",
        allowUpdating: true,
        allowAdding: false,
        allowDeleting: false
      },
      columns: [
        { dataField: "pageName", caption: "Page / Control", allowEditing: false },
        {
          dataField: "pageAccess",
          caption: "Has Access",
          dataType: "boolean",
          allowEditing: true,
          cellTemplate: function(container, options) {
            const isLeaf = !options.row.isNewRow && !options.node.hasChildren; // only for leaf nodes
            if (isLeaf) {
              $("<div>")
                .addClass("dx-checkbox")
                .appendTo(container)
                .dxCheckBox({
                  value: options.value,
                  onValueChanged(e) {
                    options.setValue(e.value);
                  }
                });
            }
          }
        }
      ]
    });