Recent

Custom Controls Using Angular Material

Git Repo:  https://github.com/yawahang/ohcontrols Features DatePicker (Date Picker, Time Picker, Date Time Picker, and many more) RatingPicker (Vertical, Horizontal, Custom Icons) Select (Single Select, MultiSelect, Single Column, MultiColumn) Recursive Treeview

Kendo Grid AutoFit Columns

https://stackblitz.com/edit/angular-prf8kx-nlbjax?embed=1&file=app/app.component.ts

import { Component } from "@angular/core";
import { sampleProducts } from "./products";
import { GridComponent } from "@progress/kendo-angular-grid";

@Component({
  selector: "my-app",

  template: `
    <kendo-grid
      #grid
      [data]="gridData"
      [resizable]="true"
      style="height: 300px"
    >
      <kendo-grid-column
        *ngFor="let column of columns; trackBy: dynamicColumns(grid)"
        field="{{ column.Name }}"
        title="{{ column.Display }}"
      >
        // {{ dynamicColumns(grid, column) }}
      </kendo-grid-column>
    </kendo-grid>
  `
})
export class AppComponent {
  public gridData: any[] = sampleProducts;

  public columns: any = [
    {
      Name: "ProductName",
      Display: "Product Name",
      Type: "text",
      Sort: true,
      ColumnWidth: 100
    },
    {
      Name: "QuantityPerUnit",
      Display: "Quantity PerUnit",
      Type: "text",
      Sort: true,
      ColumnWidth: 110
    },
    {
      Name: "UnitPrice",
      Display: "Unit Price",
      Type: "text",
      Sort: true,
      ColumnWidth: 120
    },
    {
      Name: "UnitsInStock",
      Display: "Units InStock",
      Type: "text",
      Sort: true,
      ColumnWidth: 130
    },
    {
      Name: "FirstOrderedOn",
      Display: "First OrderedOn",
      Type: "text",
      Sort: true,
      ColumnWidth: 140
    },
    {
      Name: "UnitPrice",
      Display: "Unit Price",
      Type: "text",
      Sort: true,
      ColumnWidth: 150
    }
  ];

  dynamicColumns(grid: GridComponent) {
    if (grid) {
      grid.autoFitColumns();
    }
  }
}

Comments

Top Posts

SQL Server Symmetric Key & Certificate based Encryption With AES_256 Algorithm

Kendo Grid Angular Column Width, minResizableWidth dynamic