Class GridTemplateColumn
Represents a SfDataGrid column that hosts template-specified Content in its cells.
Implements
Inherited Members
Namespace: Syncfusion.SfDataGrid.XForms
Assembly: Syncfusion.SfDataGrid.XForms.dll
Syntax
public class GridTemplateColumn : GridColumn, IDisposable
Remarks
Use GridTemplateColumn to display the value in the template of your requirement.
The GridTemplateColumn type enables you to create your own column types by specifying the cell template or cell template selector to use for displaying value. To specify the template that is used to display the contents of a cell, set the CellTemplate property. and to set the template selector, use CellTemplateSelector property.
Examples
<syncfusion:GridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Text = "{Binding CustomerID}"
TextColor="Black"
XAlign="Center"
YAlign="Center" />
</DataTemplate>
</syncfusion:GridTemplateColumn.CellTemplate>
Constructors
GridTemplateColumn()
Initializes a new instance of the GridTemplateColumn class.
Declaration
public GridTemplateColumn()
Properties
CellTemplate
Gets or sets the template that is used to display the contents of a cell.
Declaration
public DataTemplate CellTemplate { get; set; }
Property Value
Type | Description |
---|---|
Xamarin.Forms.DataTemplate | The Xamarin.Forms.DataTemplate that is used to display the contents of a cell. |
Remarks
SfDataGrid allows the user to customize the GridColumn with your own view by setting the CellTemplate of GridTemplateColumn. To specify the template that is used to display the contents of a cell, set the CellTemplate property.
Examples
<syncfusion:SfDataGrid.Columns>
<syncfusion:GridTemplateColumn MappingName="CustomerID">
<syncfusion:GridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Text = "{Binding CustomerID}" TextColor="Black"
XAlign="Center" YAlign="Center" />
</DataTemplate>
</syncfusion:GridTemplateColumn.CellTemplate>
</syncfusion:GridTemplateColumn>
</syncfusion:SfDataGrid.Columns>
See Also
CellTemplateSelector
Gets or sets the template selector that selects the template in which the Content of the cell to be displayed.
Declaration
public DataTemplateSelector CellTemplateSelector { get; set; }
Property Value
Type | Description |
---|---|
Xamarin.Forms.DataTemplateSelector | The Xamarin.Forms.DataTemplateSelector that selects the template in which the Content of the cell to be displayed. |
Remarks
SfDataGrid allows the user to customize the GridColumn with your own view by setting the CellTemplateSelector of GridTemplateColumn. When the user wants to select the template between the available templates based on the value in the underlying collection, the user can use this property. The Content of the cell will be displayed in the template selected.
Examples
<ContentPage.Resources>
<ResourceDictionary>
<DataTemplate x:Key="low" >
<Label Text = "{Binding Freight}"
TextColor="White"
BackgroundColor="Red"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center" />
</DataTemplate>
<DataTemplate x:Key="average" >
<Label Text = "{Binding Freight}"
TextColor="Black"
BackgroundColor="Yellow"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center" />
</DataTemplate>
<DataTemplate x:Key="high" >
<Label Text = "{Binding Freight}"
TextColor="White"
BackgroundColor="Green"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center" />
</DataTemplate>
</ResourceDictionary>
</ContentPage.Resources>
<syncfusion:SfDataGrid.Columns>
<sfgrid:GridTemplateColumn MappingName = "Freight">
<sfgrid:GridTemplateColumn.CellTemplateSelector>
<local:FreightTemplateSelector High = "{StaticResource high}"
Average="{StaticResource average}"
Low="{StaticResource low}"/>
</sfgrid:GridTemplateColumn.CellTemplateSelector>
</sfgrid:GridTemplateColumn>
</syncfusion:SfDataGrid.Columns>
See Also
EditTemplate
Gets or sets the Xamarin.Forms.DataTemplate to load in editing mode.
Declaration
public DataTemplate EditTemplate { get; set; }
Property Value
Type | Description |
---|---|
Xamarin.Forms.DataTemplate | The template that is used to display the contents of cell in a column that is in editing mode. The default is null. |
Remarks
To specify the template that is used to display the contents of a cell when entering edit mode, set the EditTemplate property.
Examples
<syncfusion:SfDataGrid.Columns>
<syncfusion:GridTemplateColumn MappingName="CustomerID">
<syncfusion:GridTemplateColumn.EditTemplate>
<DataTemplate>
<Entry Text = "{Binding CustomerID}" />
</ DataTemplate >
</ syncfusion:GridTemplateColumn.EditTemplate>
</syncfusion:GridTemplateColumn>
</syncfusion:SfDataGrid.Columns>
EditTemplateSelector
Gets or sets the Xamarin.Forms.DataTemplateSelector by choosing a template based on bound data objects and data-bound element in editing mode.
Declaration
public DataTemplateSelector EditTemplateSelector { get; set; }
Property Value
Type | Description |
---|---|
Xamarin.Forms.DataTemplateSelector | A custom Xamarin.Forms.DataTemplateSelector object that provides logic and returns a Xamarin.Forms.DataTemplate that is in edit mode of column. The default is null. |
Remarks
SfDataGrid can customize the GridColumn with any view by setting the EditTemplateSelector of GridTemplateColumn.
Examples
<ContentPage.Resources>
<ResourceDictionary>
<DataTemplate x:Key="low" >
<Label Text = "{Binding Freight}"
TextColor="White"
BackgroundColor="Red"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center" />
</DataTemplate>
<DataTemplate x:Key="average" >
<Label Text = "{Binding Freight}"
TextColor="Black"
BackgroundColor="Yellow"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center" />
</DataTemplate>
<DataTemplate x:Key="high" >
<Label Text = "{Binding Freight}"
TextColor="White"
BackgroundColor="Green"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center" />
</DataTemplate>
</ResourceDictionary>
</ContentPage.Resources>
<syncfusion:SfDataGrid.Columns>
<sfgrid:GridTemplateColumn MappingName="Freight" >
<sfgrid:GridTemplateColumn.EditTemplateSelector>
<local:FreightTemplateSelector High = "{StaticResource high}"
Average="{StaticResource average}"
Low="{StaticResource low}"/>
</sfgrid:GridTemplateColumn.EditTemplateSelector>
</sfgrid:GridTemplateColumn>
</syncfusion:SfDataGrid.Columns>
Methods
CanEditCell()
Determines whether the column is editable.
Declaration
protected override bool CanEditCell()
Returns
Type | Description |
---|---|
System.Boolean | Returns true if all the cells with in the column is editable . |