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

Grid selection does not work when the ID starts with an underscore (_)

1 Answer 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mjones
Top achievements
Rank 1
mjones asked on 25 Aug 2008, 02:00 PM
When you have a grid that has an ID that starts with an underscore (_), the selection does not work. 

The problem is that the javascript code in GridSelection.js does not handle the case where a grid is contained by a runat="server" control AND it's ID begins with an underscore.  In this case, the generated ID has two underscores next to each other in the generated client id.  And throughout GridSelection.js, there are lines such as:

if( el.id.split("__").length == 2 )


When your grid is contained by another runat=server control, the generated client id could be something like this:
ct100_container__grid__0, in which case the length of el.id.split("__") is 3, not two, so the client side selection code breaks.  It is important to note that a leading underscore is a perfectly valid control ID, which has the side effect of breaking the client side selection.

According to this thread, the problem will be fixed in the next update.  According to the bug report with ID 157577, the problem is too hard to fix, and Telerik may consider adding a note to the documentation to help you avoid the problem.

So, whether the forum or the bug report is correct, you might want to avoid using variables that start with a leading underscore, as it took me two days to find the problem and create a sample application.

Thanks,

Matt

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 26 Aug 2008, 02:47 PM
Hi mjones,

Thank you for notifying our community of this issue. It has been discussed in a number of posts, as this continues to be a limitation in our RadControls. We, the Telerik team, apologize for any inconveniences this might have caused you. I want to note that this issue is of high priority for future fixing, but is not a trivial one, as our entire client functionality depends on underscore positions.

For now, as a workaround for the client selecting, you need to further parse your args.get_itemIndexHierarchical() value in the RowSelecting/RowDeselecting and RowSelected/RowDeselected client events. When an underscore has been used as the beginning character in a control name, this property does not contain only the item index, but also part of the client row ID preceding it. In this case, you need to parse it further by an underscore, and take the last element in the output array of values:

function RowSelected(sender, args) 
    var values = Array 
    values = args.get_itemIndexHierarchical().split('_'); 
    var itemIndex = values[values.length-1]; 

Now itemIndex contains the actual hierarchical index of the current selected item.

Greetings,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
mjones
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or