Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugins disappear after updating config. #1260

Open
somegooser opened this issue Dec 13, 2022 · 5 comments
Open

Plugins disappear after updating config. #1260

somegooser opened this issue Dec 13, 2022 · 5 comments
Labels
bug fix Something isn't working

Comments

@somegooser
Copy link

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
Copy link
Author

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

@MehdiBenbahri
Copy link

MehdiBenbahri commented Jan 5, 2023

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

@somegooser
Copy link
Author

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
Copy link
Author

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

@afshinm afshinm added the bug fix Something isn't working label Jan 10, 2023
@afshinm
Copy link
Member

afshinm commented Jan 10, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants