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

Cancel row highlighting when cancelling row selection?

5 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
J
Top achievements
Rank 1
J asked on 04 Jan 2013, 06:58 PM
Quick background - I have a grid of users that loads some information when a user (row) is selected. If some of that information changes, the page is flagged so that when a new user is picked before saving, a confirmation box appears. Clicking OK discards the changes and selects the new user, Cancel...well, cancels the new user selection. Functionally, this works fine, but even after cancelling the new row is highlighted. How can I stop this?

Relevant code:
<ClientSettings EnablePostBackOnRowClick="True">
    <Selecting AllowRowSelect="True"/>
    <Scrolling UseStaticHeaders="True" AllowScroll="True" SaveScrollPosition="True"/>
    <ClientEvents OnRowSelecting="rgUsers_RowSelecting"/>
</ClientSettings>
function rgUsers_RowSelecting(sender, args)
{
    var changed = $get("formChanged").value;
 
    if (changed > 0) {
        if(confirm("Your changes will be discarded. Click OK to continue."))
        {
            $get("hfFormChanged").value = "0";
        }
        else
        {
            args.set_cancel(true);
        }
    }
}

It is worth noting that I've tested and checked the data to make sure the select is indeed cancelled.

Edit: Also, I am forced to use Internet Explorer. Could be a factor.

Edit 2: As far as this goes, I have found the problem. I had EnablePostBackOnRowClick="True" in the ClientSettings. This was causing the ItemCommand event to be fired on the server. In ItemCommand, I was doing something with RowClick, and this was the problem. Thanks for your help.

5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 05 Jan 2013, 05:12 AM
Hello,

Just for an testing purpose try with below code.

Because i am not able to reproduce this issue.

function rgUsers_RowSelecting(sender, args) {
                args.set_cancel(true);
}



Thanks,
Jayesh Goyani
0
J
Top achievements
Rank 1
answered on 07 Jan 2013, 02:23 PM
Well, that stops the RowSelected event from firing, but so does the code I have now. The problem is just the highlighting. I know it's not a matter of the second row clicked being "selected", because when I press cancel on the confirmation dialogue, the loaded data is still from the first row clicked. The problem is just highlighting. For some reason, the second row clicked still gets highlighted, even though the first one is selected.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 08 Jan 2013, 06:04 AM
Hello,

Please try with below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
         AllowPaging="true" AllowFilteringByColumn="true" ShowFooter="true" AllowMultiRowSelection="true"
         AllowMultiRowEdit="true" >
         <ExportSettings ExportOnlyData="true">
         </ExportSettings>
         <MasterTableView CommandItemDisplay="Top" EditMode="EditForms">
             <Columns>
                 <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                 </telerik:GridBoundColumn>
                 <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                 </telerik:GridBoundColumn>
                 <telerik:GridEditCommandColumn>
                 </telerik:GridEditCommandColumn>
             </Columns>
             <EditFormSettings EditColumn-ButtonType="ImageButton">
             </EditFormSettings>
         </MasterTableView>
         <ClientSettings>
             <Selecting AllowRowSelect="True" />
             <ClientEvents OnRowSelecting="rgUsers_RowSelecting" />
         </ClientSettings>
         <PagerStyle AlwaysVisible="True" />
     </telerik:RadGrid>
function rgUsers_RowSelecting(sender, args) {
 
               args.set_cancel(true);
 
           }
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       dynamic data = new[] {
           new { ID = 1, Name ="Name1",path="1.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(1)},
           new { ID = 2, Name = "Name2",path="2.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(2)},
           new { ID = 3, Name = "Name3",path="3.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(3)},
            new { ID = 4, Name = "Name4",path="2.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(4)},
           new { ID = 5, Name = "Name5",path="3.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(5)},
            new { ID = 6, Name ="Name1",path="1.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(6)},
           new { ID = 7, Name = "Name2",path="2.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(7)},
           new { ID = 8, Name = "Name3",path="3.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(8)},
            new { ID = 9, Name = "Name4",path="2.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(9)},
           new { ID = 10, Name = "Name5",path="3.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(10)},
            new { ID = 11, Name ="Name1",path="1.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(11)},
           new { ID = 12, Name = "Name2",path="2.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(12)},
           new { ID = 13, Name = "Name3",path="3.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(13)},
            new { ID = 14, Name = "Name4",path="2.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(14)},
           new { ID = 15, Name = "Name5",path="3.jpg",Customedate=DateTime.Now,ReceivedDate=DateTime.Now.AddDays(150)}
            
       };
 
       RadGrid1.DataSource = data;
 
   }

i am not able to reproduce the issue with above code snippet.


If it is also worked from your side then let me know which type of functionality you want now.

Thanks,
Jayesh Goyani
0
J
Top achievements
Rank 1
answered on 08 Jan 2013, 02:49 PM
Thanks for the help, Jayesh. I figured out what the problem was. I was allowing the grid to post back on row click, and in the event, I was doing setting the event arg item's selected property to true. My problem now is that my hidden field won't keep values, but it's an ASP issue.
0
J
Top achievements
Rank 1
answered on 08 Jan 2013, 04:09 PM
--
Tags
Grid
Asked by
J
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
J
Top achievements
Rank 1
Share this question
or