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

[Solved] Need Cell Click event in RadGrid

4 Answers 639 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Medac
Top achievements
Rank 1
Medac asked on 09 Jul 2009, 10:59 AM
Hi,

In radgrid to allow row selection we are adding following lines of code in the grid

<

 

ClientSettings>

 

 

<Selecting AllowRowSelect="True"></Selecting>

 

 

<ClientEvents OnRowDblClick ="RowSelectedCarrierName" ></ClientEvents>

 

 

</ClientSettings>

 


I want implement this event on cell click. for each cell click in a grid I want call a script and want access the value of selected cell.
How can I do this?

Thanks in advance,
Medac

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Jul 2009, 12:21 PM
Hi Medac,

Try the following code to access the clicked cell value from client side by attaching OnRowClick client-side event to grid.

JavaScript:
 
<script type="text/javascript"
function OnRowClick(sender, args) 
    var targetCell = args.get_domEvent().target;  
    var index = args.get_itemIndexHierarchical(); // index 
    var value = targetCell.innerHTML// Clicked value 
    alert(index);     
    alert(value);  
</script> 

-Shinu.
0
Daniel
Telerik team
answered on 09 Jul 2009, 12:21 PM
Hello Medac,

Please examine the following code:
<script type="text/javascript">  
  
    function getHeaderRow(sender)  
    {  
        var masterTable = sender.get_masterTableView();  
        return masterTable.HeaderRow == null ? sender.get_masterTableViewHeader().get_element() : masterTable.HeaderRow;  
    }  
  
    function handleRowClick(sender, args)  
    {  
        var masterTable = sender.get_masterTableView();  
        var cellIndex = args.get_domEvent().target.cellIndex; 
        var cellText = args.get_domEvent().target.innerHTML
        var colName = masterTable.getColumnUniqueNameByCellIndex(getHeaderRow(sender), cellIndex) 
        alert("Unique name: " + colName + "\nText: " + cellText);  
    }  
</script> 

<ClientSettings ClientEvents-OnRowDblClick="handleRowClick"

Hope this helps.

Best regards,
Daniel
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
kernelk
Top achievements
Rank 1
answered on 16 Jul 2013, 01:13 AM

Hi,

Why is cellIndex not a property of the target when right-clicking on the cell text data? If clicked off the cell text it works.


var cellIndex = args.get_domEvent().target.cellIndex;

This would answer part of my other post.

Thanks.
0
Venelin
Telerik team
answered on 18 Jul 2013, 10:30 AM
Hi Medec,

You can achieve the desired functionality by using the following JavaScript:

function onCellSelecting(sender, eventArgs) {
    console.log(eventArgs.row.children('td.rgFocusedCell')[0].innerHTML);
}

and adding in your RadGrid Selecting settings the CellSelectionMode="SingleCell" property.

I hope this helps.

Regards,
Venelin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Medac
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Daniel
Telerik team
kernelk
Top achievements
Rank 1
Venelin
Telerik team
Share this question
or