reusable header templates and column templates

Hello,

I am creating a grid, building the columns in typescript to have multilevel stacked header dynamically

i want to include templates for some columns and headers

i need input controls eg: input box and need to handle events also in these templates

i want to use single template for multiple columns as the columns are created dynamically


Please provide a sample for the above mentioned requirements




5 Replies

RR Rajapandi Ravi Syncfusion Team January 19, 2024 01:02 PM UTC

Hi Karthik,


Greetings from Syncfusion support


After reviewing your query, we could see that you like to define single template and reusable for all columns. Based on your query we have prepared a sample and used the single column template definition for all columns. Please refer the below code example and sample for more information.


App.component.ts

 

export class AppComponent {

    @ViewChild('template', { static: true })

    public template: TemplateRef<{}>;

    public data: Object[] = [];

    public orderColumns: ColumnModel[];

    public shipColumns: ColumnModel[];

    public columns: any;

 

    public ngOnInit(): void {

        this.data = orderDetails;

        this.columns = [{field: 'OrderID', headerText: 'Order ID', width: 150, template: this.template}, {headerText: 'Order Details', columns: [

            {

                field: 'OrderDate',

                headerText: 'Order Date',

                format: 'yMd',

                width: 130,

                textAlign: 'Right',

                minWidth: 10

            },

            {

                field: 'Freight',

                headerText: 'Freight ($)',

                width: 120,

                format: 'C1',

                textAlign: 'Right',

                minWidth: 10,

                template: this.template,

            }

        ]}, {headerText: 'Ship Details', columns: [

            {

                field: 'ShippedDate',

                headerText: 'Shipped Date',

                format: 'yMd',

                textAlign: 'Right',

                width: 150,

                minWidth: 10,

                template: this.template,

            },

            {

                field: 'ShipCountry',

                headerText: 'Ship Country',

                width: 150,

                minWidth: 10,

                template: this.template,

            }

        ]}];

    }

 

 


App.component.html

 

<div class="control-section">

    <ejs-grid [dataSource]="data" [columns]="columns" [allowPaging]='true' [allowResizing]="true">

    </ejs-grid>

 

    <ng-template #template let-data>

        <input type="text" id="data.OrderID" [value]="data[data.column.field]" (input)="onInput($event)" />

      </ng-template>

</div>

 


Sample: https://stackblitz.com/edit/angular-2mntr3-lxnkii?file=src%2Fapp.component.ts,src%2Fapp.component.html


Screenshot:



Regards,

Rajapandi R



KA Karthik August 26, 2024 03:08 PM UTC

Hello Rajapandi R,


It looks cool, do we an similar option for footer template??


Regards,

Karthik



RR Rajapandi Ravi Syncfusion Team August 27, 2024 08:34 AM UTC

Karthik,


After reviewing your query, it appears you want to define a single footer template for Aggregates and reuse it across several columns. To address this, we've created a sample where a single footer template is applied to several columns. Please refer to the code example and sample provided below for more details.


App.component.ts

 

@ViewChild('footerTemplate', { static: true })

public footerTemplate: TemplateRef<{}>;

 

public aggregates: any;

 

    public ngOnInit(): void {

        this.data = orderDetails;

        this.aggregates = [{

            columns: [{

                type: 'Sum',

                field: 'Freight',

                footerTemplate: this.footerTemplate

            },

            {

                type: 'Sum',

                field: 'OrderID',

                footerTemplate: this.footerTemplate

            }]

        }];

 

App.component.html

 

<ejs-grid [dataSource]="data" [columns]="columns" [allowPaging]='true' [aggregates]='aggregates' [allowResizing]="true">

    </ejs-grid>

 

      <ng-template #footerTemplate let-data>

          Sum: {{data.Sum}}

        </ng-template>


Sample: https://stackblitz.com/edit/angular-2mntr3-c7rj9v?file=src%2Fapp.component.ts,src%2Fapp.component.html


Screenshot:




KA Karthik August 27, 2024 09:52 AM UTC

Hello Rajapandi R,

Thanks for the update, it works, 

However it is super slow, i am updating the grid using setcellvalue from high frequency updates from server.

i used custom aggregate type as well, but still the performace is still the same.

is there any alternative to display footer for all the visible columns in the grid without aggregate, i can calculate the values on my own,

or is there any way to freeze the bottom two or three rows, so that i can caluclate the values and update them ?


Regards,

Karthik



AR Aishwarya Rameshbabu Syncfusion Team August 29, 2024 01:49 PM UTC

Karthik,


After reviewing the information you provided, we understand that you are experiencing a performance issue. To assist you more effectively, we need some additional details for clarification. Please share the following information, which will help us offer a more suitable solution.


1)            Share your complete rendering code (including app.component.ts, app.component.html files) along with event handler and template functions utilized.

2)            Since you are using remote data, kindly share the adaptor details.

3)            Please provide details on the number of columns and records you are binding in the Grid. Additionally, let us know how many of these columns are using a column template.

4)            Share your Syncfusion package version.
5)            We have already covered performance tips in our documentation. For more information, please refer to the documentation linked below.
                Documentation: https://ej2.syncfusion.com/angular/documentation/grid/performance

6)            In your query you have mentioned that “is there any way to freeze the bottom two or three rows”, we can be able to freeze the rows on the top by using the Frozen feature in the Grid. Please refer the below sample demos for more information.
                Sample demos: https://ej2.syncfusion.com/angular/demos/#/fluent2/grid/frozen-api
                                             https://ej2.syncfusion.com/angular/demos/#/fluent2/grid/frozen-rows-columns



Regards,

Aishwarya R


Loader.
Up arrow icon