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

Accessing Grid Rows on Client Side

2 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff Grol
Top achievements
Rank 1
Jeff Grol asked on 06 Apr 2010, 10:27 PM
I'm just trying to loop through the grid rows, evaluate a template column checkbox, and return a Key column value in javascript.  I can't seem to be able to get it to work.  Any help would be greatly appreciated.

2 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 07 Apr 2010, 07:26 AM
Hello Jeff,

You can use GridTableView get_items() to get all RadGrid rows on client. To get the cell for specific item you can use getCellByColumnUniqueName and to get reference to client data key values(that are declared in ClientDataKeyNames of GridTableView) you can use getDataKeyValue().

Kind regards,
Nikolay
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
Princy
Top achievements
Rank 2
answered on 07 Apr 2010, 08:06 AM
Hello,

Here is the client side code that I tried, to get the datakeyvalues of rows which the checkbox checked.

aspx:
 
<telerik:GridTemplateColumn>  
    <ItemTemplate>  
        <asp:CheckBox ID="CheckBox1" runat="server" />  
    </ItemTemplate>  
</telerik:GridTemplateColumn>  

javascript:
 
<script type="text/javascript">  
 function getKeys() {  
        var grid = $find("<%= RadGrid1.ClientID %>");  
        var masterTableview = grid.get_masterTableView();  
        var dataitems = masterTableview.get_dataItems();  
        var i = 0;  
        for (i = 0; i < dataitems.length; i++) {  
            var checkbox = dataitems[i].findElement("CheckBox1");  
            if (checkbox.checked) {  
                alert(dataitems[i].getDataKeyValue('ID')); // Set the ClientDataKeyNames as 'ID' 
            }  
        }  
    }         
</script>   

Hope this helps,
Princy.
Tags
Grid
Asked by
Jeff Grol
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Princy
Top achievements
Rank 2
Share this question
or