[]
        
(Showing Draft Content)

WjFlexGridCellTemplate Class

WjFlexGridCellTemplate Class

Angular 2 directive for the FlexGrid cell templates.

The wjFlexGridCellTemplate directive defines a template for a certain cell type in FlexGrid. The template should be defined on a <ng-template> element and must contain a cellType attribute that specifies the {@link wijmo.angular2.grid.CellTemplateType}. Depending on the template's cell type, the <ng-template> element with the wjFlexGridCellTemplate directive must be a child of either wijmo.angular2.grid.WjFlexGrid or wijmo.angular2.grid.WjFlexGridColumn components.

Column-specific cell templates must be contained in wj-flex-grid-column components, and cells that are not column-specific (like row header or top left cells) must be contained in the wj-flex-grid component.

The <ng-template> element with the wjFlexGridCellTemplate directive may contain an arbitrary HTML fragment with Angular 2 interpolation expressions and other components and directives.

Bindings in HTML fragment can use the cell local template variable containing the cell context object, with col, row, and item properties that refer to the Column, Row, and Row.dataItem objects pertaining to the cell.

For cell types like Group and CellEdit, an additional value property containing an unformatted cell value is provided. For example, here is a FlexGrid control with templates for row header cells and, regular and column header cells of the Country column:

// component.ts
import * as wjGrid from '@mescius/wijmo.angular2.grid';

@Component({
    templateUrl: './component.html',
    selector: 'my-cmp',
})
export class MyCmp {
    data: any[];
}
<!-- component.html -->
<wj-flex-grid [itemsSource]="data">
  <ng-template wjFlexGridCellTemplate [cellType]="'RowHeader'" let-cell="cell">
    {{cell.row.index}}
  </ng-template>
  <ng-template wjFlexGridCellTemplate [cellType]="'RowHeaderEdit'">
    ...
  </ng-template>

  <wj-flex-grid-column [header]="'Country'" [binding]="'country'">
    <ng-template wjFlexGridCellTemplate [cellType]="'ColumnHeader'" let-cell="cell">
      <img src="resources/globe.png" />
        {{cell.col.header}}
    </ng-template>
    <ng-template wjFlexGridCellTemplate [cellType]="'Cell'" let-cell="cell">
      <img src="resources/{{cell.item.country}}.png" />
      {{cell.item.country}}
    </ng-template>
  </wj-flex-grid-column>
  <wj-flex-grid-column [header]="'Sales'" [binding]="'sales'"></wj-flex-grid-column>
</wj-flex-grid>

The cellType attribute takes any of the following enumerated values:

Cell

Defines a regular (data) cell template. Must be a child of the wijmo.angular2.grid.WjFlexGridColumn component. For example, this cell template shows flags in the cells of Country column:

<wj-flex-grid-column [header]="'Country'" [binding]="'country'">
  <ng-template wjFlexGridCellTemplate [cellType]="'Cell'" let-cell="cell">
    <img src="resources/{{cell.item.country}}.png" />
    {{cell.item.country}}
  </ng-template>
</wj-flex-grid-column>

If Group template is not provided for a hierarchical FlexGrid (that is, one with the childItemsPath property specified), non-header cells in group rows of this Column also use this template.

CellEdit

Defines a template for a cell in edit mode. Must be a child of the wijmo.angular2.grid.WjFlexGridColumn component. This cell type has an additional cell.value property available for binding. It contains the original cell value before editing, and the updated value after editing.

For example, here is a template that uses the Wijmo InputNumber control as an editor for the "Sales" column:

<wj-flex-grid-column [header]="'Sales'" [binding]="'sales'">
  <ng-template wjFlexGridCellTemplate [cellType]="'CellEdit'">
    <wj-input-number [(value)]="cell.value" [step]="1"></wj-input-number>
  </ng-template>
</wj-flex-grid-column>

ColumnHeader

Defines a template for a column header cell. Must be a child of the wijmo.angular2.grid.WjFlexGridColumn component. For example, this template adds an image to the header of the "Country" column:

<wj-flex-grid-column [header]="'Country'" [binding]="'country'">
  <ng-template wjFlexGridCellTemplate [cellType]="'ColumnHeader'" let-cell="cell">
    <img src="resources/globe.png" />
    {{cell.col.header}}
  </ng-template>
</wj-flex-grid-column>

RowHeader

Defines a template for a row header cell. Must be a child of the wijmo.angular2.grid.WjFlexGrid component. For example, this template shows row indices in the row headers:

<wj-flex-grid [itemsSource]="data">
  <ng-template wjFlexGridCellTemplate [cellType]="'RowHeader'" let-cell="cell">
    {{cell.row.index + 1}}
  </ng-template>
</wj-flex-grid>

Note that this template is applied to a row header cell, even if it is in a row that is in edit mode. In order to provide an edit-mode version of a row header cell with alternate content, define the RowHeaderEdit template.

RowHeaderEdit

Defines a template for a row header cell in edit mode. Must be a child of the wijmo.angular2.grid.WjFlexGrid component. For example, this template shows dots in the header of rows being edited:

<wj-flex-grid [itemsSource]="data">
  <ng-template wjFlexGridCellTemplate [cellType]="'RowHeaderEdit'">
    ...
  </ng-template>
</wj-flex-grid>

Use the following RowHeaderEdit template to add the standard edit-mode indicator to cells where the RowHeader template applies:

<wj-flex-grid [itemsSource]="data">
  <ng-template wjFlexGridCellTemplate [cellType]="'RowHeaderEdit'">
    {{&amp;#x270e;}}
  </ng-template>
</wj-flex-grid>

TopLeft

Defines a template for the top left cell. Must be a child of the wijmo.angular2.grid.WjFlexGrid component. For example, this template shows a down/right glyph in the top-left cell of the grid:

<wj-flex-grid [itemsSource]="data">
  <ng-template wjFlexGridCellTemplate [cellType]="'TopLeft'">
    <span class="wj-glyph-down-right"></span>
  </ng-template>
</wj-flex-grid>

GroupHeader

Defines a template for a group header cell in a GroupRow. Must be a child of the wijmo.angular2.grid.WjFlexGridColumn component.

The cell.row property contains an instance of the GroupRow class. If the grouping comes from CollectionView, the cell.item property references the CollectionViewGroup object.

For example, this template uses a checkbox element as an expand/collapse toggle:

<wj-flex-grid-column [header]="'Country'" [binding]="'country'">
  <ng-template wjFlexGridCellTemplate [cellType]="'GroupHeader'" let-cell="cell">
    <input type="checkbox" [(ngModel)]="cell.row.isCollapsed"/>
    {{cell.item.name}} ({{cell.item.items.length}} items)
  </ng-template>
</wj-flex-grid-column>

Group

Defines a template for a regular cell (not a group header) in a GroupRow. Must be a child of the wijmo.angular2.grid.WjFlexGridColumn component. This cell type has an additional cell.value property available for binding. In cases where columns have the aggregate property specified, it contains the unformatted aggregate value.

For example, this template shows aggregate's value and kind for group row cells in the "Sales" column:

<wj-flex-grid-column [header]="'Sales'" [binding]="'sales'" [aggregate]="'Avg'">
  <ng-template wjFlexGridCellTemplate [cellType]="'Group'" let-cell="cell">
    Average: {{cell.value | number:'1.0-0'}}
  </ng-template>
</wj-flex-grid-column>

ColumnFooter

Defines a template for a regular cell in a columnFooters panel. Must be a child of the wijmo.angular2.grid.WjFlexGridColumn component. This cell type has an additional cell.value property available for binding that contains a cell value.

For example, this template shows aggregate's value and kind for a footer cell in the "Sales" column:

<wj-flex-grid-column [header]="'Sales'" [binding]="'sales'" [aggregate]="'Avg'">
  <ng-template wjFlexGridCellTemplate [cellType]="'ColumnFooter'" let-cell="cell">
    Average: {{cell.value | number:'1.0-0'}}
  </ng-template>
</wj-flex-grid-column>

BottomLeft

Defines a template for the bottom left cells (at the intersection of the row header and column footer cells). Must be a child of the wijmo.angular2.grid.WjFlexGrid component. For example, this template shows a sigma glyph in the bottom-left cell of the grid:

<wj-flex-grid [itemsSource]="data">
  <ng-template wjFlexGridCellTemplate [cellType]="'BottomLeft'">
    &amp;#931;
  </ng-template>
</wj-flex-grid>

NewCellTemplate

Defines a cell in a new row template. Must be a child of the wijmo.angular2.grid.WjFlexGridColumn component. Note that the cell.item property is undefined for this type of a cell. For example, this cell template shows a placeholder in the Date column's cell in the "new row" item:

<wj-flex-grid-column [header]="'Date'" [binding]="'date'">
  <ng-template wjFlexGridCellTemplate [cellType]="'NewCellTemplate'">
    Enter a date here
  </ng-template>
</wj-flex-grid-column>

Heirarchy

Properties

autoSizeRows

autoSizeRows: boolean

Gets or sets a value indicating whether the cell template will increase grid's default row height to accomodate cells content. Defaults to true.

cellOverflow

cellOverflow: string

Defines the style.overflow property value for cells.

cellType

cellType: any

Defines the type of cell to which the template is applied. String enum member names can be used to specify the property value as well.

forceFullEdit

forceFullEdit: boolean

For cell edit templates, indicates whether cell editing forcibly starts in full edit mode, regardless of how the editing was initiated. In full edit mode pressing cursor keys don't finish editing. Defaults to true.