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

When using GridClientSelectColumn is it possible to prevent some rows being selected on a condition?

6 Answers 177 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 30 May 2008, 06:17 AM
Hi

When using GridClientSelectColumn is it possible to prevent some rows being selected on a condition?

I tried using the grid client event "OnRowSelecting" with the following function:

function grdSearchResult_RowSelecting(sender, e)
{
    // Check if this row should be selected
    if(e.get_gridDataItem().get_element().cells[SELECT_COL].firstChild.disabled == true)

        e.set_cancel(true);
}

In this particular case I'm checking if the row has the selected checkbox disabled or not.

This doesn't work first time (e.get_gridDataItem() is NULL), however 2nd time onwards it works fine.

Am I taking the right approach?


Kind regards

Mark Eaton

6 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 02 Jun 2008, 01:35 PM
Hi Mark,

the logic of the approach is correct - you can cancel out the selection conditionally. The error may be caused by some server side logic, for disabling the checkboxes. Can you provide some additional information, as to how the checkboxes are disabled, or if there is anything that would allow me to replicate this behavior locally.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark
Top achievements
Rank 1
answered on 03 Jun 2008, 12:10 AM
Hi Yavor

I am using the following server side code to disable the checkbox:

protected void grdSearchResult_ItemDataBound(object source, GridItemEventArgs e)
{
    TableCell col = null;
    Image img = null;
    CheckBox chk = null;

    if (e.Item is GridDataItem)
    {
        col = ((Telerik.Web.UI.GridDataItem)(e.Item))["clmSelect"];

        if (col != null)
        {
            // The checkbox is always the 1st control for a Telerik select column
            chk = (CheckBox)col.Controls[0];

            if (chk != null)
                chk.Enabled = false;
        }
    }
}

Hope this helps


Kind regards

Mark Eaton
0
Yavor
Telerik team
answered on 05 Jun 2008, 12:24 PM
Hello Mark,

Attached to this message, is a sample application, which handles the required functionality.
I hope it helps.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Mark
Top achievements
Rank 1
answered on 30 Jul 2008, 04:21 AM
Hi

With the Javascript event from the attached project:

      function rowSelecting(sender, eventArgs)
      {     
        if(sender.get_masterTableView().getCellByColumnUniqueName(sender.get_masterTableView().get_dataItems()[eventArgs.get_itemIndexHierarchical()],"clmSelect" ).childNodes[0].disabled == true)
        eventArgs.set_cancel(true);     
      }


I find this works beautifully in I.E 7 however although the set_cancel(true) is reached in Safari 3 and Firefox 3 they seem to be ignoring it.

I am using Telerik AJAX 2008 Q2.

Is there anything I need to do to make it work for Safari 3 and Firefox 3?


Kind regards

Mark Eaton
0
Accepted
Pavel
Telerik team
answered on 01 Aug 2008, 08:35 AM
Hi Mark,

I have modified the sample to work with all browsers. You can find it attached to this post.

Best wishes,
Pavel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mark
Top achievements
Rank 1
answered on 04 Aug 2008, 11:55 PM
Thanks, works beautifully!


Kind regards

Mark Eaton
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Mark
Top achievements
Rank 1
Pavel
Telerik team
Share this question
or