Skip to main content

delete-assignment

PRO

The functionality is available in PRO Edition only

Description​

Fires when deleting a resource assignment

Usage​

"delete-assignment": ({
id: string | number,
}) => boolean | void;
info

For handling the actions you can use the Event Bus methods. Returning false from the action handler will block the action (see Preventing actions)

Parameters​

The callback of the delete-assignment action can take an object with the following parameters:

  • id - (required) the ID of the assignment to be deleted

Example​

Use the api.exec method to trigger the action:

import { getData } from "./common/data";
import { Gantt } from "@svar/react-gantt";
import { useState, useRef } from "react";

function App() {
const data = getData();
const api = useRef(null);

function init(ganttApi) {
api.current = ganttApi;
}

function removeAssignment() {
api.current.exec("delete-assignment", { id: 1 });
}

return (
<Gantt
tasks={data.tasks}
links={data.links}
scales={data.scales}
init={init}
/>
);
}

Prevent deleting an assignment​

You can intercept the action and return false to block it:

api.intercept("delete-assignment", ev => {
if (!allowDelete) return false; // prevents deletion
});

Related articles: