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

Using the GridClientSelectColumn

4 Answers 1690 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 20 Oct 2010, 12:59 PM
Here's a thing.

I have a grid on which I display a GridClientSelectColumn.

In my ItemDataBound event handler, I do some testing to see if the user actually has the rights to carry out the operation they are proposing on each row, and if they don't I disable the checkbox.

All good so far.

Prompted my a customer request I added the "Select All" option.

Now if the user checks the checkbox in the header of the GridClientSelectColumn, the rows where the checkbox is disabled don't  - as you would expect - have the checkboxes checked but the grid STILL SELECTS THE COLUMN.

Now surely that can't be right!

-- 
Stuart

4 Answers, 1 is accepted

Sort by
0
Stuart Hemming
Top achievements
Rank 2
answered on 20 Oct 2010, 01:10 PM
Not only is the row selected (ie highlighted) but the checkbox, although not visibly updated is, in fact checked as I was able to determine using this code...
foreach (GridDataItem i in RadGrid1.MasterTableView.Items)
                {
                    CheckBox chk = (CheckBox)i["RowSelect"].Controls[0];

Now that has to be a bug, no?

-- 
Stuart
0
Martin
Telerik team
answered on 25 Oct 2010, 04:22 PM
Hello Stuart,

The reported behavior is expected because disabling the client select check box of an item does not disable its selection. It is only the check box that can not be checked, however the item can still be selected or deselected. Since the header check box of the client select column toggles the selection status of all items, this check box should retain its functionality even for items that have disabled check boxes. Additionally on my side, checking / unchecking the header check box, checks / unchecks all check boxes, nevertheless of their state (enabled or not). I think that this is correct as well, because the GridclientSelectColumn should be in sync with the selected state of the grid items.

Here is the code I have used:

Markup:

<telerik:RadGrid ID="RadGrid1" AllowMultiRowSelection="true" runat="server"
    OnItemDataBound="RadGrid1_ItemDataBound"
    onneeddatasource="RadGrid1_NeedDataSource">
    <MasterTableView>
        <Columns>
            <telerik:GridClientSelectColumn UniqueName="MyClientSelectColumn">
            </telerik:GridClientSelectColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Selecting AllowRowSelect="true" />
    </ClientSettings>
</telerik:RadGrid>

Code behind:

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem && (e.Item.ItemIndex % 2 == 0))
    {
        ((e.Item as GridDataItem)["MyClientSelectColumn"].Controls[0] as CheckBox).Enabled = false;
    }
}
 
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    DataTable table = new DataTable();
    table.Columns.Add("Col1", typeof(int));
    table.Columns.Add("Col2");
    for (int i = 0; i < 10; i++)
    {
        table.Rows.Add(i, "Col2 Row" + i);
    }
    RadGrid1.DataSource = table;
}

Let me know if I miss something.

Regards,
Martin
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
Stuart Hemming
Top achievements
Rank 2
answered on 25 Oct 2010, 04:46 PM
Martin, 

you've not missed anything at all, in fact you have completely restated the explanation I gave in my post.

However, I would argue that that point of the GridClientSelectColumn is to provide a visible device for selecting a row. You might even argue that it should at least be optional for the developer to determine whether or not the user should be allowed to select a row by clicking on it if s/he has opted to include the GridClientSelectColumn on the grid.

I believe that the developer would expect the state of the controls to remain unchanged if the control was disabled (which it does visually if not logically here).

There is a work around for this erroneous behaviour, fortunately, and it is to handle the client-side event OnRowSelecting and call
e.set_cancel(true)
where the GridClientSelectColumn's checkbox is disabled or, as I did, you can test a value in the ClientDataKeys collection...
e.set_cancel((e.getDataKeyValue("SecurityLevel") != "Full"));

-- 
Stuart

0
Martin
Telerik team
answered on 28 Oct 2010, 04:11 PM
Hello Stuart,

Thank you for sharing your opinion with us. I have contacted our developers concerning your request and was assured that we do not plan to change the current logic of the GridClientSelectColumn. In addition to the workaround that you have already provided, this code library project demonstrates another approach to the same functionality.

I hope this helps.

Regards,
Martin
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
Grid
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Stuart Hemming
Top achievements
Rank 2
Martin
Telerik team
Share this question
or