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

[Solved] setting node css from js

5 Answers 96 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.
cp
Top achievements
Rank 1
cp asked on 02 Jun 2011, 12:04 AM
subItems.push(
{
   Text: "Some text"
   Value: "Some value",
   HtmlAttributes: ... class: someClass ...
});

How does one set the css class for a particular node when a treeview is loaded via Ajax?

Thanks,

5 Answers, 1 is accepted

Sort by
0
Hristo Germanov
Telerik team
answered on 02 Jun 2011, 09:14 AM
Hello Claudiu,

Thank you for contacting us.

Could you try this code snippet:

<%= Html.Telerik().TreeView()
      .Name("TreeView")
      .Items(item =>
      {
          item.Add()
             ...
             .HtmlAttributes(new { @class="test" })
             .Items(subItem =>
             {
                 subItem.Add()
                      ...
                      .HtmlAttributes(new { @class="test1" });
             });
      })
    %>

For more information you can examine our online demo for the TreeView component.

Kind regards,
Hristo Germanov
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
cp
Top achievements
Rank 1
answered on 02 Jun 2011, 02:47 PM
But how would I do it when using client side binding?

http://demos.telerik.com/aspnet-mvc/razor/treeview/clientsidebinding

Thanks,
0
Dimo
Telerik team
answered on 03 Jun 2011, 09:30 AM
Hi Claudiu,

You can use the OnDataBound client event:

http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-treeview-client-api-and-events.html#OnDataBound

It is raised when all new items have been populated, so in order to find the desired node, you should use some DOM operations (e.g. find a node by its content or hierarchy position in the DOM tree).

Best wishes,
Dimo
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
cp
Top achievements
Rank 1
answered on 08 Jun 2011, 09:33 PM
I'm not trying to find nodes, as I stated in my first post I'd like to set a css class on specific nodes at bind time.

Thanks,
0
Dimo
Telerik team
answered on 09 Jun 2011, 07:16 AM
Hi Claudiu,

Since there is no event fired when each node is databound, you have to use the OnDataBound event, which is fired after all nodes have been populated. And at that time you will have to determine by some criteria which specific nodes need the custom CSS class.

All the best,
Dimo
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
Tags
TreeView
Asked by
cp
Top achievements
Rank 1
Answers by
Hristo Germanov
Telerik team
cp
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or