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

Prevent default Telerik sort for RadGrid

5 Answers 254 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lajos
Top achievements
Rank 1
Lajos asked on 14 Sep 2012, 02:49 PM
I am using Telerik RadGrid and I have a data source where one of my columns look like hh:mm:ss. When I load the datasource of the RadGrid from the database I order the results (on SQL level) based on a DateTime column (which contains year, month and day too), but in the grid representation I am showing just hh:mm:ss. My custom sort on SQL level is working well, in a given page I get exactly those elements which should be there. However, when I sort a column which is essentially a DateTime but is represented as hh:mm:ss, default telerik sort also occurs which sorts the rows in the given page. This is incorrect, because '09-12-2012 20:20:20' < '09-13-2012 10:10:10', but '20:20:20' > '10:10:10'. How can I prevent default telerik sort for my RadGrid? I want everything else to work in the same way, I just want to tell Telerik "do not sort my column, I've already handled the sort event, thanks". How can I achieve this?

5 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Sep 2012, 06:39 PM
Hello,

Try with below code snippet.

<MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                    </telerik:GridBoundColumn>
                    
                </Columns>
            </MasterTableView>
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
       {
           if (e.CommandName == RadGrid.SortCommandName)
           {
               if (e.CommandArgument == "ID") // check column here
               {
                   e.Canceled = true;
                   // Here you can manage your own way  
               }
           }
       }


Thanks,
Jayesh Goyani
0
Lajos
Top achievements
Rank 1
answered on 14 Sep 2012, 07:01 PM
Thank you very much, I will try this out now and will tell you about the result. Thank you very very much.
0
Lajos
Top achievements
Rank 1
answered on 14 Sep 2012, 07:24 PM
Unfortunately this:

    Private Sub RadGrid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
        Select Case e.CommandName
            Case RadGrid.SortCommandName
                e.Canceled = True
        End Select
    End Sub

didn't solve the issue, default Telerik sort still messes up the sort. I've also tried with an event which handles RadGrid1.SortCommand, but that try was unsuccessful too. Is there a way to tell Telerik that everything should be done as expected, but without triggering the function which handles default sort?

When I get the datasource the order of the rows is good, but eventually Telerik runs its default sort function too and the result is not correct, because a later date will be represented as earlier date, because the hour:minute:second is smaller. Can I somehow solve this issue, or should I make a hack to achieve the desired result?

Thank you very much again,
Best regards,
Lajos Árpád.
0
Lajos
Top achievements
Rank 1
answered on 14 Sep 2012, 07:27 PM
There is also a ClientSettings-DataBinding-DataService-SortQueryOption attribute of RadGrid, but I don't know if it can be helpful in this problem and what can be its potential value.
0
Lajos
Top achievements
Rank 1
answered on 15 Sep 2012, 08:52 PM
AllowCustomSorting="true"

If I add that to the MasterTableView tag as attribute then it will work exactly as I described my needs in the question.
Tags
Grid
Asked by
Lajos
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Lajos
Top achievements
Rank 1
Share this question
or