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

Extend or override existing services #585

Open
richardliebmann opened this issue Sep 30, 2024 · 2 comments
Open

Extend or override existing services #585

richardliebmann opened this issue Sep 30, 2024 · 2 comments
Labels
doc Improvements or additions to documentation feature New feature or request question Further information is requested

Comments

@richardliebmann
Copy link

It would be great to be able to extend or override the internal services of revogrid. It's currently possible to hook into the events and customise the grid for our needs, but for some changes it would be great to change the default behaviour.

For example:
Change the autofill behaviour to automatically increment the value instead of just copying the value.

Currently we can hook into the beforeautofill event and add some custom logic, but it's quite complex.

onBeforeAutoFill($event: Event) {
  const detail: { colType: "rgCol", type: "rgRow", newData: { [key: number]: { [key: string]: unknown } }, oldRange: { x: number, y: number, x1: number, y1: number }, newRange: { x: number, y: number, x1: number, y1: number }, mapping: { [key: number]: { [key: string]: { colProp: string, rowIndex: number, colIndex: number } } } } = ($event as any).detail;

  // only single column supported
  if (detail.oldRange.x != detail.oldRange.x1 || detail.oldRange.y != detail.oldRange.y1 || detail.newRange.x != detail.newRange.x1) {
    $event.preventDefault();
    return;
  }

  let i = 0;

  for (const idx in detail.mapping) {
    const newData = detail.newData[idx];

    const keys = Object.keys(newData);

    if (keys.length != 1) {
      $event.preventDefault();
      return;
    }

    const key = keys[0];
    const mapping = detail.mapping[idx];
    const myMapping = mapping[key];

    if (key == "number") {
      const value = newData[key];

      const newValue = value + index + 1

      newData[key] = newValue
    }

    i++;
  }
}
@m2a2x
Copy link
Collaborator

m2a2x commented Oct 1, 2024

Hi @richardliebmann
How do you propose to expose this service?

ATM when I want to overwrite it I just make a plugin and drop original event replacing it with mine. So technically it's getting to be a small service of mine instead of the one from core

I want to understand which approach seems more favorable from your perspective and we can consider this in the future

Thanks for giving feedback very much appreciated!

@m2a2x m2a2x added doc Improvements or additions to documentation feature New feature or request question Further information is requested labels Oct 1, 2024
@richardliebmann
Copy link
Author

Hi @m2a2x,

Thanks for your reply! Yes, most cases will be covered by a plugin. But in my example above, the service already does a great job and only a small change would be required. My code in a plugin or outside will require a much more complex and larger solution.

It would be great to have a simple dependency injection system where I'm only able to override a small part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Improvements or additions to documentation feature New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants