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

Deselecting event, set_cancel(true) does not preserve selectcolumn status

3 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jimmy Vithalani
Top achievements
Rank 1
Jimmy Vithalani asked on 29 Mar 2010, 08:59 AM
Hi,

I need confirm dilog when user deselects a row.
I am using GridClientSelectColumn for row selection.
I am using RowDeselecting event of grid.

I am doing eventArgs.set_cancel(true); when user says cancel, and it leave the row in its old state(selected).

            var grid = sender;
            var MasterTable = grid.get_masterTableView();
            var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
            var cell = MasterTable.getCellByColumnUniqueName(row, "Name");

if(!confirm("confirm?"))
{
eventArgs.set_cancel(true);
}

But the problem is check box in GridClientSelectColumn loses its status. It becomes unchecked and does not get checked even if i set cancel true.

I want the select checkbox should also be cancelled and made checked again.

Tell me if I have chosen wrong event or on wrong object.

Help please.

Thanks,
Jimmy.


3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Mar 2010, 11:01 AM
Hello Jimmy,

I tried following code in order to show confirm on deselecting the row by using GridClientSelecteColumn.

C#:
 
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            CheckBox chk = (CheckBox)item["sel"].Controls[0]; 
            chk.Attributes.Add("onclick""check(this, '"+ item.ItemIndex+"');"); 
        } 
    } 

JavaScript:
 
<script type="text/javascript"
    var row; 
    function check(checkBox, index) { 
        if (!checkBox.checked && !confirm("confirm?")) { 
            var grid = $find("<%= RadGrid1.ClientID %>"); 
            var masterTableView = grid.get_masterTableView(); 
            row = masterTableView.get_dataItems()[index]; 
            setTimeout('row.set_selected(true);', 10); 
        } 
    } 
</script> 

Thanks,
Princy.
0
Jimmy Vithalani
Top achievements
Rank 1
answered on 29 Mar 2010, 12:21 PM
Hi Princy,

Your code is working nice and is exactly what I want.

Then I tried to replace statement from my code

eventArgs.set_cancel(true);

to

setTimeout('row.set_selected(true);', 10); 

and It worked :).

Actually I was feeling uneasy to bind onclick to each row's select checkbox, and using a server side event for that.

This way I achieved what I wanted and setTimeout('row.set_selected(true);', 10);  was usefull in that.

Thanks a lot.

Also can you tell me why we use setTimeOut here, why cant we directly make the row selected?

Thanks,
Jimmy.
0
Jimmy Vithalani
Top achievements
Rank 1
answered on 31 Mar 2010, 08:11 AM
Hi,

One problem I found is,
When I "deselect all" from header checkbox, it asks for all rows and when i say cancel, it still deselects the items and only leaves last item selected. 

I think it is because row variable is assigned a new value after confirm. May be.

Please help.
Thanks.
Tags
Grid
Asked by
Jimmy Vithalani
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jimmy Vithalani
Top achievements
Rank 1
Share this question
or