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 Reply
  • 600
    Offline posted in reply to Ammar Hussain

    Hello Ammar,

    Thank you for following up!

    After further investigating this matter what I could say is that the IgxColumnComponent could be used inside the ts file, for example, like the following:

    <igx-grid
        #grid
        [data]="data"
        [autoGenerate]="true"
        (columnInit)="columnInit($event)" >
    </igx-grid>

    import { IgxColumnComponent } from 'igniteui-angular';
    
    public columnInit(column: IgxColumnComponent) {
        if (column.field === "ProductName") {
            column.filterable = true;
        }
    }

    However, as previously mentioned, when defining the columns as templates, they need to be defined inside the IgxGridComponent in order to work properly and as expected. It is not possible to dynamically create columns and assign them to the grid. The correct and recommended ways is by using templates or by using the autoGenerate property.

    Additionally, the suggestion from my initial message is an alternative approach for defining the columns in a separate component in the form of an array and dynamically generating them via *ngFor loop.

    Please let me know if you need any further assistance regarding this matter.

    Looking forward to your reply.

    Sincerely,
    Riva Ivanova
    Associate Software Developer

Children
No Data