<datagrid:SfDataGrid x:Name="dataGrid"
ColumnSizer="Star"
HeaderRowHeight="0"
GridLoaded="DataGrid_GridLoaded"
AllowGroupExpandCollapse="True"
AutoGenerateColumns="False"
RowHeight="90"
ItemsSource="{Binding OrderInfoCollection, Mode=TwoWay}" >
<datagrid:SfDataGrid.Columns x:TypeArguments="syncfusion:Columns">
<datagrid:GridTemplateColumn MappingName="ShipCountry">
<datagrid:GridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Frame Grid.Column="0"
BorderColor="Tomato"
CornerRadius="8"
Padding="3"
HeightRequest="50"
HasShadow="True">
<Entry Text="{Binding Customer}" HeightRequest="50"/>
</Frame>
<Switch Grid.Column="1" />
</Grid>
</DataTemplate>
</datagrid:GridTemplateColumn.CellTemplate>
</datagrid:GridTemplateColumn>
</datagrid:SfDataGrid.Columns>
<datagrid:SfDataGrid.GroupColumnDescriptions>
<datagrid:GroupColumnDescription ColumnName="ShipCountry"/>
</datagrid:SfDataGrid.GroupColumnDescriptions>
<datagrid:SfDataGrid.CaptionSummaryTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal">
<Label Grid.Column="1"
TextColor="Black"
BackgroundColor="White"
Text="{Binding Converter={StaticResource customconverter}, ConverterParameter={x:Reference dataGrid}}"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Start"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Label.Style>
<Style TargetType="Label">
<Setter Property="FontAttributes" Value="Bold,Italic"/>
</Style>
</Label.Style>
</Label>
</StackLayout>
</DataTemplate>
</datagrid:SfDataGrid.CaptionSummaryTemplate>
<datagrid:SfDataGrid.CaptionSummaryRow>
<datagrid:GridSummaryRow Name="CaptionSummary"
Title="ShipCountry"
ShowSummaryInRow="true">
<datagrid:GridSummaryRow.SummaryColumns>
<datagrid:GridSummaryColumn Name="ShipCountry"
Format="{}{Count}"
MappingName="ShipCountry"
SummaryType="CountAggregate"/>
</datagrid:GridSummaryRow.SummaryColumns>
</datagrid:GridSummaryRow>
</datagrid:SfDataGrid.CaptionSummaryRow>
</datagrid:SfDataGrid> |
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
dataGrid.GridStyle = new CustomStyle();
}
private void DataGrid_GridLoaded(object sender, GridLoadedEventArgs e)
{
dataGrid.CollapseAllGroup();
}
}
/// <summary>
/// Converter for the caption summary rows.
/// </summary>
public class CustomConverter : IValueConverter
{
public CustomConverter()
{
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var data = value != null ? value as Group : null;
if (data != null)
{
SfDataGrid dataGrid = (SfDataGrid)parameter;
return data.Key + " - " + data.ItemsCount + " Items";
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
/// <summary>
/// Style class to customize SfDatagrid.
/// </summary>
public class CustomStyle : DataGridStyle
{
public CustomStyle()
{
}
public override ImageSource GetGroupCollapseIcon()
{
return ImageSource.FromResource("SfGridSample.GroupCollapser.png");
}
public override ImageSource GetGroupExpanderIcon()
{
return ImageSource.FromResource("SfGridSample.GroupExpander.png");
}
public override Color GetBorderColor()
{
return Color.Transparent;
}
}
|