Telerik Forums
UI for ASP.NET MVC Forum
3 answers
349 views

How can we select the node that is clicked on by a right click event?  I am trying to pass the selected node's id on a context menu select event but unless the user left clicks on the node to select it first, the last selected node information gets sent, if one was even selected.

This may be fairly basic, but I can't find any examples of this.

Thanks.

Neli
Telerik team
 answered on 25 Oct 2017
3 answers
148 views

Hello,

 

I have a Kendo treeview which loads on demand and i am using hierarchial data. So it only loads children when clicked on node . everything works fine till my records are more than 3000. In Firefox the tree loads in 5 seconds. But in IE the browser hangs and never recovers.

This is how my treeview looks

@(Html.Kendo().TreeView()
.Name("objtreeView")
.HtmlAttributes(new { style = "height:700px;overflow-x:hidden;" })
.DataImageUrlField("imageUrl")
.DataTextField("Text")
.LoadOnDemand(true)
.Template(
"# if (item.AdditionalImageUrl !='') { #" +
"<img src='#= item.AdditionalImageUrl#'/> #:item.Text#" +
"# } else {#" +
" #:item.Text#" +
"# }#"
)
.Events(events => events
.Select("onSelect")
)
.DataSource(dataSource => dataSource       
        .Read(readtree => readtree
.Action("ReadObjects", "Objekt").Data("addSearch")
)
)
)

 

And ReadObjects Looks like this

public JsonResult ReadObjects(string Id, string)
{

DataSet ds = cObjData.ReadObjects();
if ((ds != null) && ds.Tables.Count > 0)
{
//Alle Zeilen durchgehen
foreach (DataRow r in ds.Tables[0].Rows)
{

result.Add(new { Text = strText, id = r["ObjectID"].ToString(), Color = hexColor, hasChildren = bhaschildren, imageUrl = Url.Content(strImage), AdditionalImageUrl = "" });

}

return Json(result.AsQueryable(), JsonRequestBehavior.AllowGet);

}

 

In production sometimes we have 10,000 records to load. Any help is appreciated

 

Thanks

 

Anamika

Neli
Telerik team
 answered on 21 Sep 2017
1 answer
290 views

Hello,

I'm looking for add a target blank to an url but i wonder how to do it:

        @(Html.Kendo().TreeView()
        .Name("treeview-right")
        .DragAndDrop(true)
        .Items(treeview =>
        {

            treeview.Add().Text("Accès Mirakl")
                          .Url("http://google.com")
                          .ImageUrl(Url.Content("~/Content/images/internet_16x16.png"));

            treeview.Add().Text("Wiki Mirakl")
                          .Url("http://goole.fr")
                          .ImageUrl(Url.Content("~/Content/images/ampoule_16x16.png"));
        })

Neli
Telerik team
 answered on 12 Sep 2017
7 answers
991 views

Hi, 

I have a Treeview with a specific hierarchy. The parent and children nodes have checkboxes. 

The parent node should be completely checked if all the children nodes under them are checked and it should be partially checked if the children nodes are not completely checked. 

But in my case, the parent node which is having partially checked children nodes is not highlighted or partially checked when the treeview loads initially. Once the parent node has been read, the node is partially checked. I need the parent node to be partially checked if it has partially checked children nodes when the Treeview loads for the first time itself. 

I have attached the screenshot too.

Thanks in advance.

Ivan Danchev
Telerik team
 answered on 18 Aug 2017
1 answer
260 views
Hey guys,

I have a solution for adding Html.ActionLink to the Template of a TreeView control.  I searched everywhere for something similar and I was unable to find it, so I'm going to post it here in hopes that it might help others in the same predicament.

I am using the razor pages for my implementation so I, for the most part, setup my TreeView control exactly like the Remote Data Binding demo found here: http://demos.telerik.com/kendo-ui/web/treeview/remote-data.html 

My Tree View control looks like this:

<div>
       @(Html.Kendo().TreeView()
        .Name("treeview")
        .DataTextField("DisplayValue")
        .DataSource(dataSource => dataSource
            .Read(read => read
                .Action("CategoryTree", "Category")
                )
            )
        )
 </div>

In my case, I wanted to add a couple of Action Links to the end of each item, in this categories.  The purpose of the action link was to navigate to a screen to allow the user to edit the items in the category tree.  I searched everywhere but could not find a way to do this.  I even came across a few posts stating that this was not possible.

I chose to use .Template() to add the action links.

Here's what I added to my tree to add an action link.

.Template("#: item.DisplayValue #  " + @Html.ActionLink("Update", "Update", new { id = "newId" })
.ToHtmlString().Replace("newId", "#: item.id #"))


After I added one, I added a second that would navigate to another page.  My final tree view control looks like this:

<div style="padding-top: 10px;">
 
    @(Html.Kendo().TreeView()
        .Name("treeview")
        .DataTextField("DisplayValue")
        .DataSource(dataSource => dataSource
            .Read(read => read
                .Action("CategoryTree", "Category")
                )
            )
            .Template("#: item.DisplayValue #  " + @Html.ActionLink("Update", "Update", new { id = "newId" })
            .ToHtmlString().Replace("newId", "#: item.id #") + " | " + @Html.ActionLink("Deactivate", "Deactivate", new { id = "newId" })
            .ToHtmlString().Replace("newId", "#: item.id #"))
        )
</div>


I hope this helps someone out because it's not documented anywhere.

Cheers!
Rich
Top achievements
Rank 1
 answered on 24 Jul 2017
10 answers
142 views

I have a treeview set up as below ("treeview"), and the rendered checkboxes are not styled according to the theme (bootstrap).  If I set up another treeview with local data ("treeview1"), they render as themed.  Any hints as to how i can get the checkboxes to adhere to the theme when using a datasource?

 

NOT THEMED:

@(Html.Kendo().TreeView()
        .Name("treeview")
        .Checkboxes(checkboxes => checkboxes.Name("checkedCategories")
        .CheckChildren(true))
        .Events(events => events.Check("onCheck"))
        .DataTextField("description")
        .DataSource(dataSource => dataSource
            .Model(m => m.HasChildren("HasChildren").Children("Children"))
            .Read(read => read.Action("GetFilters", "ProductList")))
          )

THEMED:

@(Html.Kendo().TreeView()
        .Name("treeview1")
        .Checkboxes(checkboxes => checkboxes.Name("checkedCategories"))
        .Items(treeview =>
       {
           treeview.Add().Text("Asset Class").Id("1-1")
               .Expanded(true)
               .Items(category =>
               {
                   category.Add().Text("My first thing").Id("2-1");
                   category.Add().Text("My Second Thing").Id("2-2");
               });
       }))

Magdalena
Telerik team
 answered on 14 Jul 2017
1 answer
302 views

I am attempting to write the onDrop event:

function onTreeDrop(e) {
        var treeview = $("#treeview").data("kendoTreeView");
        var p = e.dropPosition;
        
        sn = treeview.dataItem(e.sourceNode);
        dn = treeview.dataItem(e.destinationNode);
        psn = treeview.parent(e.sourceNode);
        pdn = treeview.parent(e.destinationNode);

        if (p == "over") {
            if (dn.IsDept) {
                treeview.append(sn, pdn);
            }
            else {
                treeview.append(sn, dn);
            }
            e.setValid(true);
        }
        else if (p == "before") {

        }
        else if (p == "after") {

        }
    }

 

when I do a drop over I get the following error:

 

kendo.all.js:78326 
Uncaught TypeError: t.children is not a function
    at kendo.all.js:78326
    at init.append (kendo.all.js:79643)
    at init.onTreeDrop (Index:497)
    at init.trigger (kendo.all.js:124)
    at Object.drop (kendo.all.js:78557)
    at init.dragend (kendo.all.js:78269)
    at init.i (jquery-1.10.2.min.js:21)
    at init.trigger (kendo.all.js:124)
    at init._trigger (kendo.all.js:23904)
    at init._end (kendo.all.js:23881)

when I follow the error to kendo.all.js:78326 the object has node.children. My own Model has a Children property. Perhaps the two "children" are conflicting?

 

 

Index:497 Unc
aught TypeError: t.children is not a function at kendo.all.min.js:66 at init.append (kendo.all.min.js:67) at init.onTreeDrop (Index:497) at init.trigger (kendo.all.min.js:25) at Object.drop (kendo.all.min.js:67) at init.dragend (kendo.all.min.js:66) at init.i (jquery-1.10.2.min.js:21) at init.trigger (kendo.all.min.js:25) at init._trigger (kendo.all.min.js:36) at init._end (kendo.all.min.js:36)
Index:497 Uncaught TypeError: t.children is not a function at kendo.all.min.js:66 at init.append (kendo.all.min.js:67) at init.onTreeDrop (Index:497) at init.trigger (kendo.all.min.js:25) at Object.drop (kendo.all.min.js:67) at init.dragend (kendo.all.min.js:66) at init.i (jquery-1.10.2.min.js:21) at init.trigger (kendo.all.min.js:25) at init._trigger (kendo.all.min.js:36) at init._end (kendo.all.min.js:36)
Dimitar
Telerik team
 answered on 01 Jun 2017
2 answers
238 views
Hi , 

the data model structure the following :
public class TreeMainItem
{
   private IList<TreeSubItem> _SubItems;
   private bool _hasChildren =true;
 
   public TreeMainItem()
   
       _SubItems = new List<TreeSubItem>();
   }
 
   public int ItemIndex { get; set; }
   public string Title { get; set; }
   public string CssClass { get; set; }
   public string TargetUrl { get; set; }
   public string IconUrl { get; set; }
   public bool hasChildren
   {
      get { return this._hasChildren; }
      set { this._hasChildren = value; }
   }
   public IList<TreeSubItem> SubItems
   {
      get { return this._SubItems; }
      set { this._SubItems = value; }
   }
}
 
public class TreeSubItem
{
   private bool _hasChildren = false;
    
   public int ItemIndex { get; set; }
   public string Title { get; set; }
   public string CssClass { get; set; }
   public string TargetUrl { get; set; }
   public string IconUrl { get; set; }
   public bool hasChildren
   {
      get { return this._hasChildren; }
      set { this._hasChildren = value; }
   }
}

I use Html.Kendo().TreeView().DataSource() , but treeview can't  render subitem , 

how could I fix or use other method ?
Ivan Danchev
Telerik team
 answered on 17 May 2017
4 answers
135 views

http://dojo.telerik.com/IGujU/3

How to make it so the hint can only be moved within the boundaries of the parent?
And how to autoscroll if I have a very long list, like i'm dragging the last item and when the hint is on top most of the visible viewport it will scroll up?

Ianko
Telerik team
 answered on 10 May 2017
2 answers
396 views

I want to render a treeview and a tabstrip within a page. This tabstrip will have three tabs each of which will render a grid inside it.

<div class="row">
    <div class="demo-section narrow tree-view">
        <div>
            @(Html.Kendo().TreeView()
                .Name("AssetTreeView")
                .DataTextField("Name")
                .DataSource(dataSource => dataSource
                    .Read("ReadCategories", "Software")
                    .Model(categoriesModel => categoriesModel
                        .Id("Id")
                        .Children(clientHw => clientHw
                            .Read("ReadClientHWs", "Software")
                            .Model(clientHWModel => clientHWModel.Id("Id"))
                        )
                    )
                )
                .Events(events => events
                    .Select("onNodeSelected"))
            )
        </div>
    </div>
 
    <div class="demo-section wide grid">
        @(Html.Kendo().TabStrip()
        .Name("SoftwareTabStrip")
        .Animation(animation =>
                animation.Open(effect =>
                    effect.Fade(FadeDirection.In)))
        .Items(tabstrip =>
        {
            tabstrip.Add()
                    .Text("Blacklisted")
                    .Selected(true)
                    .ImageUrl("~/Content/Images/32x32/traffic-light-red.png")
                    .ImageHtmlAttributes(new { style = "width: 32px; height: 32px; padding: 3px;" })
                    .Content(@<text>Blacklisted is bad!
                        @(Html.Kendo().Grid<MyIT.ModelsInterfaces.Models.MyIT.Software>()
                            .Name("BlacklistedSoftwareGrid")
                            .Columns(columns =>
                            {
                                columns.Bound(s => s.Publisher).Width(250);
                                columns.Bound(s => s.SoftwareName).Width(250);
                                columns.Bound(s => s.Version).Width(100);
                                columns.Bound(s => s.Description).Width(400);
                            })
                            .NoRecords("No blacklisted software installed...")
                            .Pageable()
                            .Sortable()
                            .Scrollable(x => x.Height(400))
                            .Filterable()
                            .DataSource(dataSource => dataSource
                                .Ajax()
                                .PageSize(20)
                                .Read(read => read.Action("GetRedSoftware", "Software").Data("additionalData"))
                            )
                            .Events(events => events
                                .DataBound("onBlacklistedBound")
                                .DataBinding("onDataBinding"))
                        )
                    </text>);
 
            tabstrip.Add()
                .Text("Other Software")
                .ImageUrl("~/Content/Images/32x32/traffic-light-yellow.png")
                .ImageHtmlAttributes(new { style = "width: 32px; height: 32px; padding: 3px;" })
                .Content(@<text>Yellow is allowed!
                    @(Html.Kendo().Grid<MyIT.ModelsInterfaces.Models.MyIT.Software>()
                            .Name("UnsupportedSoftwareGrid")
                            .Columns(columns =>
                            {
                                columns.Bound(s => s.Publisher).Width(250);
                                columns.Bound(s => s.SoftwareName).Width(250);
                                columns.Bound(s => s.Version).Width(100);
                                columns.Bound(s => s.Description).Width(400);
                            })
                            .NoRecords("No software available...")
                            .Pageable()
                            .Sortable()
                            .Scrollable(x => x.Height(400))
                            .Filterable()
                            .DataSource(dataSource => dataSource
                                .Ajax()
                                .PageSize(20)
                                .Read(read => read.Action("GetYellowSoftware", "Software").Data("additionalData"))
                            )
                            .Events(events => events
                                .DataBound("onUnsupportedBound")
                                .DataBinding("onDataBinding"))
                    )
                </text>);
 
            tabstrip.Add()
                .Text("Supported")
                .ImageUrl("~/Content/Images/32x32/traffic-light-green.png")
                .ImageHtmlAttributes(new { style = "width: 32px; height: 32px; padding: 3px;" })
                .Content(@<text>Green is supported!
                    @(Html.Kendo().Grid<MyIT.ModelsInterfaces.Models.MyIT.Software>()
                            .Name("SupportedSoftwareGrid")
                            .Columns(columns =>
                            {
                                columns.Bound(s => s.Publisher).Width(200);
                                columns.Bound(s => s.SoftwareName).Width(200);
                                columns.Bound(s => s.Version).Width(100);
                                columns.Bound(s => s.Description).Width(400);
                            })
                            .NoRecords("No software available...")
                            .Pageable()
                            .Sortable()
                            .Scrollable(x => x.Height(400))
                            .Filterable()
                            .DataSource(dataSource => dataSource
                                .Ajax()
                                .PageSize(20)
                                .Read(read => read.Action("GetGreenSoftware", "Software").Data("additionalData"))
                            )
                            .Events(events => events
                                .DataBound("onSupportedBound")
                                .DataBinding("onDataBinding"))
                    )
                </text>);
        })
        )
    </div>
</div>

The treeview should always return one node (HW Category) expanded with one of it's child node (ClientHW) selected. 

Note: ReadClientHWs action method below will return node object with one of the property named "selected"

public class SoftwareController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
 
    public ActionResult ReadCategories()
    {
        var categories = from category in _clientHWService.GetMajorAssetCategoriesOfUser(_myITService.GetCurrentUser())
                         select category;
 
        return Json(_mapperService.MapToClientHWCategoryItems(categories),
            JsonRequestBehavior.AllowGet);
    }
 
    public ActionResult ReadClientHWs(int id)
    {
        var clientHardwares = from hw in _clientHWService.GetMajorAssetsForUser(_myITService.GetCurrentUser())
                              where hw.UsedAsId.Equals(id)
                              select hw;
 
        return Json(_mapperService.MapToClientHWItems(clientHardwares), JsonRequestBehavior.AllowGet);
    }
 
    public ActionResult GetGreenSoftware([DataSourceRequest] DataSourceRequest request, string computerName)
    {
        return Json(_softwareService.GetGreenSoftwares(computerName).ToDataSourceResult(request));
    }
 
    public ActionResult GetYellowSoftware([DataSourceRequest] DataSourceRequest request, string computerName)
    {
        return Json(_softwareService.GetYellowSoftwares(computerName).ToDataSourceResult(request));
    }
 
    public ActionResult GetRedSoftware([DataSourceRequest] DataSourceRequest request, string computerName)
    {
        return Json(_softwareService.GetRedSoftwares(computerName).ToDataSourceResult(request));
    }
}

I successfully made the grid loads the correct data every time user click one of the ClientHW nodes. but I haven't been able to render the grid base on this selected node the first time the page load.
how can i accomplish this?

Raditya
Top achievements
Rank 1
 answered on 05 May 2017
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?