在grid中对任务进行排序
field | string | SortTasks | 用于排序grid的列名,或自定义排序函数 |
desc | boolean | 设置排序顺序:true表示降序,false表示升序 ,默认值为false |
parent | string|number | 父任务的ID。如果只想对指定父任务分支内的任务进行排序,请使用此参数。 |
silent | boolean | 决定在重新排序项目后是否触发渲染 |
<input type='button' value='按任务名称排序' onclick='sortByName()'>
<script>
var n_direction = false;
function sortByName(){
if (n_direction){
gantt.sort("text",false);
} else {
gantt.sort("text",true);
}
n_direction = !n_direction;
};
gantt.init("gantt_here");
</script>
自定义排序函数接收Task对象作为参数,应该返回一个数字(1、0或-1)。
使用自定义排序函数时,parent参数会被忽略。查看示例。
调用sort()方法时,Gantt不会自动添加任何排序图标(例如表示排序方向的箭头)。如果需要显示排序图标,可以手动添加。查看示例。