简体   繁体   English

在Syncfusion Essential JS 2 Grid for Angular 5中按给定顺序对列进行排序

[英]Sort a column by given order in Syncfusion Essential JS 2 Grid for Angular 5

Sorting feature is described under the documentation for syncfusion-ej2 Grid ( https://ej2.syncfusion.com/angular/documentation/grid/api-column.html#sortcomparer ). 在syncfusion-ej2 Grid的文档( https://ej2.syncfusion.com/angular/documentation/grid/api-column.html#sortcomparer )下描述了排序功能。 I have already implemented it in my Angular application. 我已经在Angular应用程序中实现了它。 Still, I couldn't find a way to achieve my target as it doesn't work as I expected (May be I am thinking in a wrong way). 不过,我仍然找不到实现目标的方法,因为它没有按我预期的那样工作(可能是我想错了方向)。

I just need to introduce a default sorting to the grid. 我只需要向网格引入默认排序。 The sorting has to be implemented on the column 'Status', which can be either “Overdue”, “Planned” or “Completed”. 必须在“状态”列上执行排序,该列可以是“过期”,“计划中”或“已完成”。 The sort order should follow the same sequence as I have mentioned. 排序顺序应遵循我提到的相同顺序。 Can I achieve it using 'sortComparer' like this? 我可以使用“ sortComparer”来实现吗? If so, what are the changes that I have to perform on the existing solution, which I have quoted below? 如果是这样,我在现有解决方案上必须执行哪些更改(以下引用)?

[HTML] [HTML]

<!-- Status -->
<e-column field="statusDisplay" headerText="Status" width="85" [sortComparer]='sortComparer'>

[TS] [TS]

  public sortComparer = (reference: string, comparer: string) => {
    if (reference == "Overdue") {
      return -2;
    }
    else if (reference == "Planned") {
      return -1;
    }
    else if (reference == "Completed") {
      return 1;
    }
    return 0;
  };

Please change your sortComparer definition like below. 请如下更改您的sortComparer定义。

public comparer = (reference: string, comparer: string) => {
  if (reference == "Overdue") {
   return -1;
  }
  else if (reference == "Planned") {
    if (comparer == "Overdue") {
      return 1;
    } else {
      return -1;
    }
  }
  else if (reference == "Completed") {
   return 1;
  }
  return 0;
};

http://next.plnkr.co/edit/ihwvd7a6UxXYI1N5?preview http://next.plnkr.co/edit/ihwvd7a6UxXYI1N5?preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM