Articles in this section
Category / Section

How to sort files based on year in Angular File Manager Component?

5 mins read

The following steps used to achieve achieving year sorting using the sortComparer property in the Angular File Manager Component.

 

Step 1 : Implement the File Manager component using our Getting Started documentation.

 

Step 2 : To achieve sorting based on the year in the File Manager component:

    For the LargeIconsView, utilize the sortComparer property.
    For DetailsView, define the sortComparer property in the date column in the columns property. 

Step 3  : In the sortComparer function, separate the year value from the reference and comparer parameters to perform year sorting. Return positive and negative numbers to rearrange/reorder the files and folders based on the year.

[app.component.ts]

@Component({

  ....

  template: `<ejs-filemanager id='default-filemanager' [sortComparer]="largeIconssortComparer" [sortOrder]='sortOrder' [sortBy]="sortBy" [ajaxSettings]='ajaxSettings' [detailsViewSettings]='detailsViewSettings' [view]='view'>

</ejs-filemanager>`

})

export class AppComponent {

  ....

  public sortComparer(a: any, b: any): number {

    var ref = new Date(a).getFullYear();

    var com = new Date(b).getFullYear();

    if (ref > com) {

      return 1;

    } else if (ref < com) {

      return -1;

    } else {

      return 0;

    }

  }

  ....

  public ngOnInit(): void {

    ....

    this.sortBy = '_fm_modified';

    this.sortOrder = 'Ascending';

    this.largeIconssortComparer = this.sortComparer.bind(this);

    // Details View settings customization

    this.detailsViewSettings = {

      columns: [

         .....

        { field: '_fm_modified', headerText: 'Date Modified', minWidth: 50, width: '190', format: 'MMMM dd, yyyy', sortComparer: this.sortComparer.bind(this) }

      ]

    };

  };

}

Sample : FileManager-SortComparer (forked) - StackBlitz

 

See Also :


Conclusion

I hope you enjoyed learning about how to sort files based on year in Angular File Manager Component.

You can refer to our Angular File Manager feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Angular File Manager example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied