gridjs icon indicating copy to clipboard operation
gridjs copied to clipboard

Plugins disappear after updating config.

Open somegooser opened this issue 2 years ago • 5 comments

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}&current_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?

somegooser avatar Dec 13 '22 10:12 somegooser

@afshinm hi can you help me out please? i cant fix my issue :(

somegooser avatar Dec 13 '22 11:12 somegooser

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}&current_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

MehdiBenbahri avatar Jan 05 '23 08:01 MehdiBenbahri

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.

somegooser avatar Jan 05 '23 12:01 somegooser

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();

somegooser avatar Jan 05 '23 14:01 somegooser

Could you pull this branch #1267 and test please? I believe that branch should solve the issue.

afshinm avatar Jan 10 '23 21:01 afshinm