代码之家  ›  专栏  ›  技术社区  ›  A_J

使用ngFor kendo grid angular 2为特定列提供宽度和ng模板?

  •  0
  • A_J  · 技术社区  · 6 年前

    通常当我使用单独的 kendo-grid-column 我可以轻松给出的每一列的标签 [width] 任何特定列的ng模板如何使用ngFor kendo grid ANGLACH 2为特定列提供宽度和ng模板?以剑道文档为例 https://www.telerik.com/kendo-angular-ui/components/grid/columns/

    @Component({
      selector: 'my-app',
      template: `
          <kendo-grid
            [kendoGridBinding]="gridData"
            [filterable]="true"
            scrollable="none"
            >
            <kendo-grid-column
              *ngFor="let column of columns"
              field="{{column.field}}"
              title="{{column.title}}"
              format="{{column.format}}"
              filter="{{column.type}}"
            ></kendo-grid-column>
          </kendo-grid>
      `
    })
    export class AppComponent {
      public gridData: any[] = sampleProducts;
    
      public columns: ColumnSetting[] = [
        {
          field: 'ProductName',
          title: 'Product Name',
          type: 'text'
        }, {
          field: 'UnitPrice',
          format: '{0:c}',
          title: 'Unit Price',
          type: 'numeric'
        }, {
          field: 'FirstOrderedOn',
          format: '{0:d}',
          title: 'First Ordered',
          type: 'date'
        }
      ];
    }
    

    剑道网格柱 标记,它将适用于所有列,但我只希望它适用于特定列。我该怎么做?

    1 回复  |  直到 6 年前
        1
  •  2
  •   topalkata    6 年前

    您也可以使用与其他属性相同的方法-只需从 阵列:

    <kendo-grid-column
              *ngFor="let column of columns"
              field="{{column.field}}"
              title="{{column.title}}"
              format="{{column.format}}"
              filter="{{column.type}}"
              width="{{column.width}}"
            ></kendo-grid-column>
    
    public columns: ColumnSetting[] = [
        {
          field: 'ProductName',
          title: 'Product Name',
          type: 'text'
        }, {
          field: 'UnitPrice',
          format: '{0:c}',
          title: 'Unit Price',
          type: 'numeric',
          width: 300
        }, {
          field: 'FirstOrderedOn',
          format: '{0:d}',
          title: 'First Ordered',
          type: 'date'
        }
      ];
    

    UPDATED EXAMPLE