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

Fire Client Side Select Event On Server Side

2 Answers 216 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vince Ockerman
Top achievements
Rank 1
Vince Ockerman asked on 30 Jan 2011, 09:20 PM
I have a grid where "OnRowSelected" I fire a javascript function that moves the selection's data to another part of the screen, it works kind of like an old school windows multi-select slide over box. This is working fine, and I have no issues with it.

My problem is that this is all part of a data item that can be saved and edited later. In the event that the user wishes to edit the item later, I need to load in the grid with the data items pre-selected. I know how to do that, and have that part working.

My question is: Is there an easy way to fire my client-side events after I bind the grid and force selection server side, so that the UI will look as if the user clicked the selections (all my javascript gets executed is my main goal here). I'd like to send all the selection code down the same funnel, so that the de-select code all functions properly in the aforementioned scenario.

I am trying to avoid postbacks, ajax or otherwise, as my users' machines are very old, and even nicely setup update panels and ajaxmanagers seem to take forever to execute.

2 Answers, 1 is accepted

Sort by
0
Accepted
Radoslav
Telerik team
answered on 03 Feb 2011, 09:52 AM
Hello Vince,

To achieve the desired functionality you could try registering startup script on the server, which calls client side javascript function. This function gets as parameter all rows' indexes which need to be selected. Also into the function you could get the item by its index and select it. This will fire the OnRowSelected event. For example:
ASPX.CS
string script = string.Format("SelectItems({0})", "['1','2']");
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SelectItems", script, true);
ASPX
function SelectItems(itemsIndexes)
 {
         setTimeout(function ()
         {
                var masterTable = $find("<%=RadGrid1.ClientID %>").get_masterTableView();
                var dataItems = masterTable.get_dataItems();
                for (var i = 0; i < itemsIndexes.length; i++)
                {
                    var item = dataItems[itemsIndexes[i]].get_element();
                    masterTable.selectItem(item);
                }
            }, 300);
   }

Additionally I am sending you a simple example which demonstrates the desired functionality. Please check it out and let me know if it helps you.

Regards,
Radoslav
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Vince Ockerman
Top achievements
Rank 1
answered on 03 Feb 2011, 11:11 PM
Thank you - exactly what I was looking for.
Tags
Grid
Asked by
Vince Ockerman
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Vince Ockerman
Top achievements
Rank 1
Share this question
or