Skip to main content

getSelection()

Description

Gets an array with ID of the selected task

Usage

getSelection({
sorted?: boolean,
}): (string | number)[];

Parameters

  • sorted - (optional) if true, sorts IDs of selected tasks by the order they are displayed in the list; if false, outputs tasks' IDs without sorting

Returns

The method returns an array with IDs of selected tasks

Example

const { ToDo, Toolbar } = todo;

const list = new ToDo("#root", {
tasks: [
{ id: "1", text: "Task 1" },
{ id: "1.1", text: "Task 1.1", parent: "1" },
{ id: "1.2", text: "Task 1.2", parent: "1" },
{ id: "2", text: "Task 2" },
{ id: "2.1", text: "Task 2.1", parent: "2" },
{ id: "2.2", text: "Task 2.2", parent: "2" },
],
selected: ["1.2", "1.1", "2.2", "2.1"]
});

const toolbar = new Toolbar("#toolbar", {
api: list.api,
});

// sorted - disable;
console.log(list.getSelection({ sorted: false })); // ["1.2", "1.1", "2.2", "2.1"]

// sorted - enable;
console.log(list.getSelection({ sorted: true })); // ["1.1", "1.2", "2.1", "2.2"]

Change log: The sorted parameter was added in v1.1

Related article: