<ContentView x:Name="contentView"
HorizontalOptions="StartAndExpand"
VerticalOptions="StartAndExpand"
WidthRequest="300" HeightRequest="400">
<sfgrid:SfDataGrid x:Name="dataGrid"
ItemsSource="{Binding OrdersInfo}"
AutoGenerateColumns="True"
AllowSorting="True"
SelectionMode="Single" >
</sfgrid:SfDataGrid>
</ContentView> |
double totalRowHeight = 0;
double totalColumnWidth = 0;
dataGrid.SizeChanged += DataGrid_SizeChanged;
private void DataGrid_SizeChanged(object sender, EventArgs e)
{
if (totalRowHeight == 0 && totalColumnWidth == 0)
{
for (int i = 0; i <= this.dataGrid.View.Records.Count; i++)
totalRowHeight += dataGrid.RowHeight;
for (int i = 0; i < this.dataGrid.Columns.Count; i++)
totalColumnWidth += dataGrid.Columns[i].ActualWidth + (dataGrid.ShowRowHeader ? dataGrid.RowHeaderWidth : 0);
contentView.WidthRequest = Math.Min(totalColumnWidth, dataGrid.Width);
contentView.HeightRequest = Math.Min(totalRowHeight, dataGrid.Height);
}
} |
Hi,
I have multiple questions.
1. Is it possible to customise sfdata grid to show it in the below format. The text that is masked is the table header. The intersecting points for rows and columns are cut. Is this possible.
2. I want to set a common background for the whole sfdatagrid. How to achieve this.
3. As far as the System.OverflowException is concerned, I do see it occuring once in a while when I scroll the sfdatagrid horizontally couple of times. PFB the code snippet.
xaml:
<Grid xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="XamarinPOCPEApp.UserControls.PayoutWidget"
xmlns:local="clr-namespace: XamarinPOCPEApp;assembly=XamarinPOCPEApp"
xmlns:sfgrid="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms">
<Grid Margin="5,5,5,5" RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<BoxView Color="#f2f2f2" />
<Grid Grid.Row="0">
<Label HorizontalTextAlignment="Center" VerticalTextAlignment="Center" TextColor="#303030" FontSize = "16" Text="Payout Details" />
</Grid>
<sfgrid:SfDataGrid Grid.Row="1" x:Name="dataGrid" AutoGenerateColumns="False"
ColumnSizer="Auto" ItemsSource="{Binding OrderInfoCollection}" VerticalOptions="FillAndExpand" FrozenColumnsCount="1" HeightRequest="100" >
<sfgrid:SfDataGrid.Columns >
<sfgrid:GridTextColumn MappingName="TimeFrame" HeaderText="Time Frame" />
<sfgrid:GridTextColumn MappingName="YTDEarnings" HeaderText="YTD Earnings" />
<sfgrid:GridTextColumn MappingName="Advances" HeaderText="Advances" />
<sfgrid:GridTextColumn MappingName="Adjustments" HeaderText="Adjustments" />
<sfgrid:GridTextColumn MappingName="PayrollPayment" HeaderText="Payroll Payment" />
</sfgrid:SfDataGrid.Columns>
</sfgrid:SfDataGrid>
</Grid>
</Grid>
Code behind:
public partial class PayoutWidget : Grid
{
double totalRowHeight = 0;
public PayoutWidget()
{
InitializeComponent();
dataGrid.GridLoaded += DataGrid_GridLoaded;
}
private void DataGrid_GridLoaded(object sender, EventArgs e)
{
for (int i = 0; i <= this.dataGrid.View.Records.Count; i++)
totalRowHeight += dataGrid.RowHeight;
dataGrid.HeightRequest = totalRowHeight;
}
}