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

get_dataItem client api call?

6 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Azzi
Top achievements
Rank 2
Brian Azzi asked on 02 Apr 2010, 07:54 PM
Ok... just a very quick (i hope) question. I'm very confused with some of the Client API calls... it seems that they work in some cases and not in others (specifically depending on where the data was bound).

In the case of get_dataItem ... is it right to expect that this work for grids that have had their data bound on the server? I have been using this call with no problems on some grids where I have bound the data on the client... but it always returns null on another grid that I have recently done via server binding. 

Any help would be appreciated... : )

-Brian

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 05 Apr 2010, 08:02 AM

Hello Brian,

The get_gridDataItem() is not directly available on some client events unless OnRowCreating/OnRowCreated events are hooked up. This is done for optimization purpose. Add OnRowCreating/OnRowCreated event and try whether it is working as expected.

aspx:

 
      . . .  
    </MasterTableView>  
    <ClientSettings AllowDragToGroup="true">  
        <ClientEvents OnRowClick="OnRowClick"OnRowSelected="RowSelected"  
            OnRowCreated="OnRowCreated" OnRowCreating="OnRowCreating"/>  
        <Selecting AllowRowSelect="true" />  
    </ClientSettings>  
</telerik:RadGrid> 

javascript:

 
<script type="text/javascript">  
    function OnRowCreated(sender, args) {  
 
    }  
    function OnRowCreating(sender, args) {  
 
    }  
      . . .  
</script> 

-Shinu.

0
Brian Azzi
Top achievements
Rank 2
answered on 08 Apr 2010, 05:33 PM
Well... that didn't seem to work. : (

Here is my grid (where data is bound server side on page load):

<telerik:RadGrid ID="RadGridStatus" 
            Skin="Windows7"  
            EnableViewState="false" 
            Height="290" 
            Width="100%" 
            AllowPaging="false"  
            AllowSorting="true"  
            AutoGenerateColumns="false"    
            AllowMultiRowSelection="false"    
            runat="server"
            <ClientSettings AllowKeyboardNavigation="true">  
                <KeyboardNavigationSettings AllowActiveRowCycle="true" />  
                <Resizing AllowColumnResize="true" />   
                <Scrolling AllowScroll="True" UseStaticHeaders="true" SaveScrollPosition="True" /> 
                <Selecting AllowRowSelect="true" /> 
                <ClientEvents OnCommand="RadGridStatus_Command" 
                    OnRowSelected="RadGridStatus_RowSelected" 
                    OnGridCreated="RadGridStatus_OnGridCreated"  
                    OnRowCreated="OnRowCreated"  
                    OnRowCreating="OnRowCreating" />  
            </ClientSettings>  
            <MasterTableView AllowCustomSorting="false" ClientDataKeyNames="JobID" Width="100%" TableLayout="Fixed" ShowFooter="false" Font-Size="11px"
                <Columns> 
                    <telerik:GridBoundColumn DataField="JobID" UniqueName="JobID" HeaderText="Job ID" HeaderStyle-Width="60" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" /> 
                    <telerik:GridBoundColumn DataField="JobProfile" UniqueName="JobProfile" HeaderText="Job Profile Name" HeaderStyle-Width="200" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" /> 
                    <telerik:GridBoundColumn DataField="Title" UniqueName="Title" HeaderText="Title" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" /> 
                    <telerik:GridBoundColumn DataField="Author" UniqueName="Author" HeaderText="Author" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" /> 
                    <telerik:GridBoundColumn DataField="SubmitTime" UniqueName="SubmitTime" HeaderText="Submit Time" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" /> 
                    <telerik:GridBoundColumn DataField="Priority" UniqueName="Priority" HeaderText="Priority" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" /> 
                    <telerik:GridBoundColumn DataField="Status" UniqueName="Status" HeaderText="Status" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" /> 
                </Columns>  
                <NoRecordsTemplate> 
                    <br /> 
                    <center>No jobs to display.</center> 
                </NoRecordsTemplate>  
            </MasterTableView>  
        </telerik:RadGrid> 

... and my client events (you can see my attempts to get JobID in the row selected event, which never comes back):

//this function is used to process a sorting request from the grid. 
        function RadGridStatus_Command(sender, args) 
        { 
            //cancel any command postbacks & process client side 
            args.set_cancel(true); 
 
            if (args.get_commandName() == "Sort") 
            { 
                //refresh the data 
                //loadUsersFromService(); 
            } 
        } 
 
        function OnRowCreated(sender, args) 
        { 
 
        } 
        function OnRowCreating(sender, args) 
        { 
 
        }   
 
        function RadGridStatus_OnGridCreated(sender, args) 
        { 
            //load the job status 
            //loadJobStatusFromService(); 
        } 
 
        //this event is raised on row selection 
        function RadGridStatus_RowSelected(sender, args) 
        { 
            var rowSel = args.get_item(); 
            //alert(rowSel.get_cell("JobID")); 
            var jobID = parseInt(rowSel.get_dataItem()["JobID"]); 
            //alert(jobID); 
            //$find("<%=RadAjaxManager1.ClientID%>").ajaxRequest("loadTasksAndErrors"); 
        } 


0
Princy
Top achievements
Rank 1
answered on 09 Apr 2010, 07:59 AM
Hi,

Here is the code for accessing the jobID in OnRowSelected event. You can also access the jobID of selected row by using getDataKeyValue() method since you are using jobID as ClientDataKeyName for your RadGrid.

JavaScript:
function RadGrid3_RowSelected(sender, eventArgs) { 
   
    //Access DatakeyValue of selected row 
    var val = eventArgs.getDataKeyValue("jobID"); 
     
    //Access jobID column value from selected row  
    var grid = sender; 
    var MasterTable = grid.get_masterTableView(); 
    var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];   
    var jobID = MasterTable.getCellByColumnUniqueName(row, "jobID").innerHTML

Regards
Princy
0
Brian Azzi
Top achievements
Rank 2
answered on 09 Apr 2010, 07:42 PM
Thanks... getDataKeyValue works quite well (and certainly well enough for my purposes). I still don't quite understand why the normal client API functions are not available in this case though...  I'll give the cell method a try as well if I need any other extended data. Thanks for the helpful replies... much appreciated. :) 
0
Brian Azzi
Top achievements
Rank 2
answered on 14 Apr 2010, 06:29 PM
One more question... I can't seem to get get_dataItem to work at all in the OnRowDataBound client event... is there some issue with doing that there? I subscribe to the needed client events, but it always throws errors when I try to retrieve the grid data item in that event. (The grid has been manually bound with data on the client via client load).

... this is very frustrating. (Note that I did open a support ticket for this, but thought I'd post here as well in case anyone in the community has experienced this behavior).

Thanks!
-Brian
0
Billy Bernard
Top achievements
Rank 1
answered on 16 May 2010, 06:50 PM
This simple line of code will also do the job.
 function RowSelected(sender, eventArgs) { 
   var jobID = eventArgs.get_item().get_cell("jobID").innerHTML 
Tags
Grid
Asked by
Brian Azzi
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 1
Brian Azzi
Top achievements
Rank 2
Princy
Top achievements
Rank 1
Billy Bernard
Top achievements
Rank 1
Share this question
or