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.

import { useRef } from "react";
import { Button } from "@svar-ui/react-core";
import { Grid } from "@svar-ui/react-grid";
import { data, columns } from "./common/data";

export default function Example() {
const apiRef = useRef(null);

function doScroll(row, column) {
apiRef.current?.exec("scroll", { row, column });
}

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

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

<Grid init={init} data={data} columns={columns} />
</>
);
}

Related sample: Events

Related articles: