Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
Create generic IgxGrid Wrapper Component
posted

I want to create a wrapper for IgxGrid component which will have customizable inputs.

https://stackblitz.com/edit/angular-n71deq

Here is the stackblitz link which contains my problem. I have a component app-grid-wrapper which will contain igx-grid and another component which will pass <igx-column> as content wrapped inside the tag which will then show the columns as projection inside <igx-grid>. But using this approach breaks the application with the error.

NullInjectorError: No provider for InjectionToken IgxGridBaseToken!.

Is there any way this can be achieved. Thanks

Parents
No Data
Reply
  • 700
    Offline posted

    Hello Ammar,

    Thank you for posting into our community!

    I have been looking into your question and what I could say is that the reason for receiving this error is due to the IgxColumnComponent expects to be defined in an IgxGridComponent in order for it to work properly.

    Having this in mind, an approach I could suggest is defining the columns in an array in the ts file and dynamically generating them with a *ngFor loop in the component that holds the IgxGrid, i.e., the grid wrapper. Then, a property with an @Input decorator should be defined, which will be used for binding the columns array to the one used by the *ngFor loop.

    Additionally, in order to demonstrate my suggestion, I have prepared a small sample using the abovementioned approach and it could be found here.

    Please test it on your side and let me know if you need any further assistance regarding this matter.

    Looking forward to your reply.

    Sincerely,
    Riva Ivanova
    Associate Software Developer

Children