$(function () {
$.ajax({
type: "POST",
url: "../SampleController/GetTreeViewData",
data: {},
success: function (res) {
$("#treeView").ejTreeView({
fields: { id: "ID", parentId: "PID", text: "Name", hasChild: "HasChild", dataSource: res },
showCheckbox: true,
});
},
error: function (xhr, status, error) {
alert(error);
},
datatype: "json"
});
});
We can achieve your requirement using our existing method called “getTreeData” that return the list of tree view data. By specifying the checked node index value ( get checked node index using getCheckedNodesIndex method) in the tree view data list and get the custom values of the specified index. Please find the code snippet as follows:
function getCustomValue() {
// To get entrie tree data. var data = treeObj.getTreeData();
// To get the checked node index value. var checkedIndex = treeObj.getCheckedNodesIndex();
// To get the checkded node object. data[checked node index] checkedNodeObj = data[12]; // 12 is one of the checked node index.
// you can get the custom values from the node object. } |
http://jsplayground.syncfusion.com/1obqogbj
In the above sample, while clicking the button, we get the entire tree view data using the “getTreeData” method. By specifying the checked node index value in the tree view data and we have get the custom values of the specified index.
Please check with the given solution, if we have misunderstood your query, please provide us more details about the requirement with code snippet. This will help us to provide the exact solution to the requirement.
Query: “getCheckedNodesIndex()” doesn't work in this early version.
We are unable to reproduce the reported issue “getCheckedNodesIndex()” doesn't work in this early version” on our end. We have prepared a sample with “getCheckedNodesIndex”.Please find the sample on the above JSPlayGroundSample link.
Please check with given sample and if you are still facing any issues, please provide more information about your issue and also revert the sample with replication procedure. This will help us to provide the exact solution.
Please let me know, if you have any further assistance
Regards,
Gobalakrishnan S
[Script]
$("#btn").click(function () {
var treeObj = $("#tree").data("ejTreeView");
var widgets = { checkedNodes: treeObj.getCheckedNodesIndex() };//get the index of checked nodes
$.ajax({
url: '/Home/About',
type: 'POST',
dataType: 'json',
data: JSON.stringify(widgets),
contentType: 'application/json; charset=utf-8',
success: function (result) {
$("#demo").html("Current Checked Nodes are: " + result.toString());
},
});
});
[Controller]
[HttpPost]
public JsonResult About(IEnumerable<int> checkedNodes)
{
if (checkedNodes == null)
return Json("");
return Json(checkedNodes, JsonRequestBehavior.AllowGet);
}
|