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

RadGrid Multiple Rows-Selecting [SHIFT] event

2 Answers 165 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 07 Dec 2014, 11:54 AM
Hello,

I am working on a project with a RadGrid.

The user can select rows. However, there is a limit to the number of rows the user can select.
If the user selects more than the limit, a message pops-up telling the user about the limit. Then, all the rows surpassing the limit are unselected.

I have implement the JS function OnRowSelecting.
function Row_Selecting(sender, args) {
    var grid = $find("<%=MyGrid2.ClientID%>");
    var masterTable = grid.get_masterTableView();
    if (masterTable.get_selectedItems().length >= MAX_NUMBER) {
        alert("you reach the maximum number);
        args.set_cancel(true);
    }
}


I have a problem when the user selects multiple rows with SHIFT, the above message shows on each row, surpassing the limit.

How can I catch the SHIFT-SELECT event, so I can pop-up the message only once, and not for each row?

Thank you,
Daniel.

2 Answers, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 11 Dec 2014, 11:43 AM
Hi Daniel,

You can achieve the requested functionality using the following approach:
<ClientSettings>
    <Selecting AllowRowSelect="true" EnableDragToSelectRows="false" />
    <ClientEvents OnRowSelecting="rowSelecting" OnRowClick="rowClick" />
</ClientSettings>
JavaScript:
var alerted = false;
function rowClick(sender, args) {
    alerted = false;
}
function rowSelecting(sender, args) {
    var count = args.get_tableView().get_selectedItems().length;
    if (count > 4) {
        args.set_cancel(true);
        if (!alerted) {
            alerted = true;
            alert("you reach the maximum number");
        }
    }
}

That should do the trick. Looking forward to your reply.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Daniel
Top achievements
Rank 1
answered on 14 Dec 2014, 08:04 AM
Hello Eyup,

Thank you very much for your reply!
Its works fine!

Many Thanks,
Daniel.
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or