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

Disabaling rows in the RadGrid + selection

8 Answers 408 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Maria
Top achievements
Rank 1
Maria asked on 18 May 2009, 12:53 PM
Hello,

I have a RadGrid on my page with AllowMultiRowSelection="true" and clientSelectColumn.
In the itemDataBound evennt I perform some check on the binded item and sometimes disable the row:
e.Item.Enabled = false;    

While this line disables the checkbox, the row can still be checked when clicking on it.
Moreover, when clicking on the check all check box in header all the checkboxes become checked, even the disabled ones.

Is that a bug?




This is the grid declaration:
<telerik:RadGrid ID="gridReviews" runat="server"
            AutoGenerateColumns="false" AllowMultiRowSelection="true"
            onitemdatabound="gridReviews_ItemDataBound"  >            
            <HeaderContextMenu>
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
            </HeaderContextMenu>
            <ItemStyle Wrap="False" />
            <MasterTableView DataKeyNames="Value.Id">                
                <Columns>                    
                    <telerik:GridClientSelectColumn UniqueName="ReviewSelectCol">                        
                    </telerik:GridClientSelectColumn>
               .....
               .....


                </Columns>
            </MasterTableView>
            
            <ClientSettings >
                        <Selecting AllowRowSelect="True" />
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                        <Resizing AllowColumnResize="True" EnableRealTimeResize="True" />
            </ClientSettings>

        </telerik:RadGrid>

Thanks,
Maria.

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 May 2009, 05:53 AM
Hello Maria,

I tried your scenario at my end and I was not able to click on the disabled checkboxes but on clicking on a row or on the select all header checkbox, all the checkboxes including the ones that were disabled are checked. This is because even if the checkbox is disabled it is still possible to change its status on the client.
The following code library provides a solution to this issue wherein selection is canceled for each row where the checkbox is disabled by making use of the OnRowSelecting client event.
GridClientSelectColumn - select all rows with enabled check boxes only

Thanks
Princy.
0
Maria
Top achievements
Rank 1
answered on 19 May 2009, 08:41 AM
Thanks for the answer.

I tried to apply it but it doesn't seem to work.
First of all the JS code didn't return the false for disabled rows,
so I changed the index to 1 and then it returned false:
rowObject.Control.getElementsByTagName("input")[1];
Even though the function returns 0 the row is selected.
I'm using RAD controls version 2009_1_402.

Thank you.
0
Teguh
Top achievements
Rank 1
answered on 27 May 2009, 08:36 AM
Hi,
I also have a similar problem.
The disabled GridRow can be selected and raised the OnSelectedIndexChanged event.
This behavior was not occurred in the old telerik control.

Basically what I need is to raise the OnSelectedInxedChanged  only in certain condition.

How can I do this? Please advice.

Thanks
0
Sebastian
Telerik team
answered on 27 May 2009, 10:34 AM
Hello guys,

How to disable the grid along with the other controls/links in it client/server side you can find out from this topic in the online documentation:
http://www.telerik.com/help/aspnet-ajax/grdenabledconventions.html

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Teguh
Top achievements
Rank 1
answered on 28 May 2009, 03:05 AM
Hi Sebastian,

Thank you for the response, unfortunately it doesn't answer my need.

What I need is only certain row that disabled.
I've managed to do this by set the Enable property of the e.Item to false in the ItemDataBound event.
Here's the code sniped:

protected void MyGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (someCondition)
    {
          e.Item.Enabled = false;
    }
}

The corresponding rows is successfully disabled (it's layout is grayed) however while user click the disabled rows, the row is selected and the SelectedIndexChanged server event is triggered. And this is not the expected behavior.

Is there any work arround to do this?
Please kindly advice.

Regards,
Teguh
0
Sebastian
Telerik team
answered on 28 May 2009, 12:20 PM
Hi Teguh,

You may consider intercepting the OnRowSelecting client event of the grid and determine whether the grid row (tr element of the grid html table) is disabled. This can be done checking the eventArgs.get_gridDataItem().get_element().disabled value (where eventArgs.get_gridDataItem().get_element() points to DOM element of the grid item inside the OnRowSelecting handler).

If the returned value is 'disabled', merely invoke eventArgs.set_cancel(true) which will cancel the select operation and will stop the SelectedIndexChanged event raising.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Teguh
Top achievements
Rank 1
answered on 29 May 2009, 04:02 AM
Hi Sebastian,

Thanks for the workaround that you suggested.
However the get_gridDataItem() always returns null value.
I looked at the documentation, and found out this notes

note

get_gridDataItem() is not directly available on the client unless OnRowCreating/OnRowCreated events are hooked up. This is done for optimization purpose. If you need the rowIndex, you can use eventArgs.get_itemIndexHierarchical()


In chase somebody having a same issue, I used eventArgs.get_domEvent().target.isDisabled to check whether the object is disabled or not.

Thanks,
Teguh



0
Vlad
Top achievements
Rank 1
answered on 06 Jan 2013, 09:21 AM
This didn't work for me either, however I was able to look up the disabled status through the row's checkbox as follows:

function grdFiles_OnRowSelecting(sender, eventArgs)
{
    var b = eventArgs.get_gridDataItem().get_element(); // <tr> element
    var chkbox = b.firstElementChild.fistElementChild;  // checkbox element of the row
    if (chkbox.disabled)
        eventArgs.set_cancel(true);
}

Hope it helps,
Vlad.
Tags
Grid
Asked by
Maria
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Maria
Top achievements
Rank 1
Teguh
Top achievements
Rank 1
Sebastian
Telerik team
Vlad
Top achievements
Rank 1
Share this question
or