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

Feature Request: Allow Only Some Nodes To Have Checkboxes

9 Answers 71 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.
Kevin Watkins
Top achievements
Rank 1
Kevin Watkins asked on 11 Apr 2010, 05:37 PM
Hi,

In my tree with checkboxes I only need to have checkboxes for some of the nodes. I'm currently hiding the checkboxes using CSS as a workaround, however this means there is a load of unnecessary markup in the page for the checkboxes. It would be great if there was an option to enable checkboxes per item (maybe a Checkable property on TreeViewItem) that I could use to stop checkboxes being rendered for certain nodes.

Cheers,

Kev

9 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 12 Apr 2010, 07:43 AM
Hello Kevin,

Can you please describe your scenario a little bit more? Is it that only leaf nodes can be checked, or is it arbitrary nodes? In my opinion, the nodes will seem misaligned if sibling nodes have different values for the Checkable property, so it would be best if we see a bit of the application of the property before implementing it.

Regards,
Alex Gyoshev
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
Kevin Watkins
Top achievements
Rank 1
answered on 12 Apr 2010, 10:45 AM
Hi,

In my particular case I need the leaf nodes and the leave's parents checkable, the rest not. (For reasons I won't bore you with!)

I've implemented the checkboxes myself now; I've patched the tree to allow arbitrary HTML in the node names (discussed in another forum post) so I'm rendering my own checkboxes. This was partly to reduce the size of the markup (I can just render the checkboxes I need) and partly because I couldn't extract the POST values; the method shown in your demos of just binding to a List<TreeViewItem>s doesn't work correctly. I have two trees on my page which causes problems, presumably because the Telerik trees have the same names for the checkboxes and hidden inputs. (e.g. both trees have a checkedNodes[0].Checked) Now I'm rendering the checkboxes myself I can give them meaningful names which makes parsing the POSTed form nice and easy.

Thanks,

Kev
0
Alex Gyoshev
Telerik team
answered on 14 Apr 2010, 04:05 PM
Hello Kevin,

Magnificent feedback! The checked property is ready and will be available with SP1. Regarding the naming of the checkboxes, I think it would be nice if we introduce a field for that - what do you think?

Your Telerik points have been updated.

Kind regards,
Alex Gyoshev
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
Kevin Watkins
Top achievements
Rank 1
answered on 14 Apr 2010, 04:37 PM
Hi,

Do you really need an extra field given we already have Value? Kind of makes sense to use Value for the name of the checkbox as Value represents the ID of the node. (At least in my code!) Some people might to use something else I guess so maybe a CheckboxName property would be handy.

Guess you could have a CheckboxNameMode enumeration with values of Default, (as it currently is) Value (use Value) and Custom to specify how to setup the names. (Uses CheckboxName) Although that probably over complicates things.

My vote is just use Value, but you should probably ask some of your other users too. 8o)

Cheers,

Kev
0
Alex Gyoshev
Telerik team
answered on 19 Apr 2010, 09:12 AM
Hello Kevin,

Our idea behind the TreeView checkboxes is that they will be submitted as a list of TreeViewItemModel, like in the checkbox support example. As far as I understand, the checkbox names will clash when there are two or more TreeViews with checkboxes on the page - namely, there will be two checkedNodes arrays. My idea was to expose a property for the array name - so that you can specify different ones for each TreeView with checkboxes. Is this making sense? How do you use only the checkbox value in your code?

Greetings,
Alex Gyoshev
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
Kevin Watkins
Top achievements
Rank 1
answered on 19 Apr 2010, 11:23 AM
Hi,

I've gotten around the problem by ignoring your stuff for checkboxes and putting the HTML in myself. (I've patched my version to write HTML out instead of text as discussed somewhere else) I then manually bind on the server.

I have a couple of issues with the current Telerik approach:

  • The format for the checkboxes seems to be a specifier describing the index of the sibling in each branch, e.g. [0:1] represents the second child of the first node. Which seems like a fragile approach to me; what if the tree has changed (as it is could well do in my case) between the initial rendering of the page and the postback? You could easily end up doing something with the wrong node.
  • Seems to be some hidden fields rendered too - not sure why? Is it to work correctly with ASP.NET MVC model binding? Does this prevent the problems mentioned in the point above?
  • Seems to be some JavaScript that has to keep various values in sync, including the hidden fields. Again this seems fragile; I've already broken it by changing the checked states via JavaScript.

Personally I would like to see the tree changed so that the user has to specify some sort of unique identifier for the checkbox name. I imagine most people would probably have this anyway, especially if rendering dynamic trees. Then simple checkboxes are rendered with that identifier (maybe escape it) for the name. The markup is similar and there is no need for JavaScript. Plus it's trivial to prefix the nodes with the name of the tree to stop multiple tree problems.

Downside is it makes model binding a bit trickier. You don't have all the data you need to build a tree of TreeViewItemModels for the postback. Is that a really problem though? The user is most likely going to have to build their tree again anyways, especially given that the tree seems to be built with TreeViewItem instances yet post back stuff is TreeViewItemModel instances. Do they need a tree structure on the post back or just a list of IDs that have been checked? I just need the list of IDs, which is trivial to extract from the form. (You could provide extension methods to do this)

Cheers,

Kev

0
Alex Gyoshev
Telerik team
answered on 20 Apr 2010, 09:37 AM
Hello Kevin,

Indeed, the out-of-the-box approach is fragile for dynamic trees -- we used it in order to conform with the ASP.NET MVC checkbox binding (if you use the Html.Checkbox helper, you can see that it too renders an additional hidden field; this is a tad hacky - and the reasoning behind it is debated upon in this forum post). With the Encoded property, however, you could render the checkboxes by yourself, and they should behave in a way, similar to what you describe. Isn't that a viable option? Or does our model seem broken?

Regards,
Alex Gyoshev
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
Kevin Watkins
Top achievements
Rank 1
answered on 20 Apr 2010, 10:38 AM
Hi,

As I said that's exactly what I'm doing as your approach is too flakey with dynamic trees that might change and doesn't work full stop with multiple trees on the page.

Cheers,

Kev
0
Alex Gyoshev
Telerik team
answered on 27 Apr 2010, 08:58 AM
Hello Kevin,

The problem with multiple trees with checkboxes on the page has been fixed by prefixing all arrays with the treeview name. Since this is a breaking change, it will be available with the 2010.Q2 release.

As for the dynamic treeviews, the approach with templates is recommended.

All the best,
Alex Gyoshev
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
Kevin Watkins
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Kevin Watkins
Top achievements
Rank 1
Share this question
or