This is a migrated thread and some comments may be shown as answers.

[Solved] Get the item value from clicked checkbox

3 Answers 91 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pedro
Top achievements
Rank 1
Pedro asked on 06 Aug 2010, 07:33 PM
Hi all,
How can I get the item value based on the clicked checkbox?
I need to filter a grid based on the clicked chebox in the treeview (I'll do this using json).

Regards,
Pedro

3 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 09 Aug 2010, 09:46 AM
Hello Pedro,

If you are subscribed to the onChecked client-side event, you can use the following script to get the item value:
    var treeview = $('#TreeView').data('tTreeView');
    var value = treeview.getItemValue(e.item);


If you want to get the values of all checked treeview items, you can use the following:
    var $treeviewElement = $('#TreeView1');
    var treeview = $treeviewElement.data('tTreeView');
    var values = [];
    $treeviewElement.find(':checked').each(function() {
        var item = $(this).closest('.t-item');
        values.push(treeview.getItemValue(item));
    });

    // values is now an array that contains all checked items' values

Regards,
Alex Gyoshev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Pedro
Top achievements
Rank 1
answered on 09 Aug 2010, 01:46 PM
Thank you Alex, but I dont have the onChecked event in the TreeView (I think i'm using a old version of the control). :(
Can I update the control? (I'm not using the .Net 4 framework)
Is This the best choice?

Cheers,
Pedro
0
Pedro
Top achievements
Rank 1
answered on 10 Aug 2010, 06:58 PM
Well... I did it my way. :)
I put a code to get all the treeview checkboxes and put a click event to fire a post using json.
Like this:
 

 $(document).ready(function () {
        $("#treeview").find("li").find("div").each(function (index, item) {
            var cb = $(item).find(':checkbox');
            $(cb).click(function () {
                if (cb.attr("checked")) {
                    jsonPost(cb, item, true);
                } else {
                    jsonPost(cb, item, false);
                }
            });           
        });       
    })

 

 


I hope this help somebody.

Cheers,
Pedro 

Tags
TreeView
Asked by
Pedro
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Pedro
Top achievements
Rank 1
Share this question
or