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

[Solved] Delete and Edit TreeView on client side

8 Answers 472 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.
Evgenuy
Top achievements
Rank 1
Evgenuy asked on 29 Mar 2010, 08:52 AM
How i can delete and edit Treeview on client side,
for example using JQuery.
Controller Action call javascript on clientside:
       public JavaScriptResult ObjectType_Delete(Int64? Id) 
        { 
            var script = string.Empty; 
            if (Id.HasValue) 
            { 
                Models.ObjectType dbObjectType = _dataManager.ObjectTypeRepository.GetObjectType(objTypeId.Value); 
                if (dbObjectType != null) 
                { 
                    _dataManager.ObjectTypeRepository.DeleteObjectType(dbObjectType.ObjectType_Id); 
 
                    script = string.Format("onItemDelete({0},{1})", objTypeId.Value, JavaScriptEncode(dbObjectType.Name)); 
                    return JavaScript(script); 
                } 
            } 
            return null; 
        } 
 
 
 
 
 
 
 
 
Java script on client side





                    <script type="text/javascript"> 
                         function onItemDelete(id, name) { 
 
                         } 
                    </script> 

How i can delete or edit node in treeview?
this is a declared TreeView:
                    <%=Html.Telerik().TreeView() 
                            .Name("objecttypetree") 
                            .BindTo(Model.ObjectTypeList, (item, objType) => 
                                { 
                                    // bind initial data - can be omitted if there is none 
                                    item.Text = objType.Name; 
                                    item.Value = objType.ObjectType_Id.ToString(); 
                                    item.LoadOnDemand = (from i in Model.DataManager.ObjectTypeRepository.GetObjectTypes(objType.ObjectType_Id) 
                                                         select i).Count() > 0; 
                                    item.ImageHtmlAttributes.Add("style", "margin-right: 10px"); 
                                }) 
                         .DataBinding(dataBinding => dataBinding.Ajax().Enabled(true).Select("ObjectTypeTree_AjaxLoading", "ObjectType") 
                         )  %> 


Fanks.

8 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 01 Apr 2010, 02:01 PM
Hello Evgenuy,

I am sending you a complete example showing how to perform CRUD with the TreeView. It is using a newer build than the official one which is attached in this forum thread.

I hope this helps,
Atanas Korchev
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
Evgenuy
Top achievements
Rank 1
answered on 01 Apr 2010, 05:41 PM
Fank you very match!
0
Nick
Top achievements
Rank 1
answered on 18 Mar 2011, 10:49 AM
Hi,

Thanks for posting the CRUD example, I found it very useful...
I have one question though .. ? the context menu does not rewind after a right click in IE..
Any suggestions to make this work ?

Cheers,

Nick
0
Mathias
Top achievements
Rank 1
answered on 21 Mar 2011, 04:50 PM
I would like to point out that the example you attach is not a complete CRUD example. There is no Create/Add functionality in it.
0
Carson
Top achievements
Rank 1
answered on 06 Apr 2011, 06:32 PM
This is some excellent JavaScript. I think this functionality should be part of the TreeView by default.
But anyway, a slight improvement: in function onLoad(), I strongly suggest adding the following after e.preventDefault()

$('div#contextMenu').each(function (index) {
    $(this).remove();
});

... to get rid of old context menus that may be laying around... for instance, after multiple consecutive 'contextmenu' events.

EDIT
Or better yet, for some animated goodness do this:

// default "slide" effect settings
 var fx = $.telerik.fx.slide.defaults();
 
$('div#contextMenu').each(function (index) {
   $.telerik.fx.rewind(fx, $(this).find('.t-group'), { direction: 'bottom' }, function () {
     $(this).remove();
   });
});
 
// context menu definition - markup and event handling
var $contextMenu = ...
0
lbartroli
Top achievements
Rank 1
answered on 19 Aug 2011, 07:25 PM
Atanas Korchev Very good example, I would need to create nodes as well as edit and delete. Could you give me an example of this?
Obviously I need to create them dynamically as you edit them.

Thanks .-
0
lbartroli
Top achievements
Rank 1
answered on 06 Oct 2011, 02:29 PM
Please, I need to create nodes too...
0
wandelson
Top achievements
Rank 1
answered on 10 Oct 2011, 01:08 PM
Please ;;  function "create" 
Tags
TreeView
Asked by
Evgenuy
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Evgenuy
Top achievements
Rank 1
Nick
Top achievements
Rank 1
Mathias
Top achievements
Rank 1
Carson
Top achievements
Rank 1
lbartroli
Top achievements
Rank 1
wandelson
Top achievements
Rank 1
Share this question
or