Skip to main content

api.on()

Description​

Allows attaching a handler to the inner events

Usage​

api.on(
event: string,
handler: function
): void;

Parameters​

  • event - (required) an event to be fired
  • handler - (required) a handler to be attached (the handler arguments will depend on the event to be fired)
info

The full list of the Grid actions can be found here

Example​

In the example below we output to the console that the scroll action is detected.

<script>
import { Button } from "@svar-ui/svelte-core";
import { Grid } from "@svar-ui/svelte-grid";
import { data, columns } from "./common/data";

let api = $state();
function doScroll(row, column) {
api.exec("scroll", { row, column });
}

function init(api){
api.on("scroll", () => {
console.log(`Scrolling detected`);
});
}
</script>

<Button type="primary" onclick={() => doScroll(data[0].id, columns[1].id)}>
Scroll to First Row / Column
</Button>

<Grid bind:this={api} {init} {data} {columns} />

Related sample: Events

Related articles: