sort-resources
PRO
The functionality is available in PRO Edition only
Description
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:
<script>
import { getData } from "./common/data";
import { Gantt, ResourceLoad } from "@svar-ui/svelte-gantt";
const { tasks, scales, resources, assignments } = getData();
let api = $state();
function init(api) {
api.exec("sort-resources", { key: "name", order: "asc" });
}
</script>
<Gantt bind:this={api} {tasks} {scales} {resources} {assignments} {init} />
<ResourceLoad {api} />
To apply multi-level sorting, call the action again with add: true:
api.exec("sort-resources", { key: "role", order: "asc", add: true });
Related articles: