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

Hierarchical GridTableView RowClick getDataKeyValue

4 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mabs
Top achievements
Rank 1
mabs asked on 03 May 2012, 10:42 AM
I am creating a Hierarchical grid programmatically by using a radgrid with a GridTableView.  This is generated fine without issue.  What I would like to do is have a row click on the gridtableview rows as well as the mastertable rows.  So when I click the expand icon on the main grid, the sub rows will fire the same rowclick.  Which does happen, howeveer I can not seem to get hold of the datakeyvalue of the gridtableview.  For example, my javascript rowclick,
function RowClick(sender, eventArgs) {
    eval(eventArgs.getDataKeyValue("ROWCLICK"));
}
RowClick fires fine, but the getDataKeyValue is always null for the sub rows (which i believe is the gridtableview).  Any help with this would be much appreciated.

I have a similar issue with the contextmenu, but I guess it would be related to getting the datakeyvalue for the gridtableview.

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 May 2012, 11:20 AM
Hello,

Try the following javascript to access datakeyvalue.
JS:
<script type="text/javascript">
function OnRowClick(sender, args)
{
  var MasterTable = sender.get_masterTableView();
  var row = MasterTable.get_dataItems()[0];
  var detailTable = row.get_nestedViews()[0];
  alert(detailTable.get_dataItems()[0].getDataKeyValue("ID"));
 }
</script>

Thanks,
Shinu.
0
mabs
Top achievements
Rank 1
answered on 03 May 2012, 11:32 AM
Thank you for the quick reply.

detailTable comes back as undefined.  I have included some of the code used to create the grid.

Dim RadGrid1 As RadGrid = New RadGrid
 RadGrid1.HeaderContextMenu.EnableEmbeddedSkins = False
 RadGrid1.ID = "RadGrid1"
 RadGrid1.ClientSettings.ClientEvents.OnRowClick = "RowClick"
 ....
'set the datakeynames, create the columns for the RadGrid1
 ....
 
 Dim hierarchyTable As New GridTableView(RadGrid1)
 
 ....
'set the datakeynames, create the columns for the hierarchyTable
 ....
 
 Dim relationFields As GridRelationFields = New GridRelationFields()
 relationFields.MasterKeyField = MasterKeyField
 relationFields.DetailKeyField = DetailKeyField
 hierarchyTable.ParentTableRelation.Add(relationFields)
 RadGrid1.MasterTableView.DetailTables.Add(hierarchyTable)

I have chopped the code a bit just to reduce the size and make it easier to read, but basically once created this then gets added to a place holder.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 04 May 2012, 05:24 AM
Hi,

Try setting the ClientDataKeyNames to get the datakeyvalue on row click.

VB:
Dim RadGrid1 As RadGrid = New RadGrid
RadGrid1.HeaderContextMenu.EnableEmbeddedSkins = False
RadGrid1.ID = "RadGrid1"
RadGrid1.MasterTableView.DataKeyNames = New String() {"CustomerID"}    'set the datakeynames
RadGrid1.MasterTableView.ClientDataKeyNames = New String() {"CustomerID"}   'set the ClientDataKeyNames
RadGrid1.ClientSettings.ClientEvents.OnRowClick = "RowClick"
 
...
 
' create the columns for the RadGrid1
....
 
 
Dim tableViewOrders As New GridTableView(RadGrid1)
 
...
...
hierarchyTable.DataKeyNames = New String() {"OrderID"'set the datakeynames
hierarchyTable.ClientDataKeyNames = New String() {"OrderID"}   'set the ClientDataKeyNames
 
...
 
'create the columns for the hierarchyTable
...
 
 
Dim relationFields As GridRelationFields = New GridRelationFields()
relationFields.MasterKeyField = MasterKeyField
relationFields.DetailKeyField = DetailKeyField
hierarchyTable.ParentTableRelation.Add(relationFields)
RadGrid1.MasterTableView.DetailTables.Add(hierarchyTable)

Thanks,
Shinu.
0
mabs
Top achievements
Rank 1
answered on 04 May 2012, 05:01 PM
Thanks for the reply, I had missed the
hierarchyTable.ClientDataKeyNames = "my keys"
with this set all is now good.  The original javascript call now works.

Tags
Grid
Asked by
mabs
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
mabs
Top achievements
Rank 1
Share this question
or