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

Disable AutoSorting

1 Answer 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jean-Marie
Top achievements
Rank 1
Jean-Marie asked on 25 Sep 2013, 03:34 PM
Hi there,

I need some help on RadGrid and its autosort :)

I want a Header column clickable to start OnSortCommand then my tableview.rebind.
But my data linked with DataSource , are already sorted as i want , nothing else :)

Each time i click header column , i can see my data but sorted again by RadGrid. 

I try lot of thing to stop auto sorting :D Nothing works

On Tableview :
tableView.AllowNaturalSort = false;
tableView.OverrideDataSourceControlSorting = true;
tableView.AllowSorting = false;
tableView.SortExpressions.Clear();
                     
tableView.Rebind();


My NeedDataSource : 

protected void rg_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
       {
           try
           {
               this.rg.VirtualItemCount = this.ItemCount;
               DataTable tb ;
                
               if (string.IsNullOrEmpty(sortedFieldClicked))
                   tb = this.DataSourceObject.GetData(this.TabId, this.rg.CurrentPageIndex + 1, this.rg.PageSize, null, SortOrder.None);
               else
               {
                   tb = this.DataSourceObject.GetDataBySortedField(this.TabId, this.rg.CurrentPageIndex + 1, this.rg.PageSize, sortedFieldClicked, actualSortOrder);
               }
               this.rg.DataSource = tb;
            
           }
           catch (Exception ex)
           {
               UIProcessHelper.AddMessage(String.Format("Error while fetching data for tab '{0}' TODO List: {1}", this.TabId,ex.Message), UIMessage.UIMessageType.error);
           }
       }

this.rg.DataSource = tb;

tb is exact data sorted as i want but i want to avoid autosorting done by radgrid or tableview after "this.rg.DataSource = tb;"

Any Helps ? =D

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 26 Sep 2013, 11:01 AM
Hello,

Please try with the below code snippet.

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
    {
        if (e.CommandName == RadGrid.SortCommandName)
        {
            // IF you want to disable sorting conditinally then
            if (e.CommandArgument == "YourFieldName/UniqueName")
            {
                e.Canceled = true;
            }
 
            //For All Column
 
            e.Canceled = true;
        }
    }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Jean-Marie
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or