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

Allow multi row select but single row for detail table

2 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sameers
Top achievements
Rank 1
Sameers asked on 19 Apr 2011, 09:22 AM
I have a grid with detail table, I would like user to allow multiple parent rows, but only single row from detail table. Is that possible? I see that AllowMultiRowSelect is at Grid level, not table view level. So when I enable that, it allows selection of multiple rows on both parent and child rows.

At the same time, I want to allow user to select detail table row only if parent row is NOT slected and allow to select parent row only if child row is NOT selected. Is there a way to achieve this task?

thanks,
Sameers

2 Answers, 1 is accepted

Sort by
0
Accepted
Mira
Telerik team
answered on 22 Apr 2011, 08:04 AM
Hello Sameers,

In order to implement the desired functionality, I recommend that you use the approach from the Conditional row select in hierarchy help topic. In the RowSelecting client-side event you can check the table view of the record the user is trying to select and cancel the selection if your custom logic requires it.

I hope this helps.

Greetings,
Mira
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
Sameers
Top achievements
Rank 1
answered on 24 Apr 2011, 09:45 AM
Thank you, that helped. For the information of the rest of the people, I am pasting my code here.

My task was to let customers select child row only if the parent row is selected. That means

1. You can select parent row, but not necessarily child row.
2. Only one of the child row can be selected (or none)
3. IF parent row deselected, child must be de-selected as well.

function RowSelecting(sender, eventArgs) {
    //eventArgs.get_tableView() returns the gridtable
    //from which the event originated
    if (eventArgs.get_tableView().get_name() == "Vendors") {
        //Make sure parent Row is selected
        //var parentRow = eventArgs.get_tableView().get_parentRow();
        var parentRow = eventArgs.get_tableView().get_parentRow();
        var parentView = eventArgs.get_tableView().get_parentView();
        parentView.selectItem(parentRow);
        //parentRow.set_selected(true);
        //Make sure,  no other row is selected, if there is, deselect that.
        for (var i = 0; i < eventArgs.get_tableView().get_dataItems().length; i++) {
            var row = eventArgs.get_tableView().get_dataItems()[i];
            var chkSelect = row.findElement("chkSelectChild");
            row.set_selected(false);
        }
    }
    else if (eventArgs.get_tableView().get_name() == "Products") {
          
    }
}
function RowDeSelecting(sender, eventArgs) {
    if (eventArgs.get_tableView().get_name() == "Products") {
        var item = eventArgs.get_gridDataItem();                
        if (item.get_nestedViews() != null && item.get_nestedViews()[0] != null) {
            item.get_nestedViews()[0].clearSelectedItems();
        }  
    }
}
function RowCreated(sender, eventArgs) {
      
}
Note that I used an empty RowCreated event, since I read on the forum that until you hook that event, you can't get reference of selected row (RowDeSelecting) and yes, it was true. If you dont hook that, you will get null reference for the de-selected item.
Tags
Grid
Asked by
Sameers
Top achievements
Rank 1
Answers by
Mira
Telerik team
Sameers
Top achievements
Rank 1
Share this question
or