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

Detect final OnRowSelected and OnRowDeselected

2 Answers 165 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rohan
Top achievements
Rank 1
Rohan asked on 16 Jun 2011, 02:40 PM
Hi,

Is it possible to detect (or if there is an event that I am missing) the final OnRowSelected/OnRowDeselected?

I have a grid of 100 items and I am turning toolbar icons on/off depending if there are any items in the grid selected or not i.e. if one or more items selected then turn on the Delete/Move buttons, if not, disable the Delete/Move buttons.

As the events (OnRowSelected and/or OnRowDeselected) fire for each row selection change, I don't really want to call the enable/disable methods 100 times (if the user selects ALL rows) and again 100 times if they deselect all rows.

Is there an event that fires when the final select/deselect event fires so you can then process the actuall selected rows?

The work around I am using is to have a timer created on the OnRowSelected and in the OnRowDeselected - this timer has an interval of 50ms which when fires does the toolbar options. Each time the OnRowSelected/OnRowDeselected  events fire they cancel the timer and create a new timer. So, if there is no events fired for 50ms I am "assuming" the events have completed and therefore perform the toolbar methods.

But this seems a bit of a hack.

Anyone got any ideas?

Thanks,

Ro

2 Answers, 1 is accepted

Sort by
0
Accepted
Galin
Telerik team
answered on 22 Jun 2011, 08:25 AM
Hello Rohan,

As it is expected and also you mentioned the events OnRowSelected/OnRowDeselected are fire for each row selection change. There in no an event like OnRowsSelected.

Your suggested hack with time interval is a solution, but I am not sure if it will be improve the performance. Perhaps the better way is to check out how many items are selected and also to use a flag. So the event is fired again on every selection change, but your method will be called only when it is necessary, e.g.:
var selectedFlag = false;
function selectDeselectHandler(sender, arg)
{
    if(sender.get_selectedItemsInternal().length && !selectedFlag)
    {
        alert('select');
        selectedFlag = true;
    }
    else if(!sender.get_selectedItemsInternal().length && selectedFlag)
    {
        alert('deselect')
        selectedFlag = false;
    }
}

$find('RadGrid1').get_selectedItemsInternal().length

I hope this helps.


Regards,
Galin
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
Rohan
Top achievements
Rank 1
answered on 22 Jun 2011, 09:27 AM
Hi Galin,

Thank you for your work-around to this. It does seem a much better solution to the timer.

I have implemented your method and it works great!

Thanks again.

Ro
Tags
Grid
Asked by
Rohan
Top achievements
Rank 1
Answers by
Galin
Telerik team
Rohan
Top achievements
Rank 1
Share this question
or