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

0 selected items OnGridCreated

2 Answers 38 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian McRaven
Top achievements
Rank 1
Brian McRaven asked on 17 Aug 2010, 09:54 PM
When I hit the back button in my browser and return to a page that has a RadGrid with selected items I am getting 0 for the length of get_selectedItems().  The following code is wired to the RadGrid's OnGridCreated ClientEvent.  I can see in the browser that when I return to the page my previously selected items in the RadGrid return to their selected state. 

The necessary code is found below.  Is there a better ClientEvent to subscribe to that will catch the RadGrid after it's selected items have been repopulated?  The code snippet below is also wired to the RowSelected and RowDeselected ClientEvents and it functions properly.  It is just a problem of running this code when my grid items selected state has been established after hitting the back button in my browser.

var grid = $find('<%= gvNodes.ClientID %>');            
var gridSelectedItems = grid.get_selectedItems();

if
 (gridSelectedItems.length == 1) {
// enable a rad tool bar button

else {
// disable a rad tool bar button
}

2 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 20 Aug 2010, 10:26 AM
Hi Brian,

Try calling RadGrid.get_masterTableView().get_dataItems() first to have the GridDataItems' client objects created after the page is loaded.

Greetings,
Veli
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
Brian McRaven
Top achievements
Rank 1
answered on 23 Aug 2010, 04:29 PM
So I am able to get the set of data items from the grid using the code you suggested.  However when I look at this collection I still see that none of the data item's get_selected() functions are returning true when I know that at least one of these data item's is selected.

I know that when the page loads in the browser I can see that there are row(s) that are selected when I go back to the page.  The checkbox for the selected row(s) are showing up checked.  However, when I add a watch and execute the OnGridCreated Client Event there are no rows (data items) that are showing up as selected.  I then went a step further and added a button to this page which would execute this piece of code when clicked:

var
 dataItems = grid.get_masterTableView().get_dataItems();
var isSel = dataItems[1].get_selected();










So I go back to the page using the Back button and click my temporary button. 
I know that the second row is selected when I return to this page but once again, even though the page has completely loaded and that specific row has a check box that is checked, the selected state is showing up as false when I click on the button. 

So as a workaround I do something that is  pretty hacky but it does cause the selected state of the rows to return accurate values in the OnGridCreated Client Event.  There should be a cleaner way to do what I want to get done so I'm open to suggestions.

My workaround is the following piece of jquery code on document ready.....

$(document).ready(function () {
    $('#<%= gvNodes.ClientID %> input:checkbox.checked').checked = true;
});

Tags
Grid
Asked by
Brian McRaven
Top achievements
Rank 1
Answers by
Veli
Telerik team
Brian McRaven
Top achievements
Rank 1
Share this question
or