Welcome to the Blazor feedback portal. We’re happy you’re here! If you have feedback on how to improve the Blazor, we’d love to hear it!>
Thanks for joining our community and helping improve Syncfusion products!
Prevent grid column from sorting and do not show change sort icons
Hello,
I am using the "sorting" event to set "cancel" to "true". This prevents sorting - ok.
But still the sort icons are changing in the column header. How can I avoid that.
Please note tat I am using a custom DataAdaptor, but do not know if this has any effect on the behavior.
Replication Stesps:
@page "/s"
@using Syncfusion.Blazor
@using Syncfusion.Blazor.Data
@using Syncfusion.Blazor.Grids
<SfGrid TValue="Order" ID="Grid" AllowSorting="true" AllowFiltering="true" AllowPaging="true">
<SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Syncfusion.Blazor.Adaptors.CustomAdaptor"></SfDataManager>
<GridEvents Sorting="SortingHandler" TValue="Order"></GridEvents>
<GridSortSettings AllowUnsort="false"></GridSortSettings>
<GridPageSettings PageSize="8"></GridPageSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@Syncfusion.Blazor.Grids.TextAlign.Center" Width="140"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" Width="150"></GridColumn>
</GridColumns>
</SfGrid>
@code {
public static List<Order> Orders { get; set; }
protected override void OnInitialized()
{
Orders = Enumerable.Range(1, 75).Select(x => new Order()
{
OrderID = 1000 + x,
CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],
Freight = 2.1 * x,
}).ToList();
}
public class Order
{
public int OrderID { get; set; }
public string CustomerID { get; set; }
public double Freight { get; set; }
}
public void SortingHandler(Syncfusion.Blazor.Grids.SortingEventArgs args)
{
args.Cancel = true;
}
// Implementing custom adaptor by extending the DataAdaptor class
public class CustomAdaptor : Syncfusion.Blazor.DataAdaptor
{
// Performs data Read operation
public override object Read(Syncfusion.Blazor.DataManagerRequest dm, string key = null)
{
IEnumerable<Order> DataSource = Orders;
if (dm.Search != null && dm.Search.Count > 0)
{
// Searching
DataSource = Syncfusion.Blazor.DataOperations.PerformSearching(DataSource, dm.Search);
}
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
// Sorting
DataSource = Syncfusion.Blazor.DataOperations.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0)
{
// Filtering
DataSource = Syncfusion.Blazor.DataOperations.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
int count = DataSource.Cast<Order>().Count();
if (dm.Skip != 0)
{
//Paging
DataSource = Syncfusion.Blazor.DataOperations.PerformSkip(DataSource, dm.Skip);
}
if (dm.Take != 0)
{
DataSource = Syncfusion.Blazor.DataOperations.PerformTake(DataSource, dm.Take);
}
Syncfusion.Blazor.Data.DataResult DataObject = new DataResult();
if (dm.Aggregates != null) // Aggregation
{
DataObject.Result = DataSource;
DataObject.Count = count;
DataObject.Aggregates = Syncfusion.Blazor.Data.DataUtil.PerformAggregation(DataSource, dm.Aggregates);
return dm.RequiresCounts ? DataObject : (object)DataSource;
}
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
}
}