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

get_dataItem() is null in OnRowSelecting()

4 Answers 204 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 13 Feb 2009, 05:50 PM
We need a grid in which the user can drag rows to reorder them, except for the first few rows, which must remain fixed.

I thought I'd figured out how to do this in OnRowSelecting, as described in this thread: http://www.telerik.com/community/forums/aspnet-ajax/grid/undraggable-rows.aspx

Unfortunately, that depends upon out setting Enabled=false in OnItemDataBound().  If the row is disabled, it can't be edited, and we need these rows to be editable, even if they can't be reordered.

I had thought that if I added a boolean column "isFixed" to the datasource, or a hidden GridBoundColumn to the grid, I'd be able to access one or the other in OnRowSelecting.
function onRowSelecting(sender, args) { 
   var item = args.get_gridDataItem(); 
   var element = item.get_element(); 
   var dataItem = item.get_dataItem(); 
}

Unfortunately, element does not contain the hidden GridBoundColumn, so I can't access it.  And get_dataItem() returns null.

Looking through your examples, the only ones that show get get_dataItem() being called are in OnRowDataBound().

Is there some way to access the underlying row data in OnRowSelecting()?


4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Feb 2009, 06:03 AM
Hi Jeff,

Give a try with the following code snippet to get the cell value in the OnRowSelecting client event.

CS:
<script type="text/javascript" > 
 function OnRowSelecting(sender, eventArgs) 
 { 
   var grid = sender; 
   var MasterTable = grid.get_masterTableView(); 
   var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; 
   var cell = MasterTable.getCellByColumnUniqueName(row, "ProductID"); 
   //here cell.innerHTML holds the value of the cell 
   alert(cell.innerHTML
 } 
</script> 


Regards
Shinu



0
Jeff
Top achievements
Rank 1
answered on 16 Feb 2009, 07:07 PM
MasterTable.getCellByColumnUniqueName() returns null, when the column is not visible.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 Feb 2009, 04:04 AM
Hi Jeff,

Try hiding the column using the Display property instead of Visible property and see whether you are able to get the cell value of the hidden column on the client side.

Thanks
Shinu
0
Jeff
Top achievements
Rank 1
answered on 17 Feb 2009, 03:42 PM
That works, thanks.
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jeff
Top achievements
Rank 1
Share this question
or