angular - 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). I have already implemented it in my Angular application. 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? If so, what are the changes that I have to perform on the existing solution, which I have quoted below?
[HTML]
<!-- Status -->
<e-column field="statusDisplay" headerText="Status" width="85" [sortComparer]='sortComparer'>
[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.
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;
};
推荐阅读
- java - E/Volley:[6074] BasicNetwork.performRequest:意外响应代码 403
- javascript - 避免文本移位,因为它在列中上升
- javascript - Javascript设置cookie在Web服务器上不起作用
- python - Pip 无法安装密码学
- ios - 仅检索一次设备运动数据 - Core Motion
- ios - 单击Xcode时更改按钮的图像
- php - 如何在 laravel 的队列作业中运行 Symfony Process 功能
- python - 机器学习中带有异常值的线性回归
- sql - Postgres/SQL 子查询 - 根据条件返回每个分组的多个列
- android - 停止 exoplayer 在后台播放视频