Advanced Plugins
Now that we know how to write a basic Grid.js plugin, let's take a look at some complex examples.
Using the pipeline
Grid.js has an internal pipeline which takes care of processing, filter and refining the raw data. You can get access to the current pipeline by using config.pipeline
(via the useConfig
hook) or you can use the useSelector
hook to subscribe to a specific part of
Grid.js state.
In this example, we have a table of Name (string) and Salary (double) and our custom plugin is in charge of summing salaries and displaying the total in the footer.
import { useSelector } from "gridjs";
Using the translation
Likewise, you can get access to the Translator function using the useTranslator
hook to localize strings in your Grid.js plugin:
import { useTranslator } from "gridjs";
Hooks
Grid.js provides the following hooks. You can use them to build and customize the behavior of your plugin:
useConfig
: Retrieve the current Grid.js config objectuseSelector
: Subscribe to a specific part of the Grid.js state (e.g.useSelector(state => state.data)
)useTranslator
: Get the Grid.js Translator functionuseStore
: Retrieve the Grid.js internal Store object