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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add ClientSideEvents dynamically to an existent control.

Thread ID:

Created:

Updated:

Platform:

Replies:

127117 Oct 27,2016 04:54 AM UTC Nov 8,2016 07:00 AM UTC ASP.NET MVC 3
loading
Tags: TreeView
Juan Acosta
Asked On October 27, 2016 04:54 AM UTC

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



Ashokkumar Balasubramanian [Syncfusion]
Replied On 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.

Juan Acosta
Replied On 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

Ashokkumar Balasubramanian [Syncfusion]
Replied On November 8, 2016 07:00 AM UTC

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;