Is there any way to ignore rows on sorting?

Hi, I have a grid, with a lot of rows, some rows have a flag (boolean), I want to ignore those rows when the user are sorting the rows, I mean, I want to put always those rows at the top of the grid, is there a way to do that?.


Thank you

1 Reply

PS Pavithra Subramaniyam Syncfusion Team August 10, 2022 07:12 AM UTC

Hi Christian,


Thanks for contacting Syncfusion support.


By default, Grid will sort based on all the records. So it is not possible to avoid some records from sorting. However, you can use your own sorting logic for columns using the “Sort Comparer” feature. Please refer to the below documentation for more information.


@Component({

  selector: 'app-root',

  template: `<ejs-grid [dataSource]='data' [allowSorting]='true' height='315px'>

                <e-columns>

                    <e-column field='CustomerID' [sortComparer]='sortComparer' headerText='Customer ID' width=150></e-column>

                    .   .   .

                </e-columns>

                </ejs-grid>`

})

export class AppComponent implements OnInit {

 

  // The custom function where you can use your custom logic and return 0, 1 or -1 

  public sortComparer = (reference: string, comparer: string, referenceRecord: object, comparerRecord: object) => {

    if (reference < comparer) {

      return -1;

    }

    if (reference > comparer) {

      return 1;

    }

    return 0;

  }

}

 


https://ej2.syncfusion.com/angular/documentation/grid/sorting/#sort-comparer


Regards,

Pavithra S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Loader.
Up arrow icon