setSort()
Description
Sorts tasks of the active project by the specified parameters
Usage
setSort({
by?: string | ((task: object) => string),
dir?: "asc" | "desc",
tree?: boolean
}): void;
Parameters
by
- (optional) the search criterion (either the key of the task attribute or a search function which returns a string)dir
- (optional) the direction of sorting: "asc" or "desc"tree
- (optional) enables/disables sorting for child tasks; false by default
Example
const { ToDo, Toolbar } = todo;
const list = new ToDo("#root", {
tasks: [
{ id: "a", text: "A" },
{ id: "ac", text: "C", parent: "a" },
{ id: "ad", text: "D", parent: "a" },
{ id: "aa", text: "A", parent: "a" },
{ id: "ab", text: "B", parent: "a" },
{ id: "c", text: "C" },
{ id: "d", text: "D" },
{ id: "b", text: "B" },
],
});
const toolbar = new Toolbar("#toolbar", {
api: list.api,
});
// sort tasks in ascending order by the "text" parameter
list.setSort({
by: task => task.id, // or by: "text"
dir: "asc",
// tree: true // enable tree sort, false by default
});
Change log: Added in v1.1
Related article: Sorting and filtering tasks