How can I change state of the Grid.js component from the plugin context?
I'm trying to implement a visual configurator for the pagination.limit
prop (https://gridjs.io/docs/config/pagination):
import { BaseComponent, BaseProps, h, PluginPosition } from 'gridjs';
class LimitConfigurator extends BaseComponent {
setLimit(limitNew) {
// this.setState({ pagination: {limit: limitNew}});
// this.config.pagination.limit = limitNew;
}
render() {
const self = this;
return h(
'div',
{ class: 'limit-configurator' },
[
h('span', { onclick: function () { self.setLimit(10); } }, '10'),
h('span', {}, '25'),
h('span', {}, '50'),
]
);
}
}
It renders something like 10 | 25 | 50
under the grid's footer and dynamically sets new per-page number for the pagination.limit
path in the original component. Registration code:
// somewhere in the Vue component (using gridjs-vue bridge)...
async mounted() {
await elementReady('.grid-operator', { stopOnDomReady: false });
const gridComponent = this.$refs.gridReference.$data.grid;
gridComponent.plugin.add(
{
id: 'limitEditor',
component: LimitConfigurator,
position: PluginPosition.Footer,
},
);
gridComponent.forceRender();
},
I see prop values in the this.config
but don't know how to properly manipulate them from the plugin (currently learning preact + vue environment). Is there a "convenient" way to do it?