We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How can I catch sort event

I want to catch the column sorting event. after click the  column  header I want to catch the column title and stop default sorting action.

1 Reply

RU Ragavee U S Syncfusion Team December 8, 2016 07:21 AM UTC

Hi Mohamed, 

Thanks for your interest in Syncfusion products. 

We can achieve your requirement using the actionBegin event of the Grid. In actionBegin event, when the requestType is “sorting”, we can the corresponding columnName in the event arguments and thus can prevent the default sort action by settings the argument.cancel as true.  

The APIs used in Angular 2 is like that JavaScript APIs only the syntax for the member definition differs. For example, in JavaScript allowFiltering is used to enable filtering to grid whereas in Angular 2, we define the properties within square brackets ie [allowFiltering]. Please refer to the below document for angular2 properties and events declarations syntax.  

Please refer to the below code example. 

<h2>Syncfusion Javascript Angular 2 Component</h2> 
<ej-grid #grid  [dataSource]="employeeData" [allowPaging]="true" [allowSorting]="true" (actionBegin)="onBegin($event)" > 
    . . . . 
export class AppComponent { 
    if(e.requestType == "sorting"){ 
    alert("Sorted Field Name: " +e.columnName);//display the column field name 
    alert("Sorted Column Header Text: "+this.Grid.widget.getHeaderTextByFieldName(e.columnName));//display the column header text 
    e.cancel = true;//prevent the default sort action 

We have prepared a sample for your reference, which can be downloaded from the below location. 

Ragavee U S. 

Live Chat Icon For mobile
Up arrow icon