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

Treeview - onload of page select checkboxes with specific id

6 Answers 195 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
V
Top achievements
Rank 1
V asked on 29 Jan 2020, 11:15 AM

I am trying to select checkboxes in Treeview on load using javascript or jquery. I have tried the following dojo code, but I am getting .dataitems() undefined in console.

Does anyone know why?

6 Answers, 1 is accepted

Sort by
0
V
Top achievements
Rank 1
answered on 30 Jan 2020, 10:24 AM

anyone?

 

0
Veselin Tsvetanov
Telerik team
answered on 03 Feb 2020, 08:40 AM

Hi Vasiliki,

I have tested the Dojo sent in Chrome, IE, Firefox, and Edge. In all browsers, the A and C items are properly checked with no errors observed. Attached you will find a short video of running the sample.

May I ask you to explain a bit in detail what is the issue faced? A short screencast demonstrating the problem would also be very helpfull.

Regards,
Veselin Tsvetanov
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
V
Top achievements
Rank 1
answered on 04 Feb 2020, 07:17 AM
In dojo is working fine for me too! The problem is when I took the code and copy it on  testing project.
0
V
Top achievements
Rank 1
answered on 04 Feb 2020, 07:23 AM

Maybe its because there are children as well in the structure?

Can you do a dojo example with children included in the datasource?

0
Accepted
Veselin Tsvetanov
Telerik team
answered on 07 Feb 2020, 07:42 AM

Hello Vasiliki,

If you need to check items deeper in the hierarchy of the TreeView, you will have to do that when those items are already loaded. Having that said, the check logic should be moved to the dataBound event of the TreeView:

dataBound: function(e) {
  var tv = e.sender;
  var tvDataItems;
  var values = ["A", "C"];

  if(!e.node) {
    tvDataItems = tv.dataItems();
  } else {
    tvDataItems = e.sender.dataItem(e.node).children.data();
  }

  tvDataItems.forEach(function(dataItem) {
    if (values.indexOf(dataItem.text) > -1) {
      dataItem.set("checked", true);
    }
  });
}

Here is a modified version of the Dojo discussed: http://dojo.telerik.com/AqEpIViJ/6

Regards,
Veselin Tsvetanov
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
V
Top achievements
Rank 1
answered on 07 Feb 2020, 07:48 AM
Okay great thank you!
Tags
TreeView
Asked by
V
Top achievements
Rank 1
Answers by
V
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Share this question
or