gridjs
gridjs copied to clipboard
Plugins disappear after updating config.
Hi,
Im trying to update the pagination limit but the custom plugins i added before disappear after updateConfig * forceRender:
let pn = {
enabled: true,
limit: this.getPerPage(),
summary: true,
server: {
url: (prev, page, limit) => `${prev}¤t_page=${page+1}`
}
};
grid.updateConfig({pagination: pn});
grid.forceRender();
it also does not matter what i put in the updateConfig as value. All the plugins will disappear. How can i fix this?
@afshinm hi can you help me out please? i cant fix my issue :(
Hi, i'm not an expert of gridjs, but it's maybe because you have to implement your plugin in the new config ? Something like this :
let pn = {
enabled: true,
limit: this.getPerPage(),
summary: true,
server: {
url: (prev, page, limit) => `${prev}¤t_page=${page+1}`
}
};
grid.updateConfig({pagination: pn});
//you just reset the plugin too
grid.plugin.add({
id: 'yourPlugin',
component: YourPlugin,
position: PluginPosition.Header,
});
grid.forceRender();
https://gridjs.io/docs/plugins/basics/#adding-a-plugin
unfortunately.. it will throw a error for duplicate id for plugin.
Even if i remove the existing plugins first and add them after it wont get rendered again.
I just need fetch server instead of completely rendering the table but unfortunately that also does not exists.
I found a workaround for everyone who is interested:
Reset your div / element and reset the gridjs object. After rebuild it with forceRender. This way it completely rebuilds with new config and plugins.
Example:
// Standard grid
let element = document.querySelector('.table');
let options = {};
let grid = new Grid(options);
grid.render(element);
// Rebuild with new config
grid = null;
element.innerHTML = '';
let grid = new Grid(options);
grid.render(element);
grid.forceRender();
Could you pull this branch #1267 and test please? I believe that branch should solve the issue.