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

how to fire a event inside treeview node

2 Answers 305 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 29 Jan 2013, 08:44 PM
 <script id="treeview-template" type="text/kendo-ui-template">
            <button  class="editrow"><i class="icon-pencil"></i>Edit</button>
            <button  class="removerow k-button"><i class="icon-trash"></i>Delete</button>
         
             <span class="k-label" style="margin-left:50px">#: item.AttrID #</span>  <span class="k-label" style="margin-left:150px"> #: item.AttrDesc #</span>
            <input type="hidden" name="itemid" value="#: item.UID # ">
            <input type="hidden" name="itemCustomerUID" value="#: item.CustomerUID # ">
             <input type="hidden" name="itemAttrTable" value="#: item.AttrTable # ">
            <input type="hidden" name="itemAttrID" value="#: item.AttrID # ">
             <input type="hidden" name="itemAttrDesc" value="#: item.AttrDesc # ">                      
</script>     

both 
  $('.removerow').on('click', function (e) {                  
            alert('removerow edit');           
        });

and
  $('.removerow').on('click', function (e) { 
  e.preventDefault();
            e.stopPropagation();                
            alert('removerow edit');           
        });
can not work.


i even add 
 $('#treeview').kendoTreeView({
            dataSource: hierarchyAttrs,
             select: onSelect,
            template: kendo.template($("#treeview-template").html())
        });

        function onSelect(e) {
            alert('sel');
           e.preventDefault();
          e.stopPropagation();
         }
it can show 'sel'
but  alert('removerow edit');  still can not work.

same thing for the .editrow


pls help , urgent.
thanks
andy



2 Answers, 1 is accepted

Sort by
0
Andy
Top achievements
Rank 1
answered on 29 Jan 2013, 09:04 PM
i changed treeview to listview , samething , can not fire click inside both treeview and listview.


help

when i changed the button outside  both treeview and listview. it showed alert, that is ok


0
Accepted
Alex Gyoshev
Telerik team
answered on 30 Jan 2013, 08:08 AM
Hello Andy,

The code
$('.removerow').on('click', function (e) { ... })
immediately finds all .removerow elements on the page. It is likely that they are not yet rendered, and thus -- they do not get the event handler. In order to handle all such elements that will be added to the treeview in the future, use delegated events. In your scenario, this would be:
$('#treeview').on('click', '.removerow', function (e) { ... })

Regards,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Andy
Top achievements
Rank 1
Answers by
Andy
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Share this question
or