The documentation says there is a get_selected() boolean for a GridDataItem. I tried to use this and it tells me "Object doesn't support property or method". I'm using the OnRowClick event of the grid:
function RowClick(sender,item){
alert("click:" + item.getitemIndexHierarchical());
if(item.get_selected()){
alert("selected");
//do something
}
}
The first alert shows but then the error occurs and the 2nd one is never shown. I took the if statement out and I still didn't get the 2nd alert so I know it's that call to get_selected() that is the problem.
How do I use that function?
function RowClick(sender,item){
alert("click:" + item.getitemIndexHierarchical());
if(item.get_selected()){
alert("selected");
//do something
}
}
The first alert shows but then the error occurs and the 2nd one is never shown. I took the if statement out and I still didn't get the 2nd alert so I know it's that call to get_selected() that is the problem.
How do I use that function?
9 Answers, 1 is accepted
0
HorseFly
Top achievements
Rank 1
answered on 11 Mar 2008, 03:48 AM
Also, in my attempt to workaround the get_selected() not working, I found another issue.
var row = grid.get_masterTableView().get_selectedItems()[0];
alert(row.get_itemIndexHierarchical());
//grid.get_masterTableView().get_selectedItems().length=1
It gives me the same Object doesn't support Method or Property error for get_itemIndexHierarchical(). Note row.get_id() returns grid.clientID__row index which seems like a valid GridDataItem client side id. So I'm not sure what is going on.
I used eventArgs.get_itemIndexHierarchical in my OnRowClick event and it worked fine. So it seems to have something to do with getting the GridDataItem via the get_selectedItems() array.
I can't figure it out.
var row = grid.get_masterTableView().get_selectedItems()[0];
alert(row.get_itemIndexHierarchical());
//grid.get_masterTableView().get_selectedItems().length=1
It gives me the same Object doesn't support Method or Property error for get_itemIndexHierarchical(). Note row.get_id() returns grid.clientID__row index which seems like a valid GridDataItem client side id. So I'm not sure what is going on.
I used eventArgs.get_itemIndexHierarchical in my OnRowClick event and it worked fine. So it seems to have something to do with getting the GridDataItem via the get_selectedItems() array.
I can't figure it out.
0
Hi HorseFly,
The second argument passed to each client event handler of RadGrid Prometheus is eventArgs:
http://www.telerik.com/help/radcontrols/prometheus/?grdMigrationToPrometheus.html (see the last paragraph of the topic)
Hence you code should be modified as follows:
Regarding the issue with the length of the get_selectedItems() array:
Can you please verify that you are using the latest release Q3 2007 SP2 of RadGrid Prometheus (2007.3.14.25)? We have similar problem reported before which should be addressed in the latest version.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
The second argument passed to each client event handler of RadGrid Prometheus is eventArgs:
http://www.telerik.com/help/radcontrols/prometheus/?grdMigrationToPrometheus.html (see the last paragraph of the topic)
Hence you code should be modified as follows:
| function RowClick(sender,eventArgs){ |
| alert("click:" + eventArgs.get_itemIndexHierarchical()); |
| if(eventArgs.get_gridDataItem().get_selected()){ |
| alert("selected"); |
| //do something |
| } |
| } |
Regarding the issue with the length of the get_selectedItems() array:
Can you please verify that you are using the latest release Q3 2007 SP2 of RadGrid Prometheus (2007.3.14.25)? We have similar problem reported before which should be addressed in the latest version.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
HorseFly
Top achievements
Rank 1
answered on 11 Mar 2008, 02:32 PM
When I change it as suggested I get the error: 'get_gridDataItem()' is null or not an object
0
Hello HorseFly,
Can you check whether accessing the get_dataItems() collection prior to the reference to the get_gridDataItem() property makes a difference? You may also try intercepting the OnRowCreated client event of the grid (providing an empty handler). In some cases due to performance reasons the data items are serialized client-side only after you perform one of the suggested actions.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Can you check whether accessing the get_dataItems() collection prior to the reference to the get_gridDataItem() property makes a difference? You may also try intercepting the OnRowCreated client event of the grid (providing an empty handler). In some cases due to performance reasons the data items are serialized client-side only after you perform one of the suggested actions.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
HorseFly
Top achievements
Rank 1
answered on 11 Mar 2008, 05:40 PM
Accessing get_dataItems() beforehand didn't fix the error. However, I was able to do this:
var tbl = grid.get_masterTableView();
var row=tbl.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
if(row.get_selected())
{
...
}
var tbl = grid.get_masterTableView();
var row=tbl.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
if(row.get_selected())
{
...
}
0
HorseFly
Top achievements
Rank 1
answered on 11 Mar 2008, 06:24 PM
...but, even though I managed to get rid of the error, get_selected() is always returning false for me :P
Back to the drawing board.
Back to the drawing board.
0
Hello HorseFly,
I am not sure whether I follow your idea correctly. I assume that you select several records in the grid and then click another record - is this correct? Note that in this case the previously selected items on the client will be deselected:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Client/Selecting/DefaultCS.aspx
and this is the expected behavior. If you want to keep the selected rows and traverse them on subsequent row click, consider using server selection and couple it with Ajax to simulate client-side performance:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/SelectRowWithCheckBox/DefaultCS.aspx
Let me know if I am leaving something from your logic out.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I am not sure whether I follow your idea correctly. I assume that you select several records in the grid and then click another record - is this correct? Note that in this case the previously selected items on the client will be deselected:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Client/Selecting/DefaultCS.aspx
and this is the expected behavior. If you want to keep the selected rows and traverse them on subsequent row click, consider using server selection and couple it with Ajax to simulate client-side performance:
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/Programming/SelectRowWithCheckBox/DefaultCS.aspx
Let me know if I am leaving something from your logic out.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
HorseFly
Top achievements
Rank 1
answered on 12 Mar 2008, 02:38 PM
I was trying to work around grid functionality that doesn't work right for us. If you turn off multi-row selection, once the user selects a row in the grid, they can't unselect it without selecting another row. Clicking the checkbox off works for multi-row selection only. This is a problem in our application so I was trying to write script to make the selected row unselect on click. In the old grid, I had this working via the RowSelecting and RowClick events. When I upgraded it all broke. I managed to get it all upgraded yesterday, but then the logic wouldn't work for the new grid. I guess the events fire in a different order or something.
Anyway, I figured out that on the new grid I only need the RowSelecting event to accomplish this. I was able to to get it all working by setting AllowMulitRowSelection=true and doing this on RowSelecting:
Anyway, I figured out that on the new grid I only need the RowSelecting event to accomplish this. I was able to to get it all working by setting AllowMulitRowSelection=true and doing this on RowSelecting:
function
RowSelecting(sender,eventArgs){
var grid=$find(grdcid);
var tbl=grid.get_masterTableView();
tbl.clearSelectedItems();
return true;
}
This is an acceptable solution for us, but for future reference you might consider changing the single-row selection grid to allow you to clear your selection like the multi-row selection grid does.
0
Hello HorseFly,
Thank you for the detailed explanation - now I see your point more clearly.
We may consider changing the single selection behavior the way you specified, however you will probably agree with me that this change should cover a wide variety of scenarios related to client selection and a stable/unique solution may not be possible. Nevertheless I will pass your proposal to our developers for further consideration.
I am glad that the solution you implemented suits your needs. Your Telerik points have been updated for sharing it with the rest of the Telerik community members.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thank you for the detailed explanation - now I see your point more clearly.
We may consider changing the single selection behavior the way you specified, however you will probably agree with me that this change should cover a wide variety of scenarios related to client selection and a stable/unique solution may not be possible. Nevertheless I will pass your proposal to our developers for further consideration.
I am glad that the solution you implemented suits your needs. Your Telerik points have been updated for sharing it with the rest of the Telerik community members.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center