We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Get custom values of checked nodes

Hi Team,

I'm trying to use the tree view with checkbox and in the data source I included several custom values. How do I get the custom values of a checked node once  #btnDummy is clicked?
I'm using the Vol3 SP1 (2015) - v13.3.0.12 library, as I understand it, getCheckedNodesIndex() doesn't work in this early version.

[script]

$(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"                

            });

});



3 Replies

GS Gobalakrishnan S Syncfusion Team March 17, 2016 02:13 PM UTC

Hi Lory,
Thanks for using Syncfusion products,
Query: How do I get the custom values of a checked node once #btnDummy is clicked?

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.

        }


For your convenience, we have prepared the JSPlayGroundSample .Please find the sample as follows:

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



ME Megatron August 16, 2016 05:25 PM UTC

I am using similar with ASP MVC C#, can you tell me how to send and get checked values of the list to POST on the serverside


PR Piramanayagam Ramakrishnan Syncfusion Team August 17, 2016 01:53 PM UTC

Hi Lory, 
 
Thanks for your update. 
 
We have analyzed your query. You can achieve your requirement (“how to send and get checked values of the list to POST on the server side”) by using AJAX in application level. You can pass the checked node values to server side and you can access these details from controller action. Please refer the below code sample. 
 
[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); 
} 
 
 
We have prepared the sample based on your requirement and it can be downloaded from the below location: Sample 
 
Are you expecting this? Or please provide the more details about your requirement this would be helpful for us to identify your exact requirement and provide a solution at the earliest. 
 
Regards, 
Piramanayagam R 


Loader.
Live Chat Icon For mobile
Up arrow icon