Display Sort Icon for TelerikGrid on Initial Load

1 Answer 24 Views
Grid Styling
Nate
Top achievements
Rank 1
Iron
Nate asked on 04 Apr 2025, 03:00 PM
We are implementing the TelerikGrid for a Blazor application and they have asked that the sort icons be displayed by default on the component's initial load, not after the user clicks in the header row.  It seems to work this way in all of the demo examples.  Is there a way to toggle the display so that sort icons display automatically?

1 Answer, 1 is accepted

Sort by
1
Accepted
Anislav
Top achievements
Rank 6
Silver
Bronze
Iron
answered on 04 Apr 2025, 03:31 PM

Hi Nate,

By default, the Grid does not sort the provided data automatically, so no sorting indicator is displayed. To resolve this, I usually handle the OnStateInit event, allowing me to define an initial state for the Grid. In this event handler, I include a Sort Descriptor to sort the first column during initialization.

For further information, refer to the official documentation: https://www.telerik.com/blazor-ui/documentation/components/grid/state#onstateinit

Regards,
Anislav Atanasov

Nate
Top achievements
Rank 1
Iron
commented on 04 Apr 2025, 04:39 PM

Thanks for the quick reply Anislav, I fixed it per the following:

OnStateInit="@((GridStateEventArgs<EventsDto> args) => AddDefaultEventsSort(args))"

and

  private void AddDefaultComplianceSort(GridStateEventArgs<ComplianceEventsDto> args)
  {
    args.GridState.SortDescriptors.Add(new SortDescriptor()
    {
      Member = nameof(ComplianceEventsDto.TractorId),
      SortDirection = ListSortDirection.Descending
    });
  }
Got me where I needed to be.

 

 

Tags
Grid Styling
Asked by
Nate
Top achievements
Rank 1
Iron
Answers by
Anislav
Top achievements
Rank 6
Silver
Bronze
Iron
Share this question
or