sort-resources
The functionality is available in PRO Edition only
PRODescription
Fires when the resource grid is sortedUsage
"sort-resources": ({
key: string,
order: "asc" | "desc",
add?: boolean,
}) => boolean | void;
info
For handling the actions you can use the Event Bus methods
Parameters
The callback of the sort-resources action takes an object with the following parameters:
key- (required) the column ID to sort byorder- (required) sort direction:"asc"for ascending,"desc"for descendingadd- (optional) iftrue, appends this sort level to the existing multi-sort order; iffalseor omitted, replaces the current sort; Default:false
Example
Use the api.exec method to sort the resource grid programmatically:
import { useRef } from "react";
import { getData } from "./common/data";
import { Gantt, ResourceLoad } from "@svar-ui/react-gantt";
const { tasks, scales, resources, assignments } = getData();
function App() {
const apiRef = useRef(null);
function init(api) {
api.exec("sort-resources", { key: "name", order: "asc" });
}
return (
<>
<Gantt ref={apiRef} tasks={tasks} scales={scales} resources={resources} assignments={assignments} init={init} />
<ResourceLoad api={apiRef.current} />
</>
);
}
export default App;
To apply multi-level sorting, call the action again with add: true:
api.exec("sort-resources", { key: "role", order: "asc", add: true });
Related articles: