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

Add ClientSideEvents dynamically to an existent control.

Hi, 

I want to now if it possible to add dynamic ClientSideEvents. 

I have a set of controls inside a partial view something like this:

 <div class="col-lg-3 col-md-6">
    <span class="txt">Select The group To be assigned </span>
    <div style="display: inline-block;">
        @Html.EJ().TreeView("tree").TreeViewFields(s => s.Datasource((IEnumerable<Models.Visual.VisualGroup>)ViewBag.groupsSource)
                .Id("id").ParentId("parentId").Text("name").HasChild("hasChild")).ShowCheckbox(true).EnablePersistence(true).EnableRTL(true).LoadOnDemand(true).ClientSideEvents(e => e.NodeCheck("onItemSelectGroups")).ClientSideEvents(e => e.NodeUncheck("onItemSelectGroups"))
    </div>
</div>
<div class="col-lg-3 col-md-6">
    <span class="txt">and/or the specific Individual.</span>
    @Html.EJ().TreeView("tree2").TreeViewFields(s => s.Datasource((IEnumerable<Models.Visual.VisualGroup>)ViewBag.groupsIndividualSource)
                .Id("id").ParentId("parentId").Text("name").HasChild("hasChild")).ShowCheckbox(true).EnablePersistence(true).EnableRTL(true).LoadOnDemand(true).ClientSideEvents(e => e.NodeCheck("onItemSelectGroups")).ClientSideEvents(e => e.NodeUncheck("onItemSelectGroups"))
</div>

I want to reuse that control several times in different screens. However, the method onItemSelectGroups is burned to the control.
<script type="text/javascript">
function onItemSelectGroups(args) {
    console.log('onItemSelectGroups ' + args);
    //do something
}
</script>

I want to add that method dynamically using javascript. 

So, I will have the partial view with the simple declaration of the object

 @Html.EJ().TreeView("tree").TreeViewFields(s => s.Datasource((IEnumerable<Models.Visual.VisualGroup>)ViewBag.groupsSource)
                .Id("id").ParentId("parentId").Text("name").HasChild("hasChild")).ShowCheckbox(true).EnablePersistence(true).EnableRTL(true).LoadOnDemand(true)

So, I can customise specific behaviours per screen that have that partial included.

Could you please tell me how to create a function to recover the control and dynamically assign the events NodeUncheck and NodeCheck on demand to a specific javascript functions.

Kind regards, 

Juan Acosta



3 Replies

AB Ashokkumar Balasubramanian Syncfusion Team November 1, 2016 01:42 PM UTC

Hi Juan, 
 
Thank you for contacting syncfusion support. 
 
We have analyzed requirement (dynamically add ClientSideEvents for treeview control) and code snippet. We can dynamically add any property and events using option method.    
 
Please refer the below code snippet: 
 
[JAVASCRIPT] 
   function screen1Check(args){ 
        console.log("Screen1 Element Checked"); 
    } 
    function screen1UnCheck(args) { 
        console.log("Screen1 Element UnChecked"); 
    } 
   var treeObj = $("#tree").ejTreeView("instance"); 
   treeObj.option({ "nodeCheck": “screen1Check”, "nodeUncheck": “screen1UnCheck” }); 
 
To know more about the api configuration, please refer the below link. 
 
Based on your requirement, we have prepared simple sample. Please check the sample in below location 
Please let us know whether the provided information is helpful for achieve your requirement.  
 
Regards, 
Ashokkumar B.


JA Juan Acosta November 7, 2016 05:39 AM UTC

Hi Ashokkuma,

Thank you for your reply. I will analyse the source code provided and let you know if I have suggestions or doubts.

Kind regards,

Juan


AB Ashokkumar Balasubramanian Syncfusion Team November 8, 2016 07:00 AM UTC

Hi Juan, 
 
Thanks for the update. We will wait to hear from you. 
 
Regards, 
Ashokkumar B. 


Loader.
Up arrow icon