- Home
- Forum
- Xamarin.Forms
- [SfDataPager] Calculate optimal PageSize so that there is no vertical scrollbar based on rotation?
[SfDataPager] Calculate optimal PageSize so that there is no vertical scrollbar based on rotation?
How can I calculate the optimal PageSize for the datapager so that there is no vertical scrollbar!!!! based on device rotation (more entries in portrait compared to landscape)?
VS2017 15.9.5
Xamarin.Forms 3.4.0.1009999
Syncfusion.Xamarin.SfDataGrid 16.4.0.42
VS2017 15.9.5
Xamarin.Forms 3.4.0.1009999
Syncfusion.Xamarin.SfDataGrid 16.4.0.42
.net standard 2.0 lib as shared project
Windows 10 1709 (UWP app MinVersion 16299/Target: 17763 with Microsoft.NETCore.UniversalWindowsPlatform Version 6.1.9)
SIGN IN To post a reply.
10 Replies
SP
Subburaj Pandian Veluchamy
Syncfusion Team
January 23, 2019 10:50 AM UTC
Hi Andre,
Thank you for contacting Syncfusion support.
We have checked query “Optimal way to calculate page size of the DataPager based on device orientation”, it can be achieved. Page size can be calculated based on datagrid height, please refer the following code example for the same.
|
[C#]
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (this.screenWidth != width && dataGrid.Width>0 || this.screenHeight != height && dataGrid.Height>0)
{
// Update page size when device orientation is changed
this.screenWidth = width;
this.screenHeight = height;
dataPager.PageSize= this.SetPageSize();
dataPager.ForceLayout();
}
}
private int SetPageSize()
{
return (int)((dataGrid.Height - (dataGrid.GetRowHeight(dataGrid.GetHeaderIndex()) - dataGrid.Padding.Top - dataGrid.Padding.Bottom)) / dataGrid.RowHeight);
} |
We have prepared a sample based on your requirement, you can download the same from the following link.
We hope this helps. Please let us know, if you have any concern.
Regards,
Subburaj Pandian V
Subburaj Pandian V
AZ
André Ziegler
January 23, 2019 02:06 PM UTC
Hi
I tried your demo, but I can't compile it in VS2017 15.9.5. When I add your function to my app I get the error message that GetRowHeight is not found as extension methode for SfDataGrid.
kind regards
André
I tried your demo, but I can't compile it in VS2017 15.9.5. When I add your function to my app I get the error message that GetRowHeight is not found as extension methode for SfDataGrid.
kind regards
André
AZ
André Ziegler
January 24, 2019 10:00 AM UTC
Hi,
I've added using statement
and now it works.
I've added using statement
| using Syncfusion.SfDataGrid.XForms; using Syncfusion.SfDataGrid.XForms.DataPager; |
and now it works.
But I forget that my sfdatagrid is inside a normal grid for layout (4 rows, grid is in 1)
| <xForms:SfDataGrid x:Name="dataGrid" Grid.Row="1" Grid.Column="0" AutoGeneratingColumn="dataGrid_AutoGeneratingColumn" AutoGenerateColumns="true" ColumnSizer="Auto" NavigationMode="Cell" SelectionMode="Single" VerticalOverScrollMode="None"> |
and with the code I get a value which still causes scrollbar.
JP
Jagadeesan Pichaimuthu
Syncfusion Team
January 24, 2019 11:28 AM UTC
Hi Andre,
Thanks for your update.
We have checked your query and we have prepared the sample with Xamarin.Forms 3.4, Syncfusion.Xamarin.SfDataGrid 16.4.0.42 and .net standard 2.0 and tested the sample in VS15.9.5. But we are not able to reproduce the reported “GetRowHeight is not found as extension method for SfDataGrid” issue. We have attached the sample for your reference and you can download the same from the below link. If still the issue reproduced from your side, please modify the attached sample and revert us. It will help us to provide the better solution.
Sample Link: http://www.syncfusion.com/downloads/support/forum/142120/ze/DataGridDemo_Pager1285937703
Regards,
JagadeesanHi Andre,
Thanks for your update.
We have checked your query and we have prepared the sample with Xamarin.Forms 3.4, Syncfusion.Xamarin.SfDataGrid 16.4.0.42 and .net standard 2.0 and tested the sample in VS15.9.5. But we are not able to reproduce the reported “GetRowHeight is not found as extension method for SfDataGrid” issue. We have attached the sample for your reference and you can download the same from the below link. If still the issue reproduced from your side, please modify the attached sample and revert us. It will help us to provide the better solution.
Sample Link: http://www.syncfusion.com/downloads/support/forum/142120/ze/DataGridDemo_Pager1285937703
Regards,Jagadeesan
Hi Jagadeesan,
as I said it works now and I can compile it. But I still have scrollbar, because I have the datagrid inside a nornal grid (grid has 4 rows and I put the datagrid in row 1, the sfdatapager in row 2 and in row 3 I have buttons to to some actions with the sellected row/cell)
André
AA
Arulraj A
Syncfusion Team
January 25, 2019 12:01 PM UTC
Hi Andre,
Thanks for your updated.
To achieve your requirement, you need to subtract the SfDataPager height in SfDataGrid height to calculated pagesize of the SfDataPager. So that the vertical scroll bar will not appear in the view. Please refer the following code example for the same.
|
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (this.screenWidth != width && dataGrid.Width > 0 || this.screenHeight != height && dataGrid.Height > 0)
{
this.screenWidth = width;
this.screenHeight = height;
dataPager.PageSize = this.SetPageSize();
dataPager.ForceLayout();
}
}
private int SetPageSize()
{
return (int)((dataGrid.Height - (dataGrid.GetRowHeight(dataGrid.GetHeaderIndex()) - dataGrid.Padding.Top - dataGrid.Padding.Bottom)- dataPager.Height) / dataGrid.RowHeight);
}
|
We have prepared the sample based on your requirement and attached for your reference. You can download the same from the below link.
Sample Link: http://www.syncfusion.com/downloads/support/forum/142120/ze/DataGridDemo_Pager1244719625
Let us know whether this helps also if you need any further assistance on this.
Regards,
Arulraj A
AZ
André Ziegler
February 22, 2019 11:11 AM UTC
Thanks for the reply,
it works fine for 1st view of a page, when I return back the SetPageSize returns different values, because
returns 2 different values.
On 1st call it return 20 and when I open a new page, navigate back it return 35.5 where all other data are the same:
dataGrid.Height = 615
this.screenWidth = 1663
this.screenHeight = 838
So what is dataGrid.GetRowHeight(dataGrid.GetHeaderIndex()) doing?
André
it works fine for 1st view of a page, when I return back the SetPageSize returns different values, because
| dataGrid.GetRowHeight(dataGrid.GetHeaderIndex()) |
returns 2 different values.
On 1st call it return 20 and when I open a new page, navigate back it return 35.5 where all other data are the same:
dataGrid.Height = 615
this.screenWidth = 1663
this.screenHeight = 838
So what is dataGrid.GetRowHeight(dataGrid.GetHeaderIndex()) doing?
André
PK
Pradeep Kumar Balakrishnan
Syncfusion Team
February 25, 2019 06:13 PM UTC
Hi André,
Thank you for the update.
We have checked the reported issue “GetRowHeight method is returning different value for header row height while loading and after navigating to another page.” And it was working fine from our side, and we have attached the sample which is used for testing.
In case, if you still experience the issue from your side, please modify the attached sample to reproduce the issue from your side so that it will be helpful for us to validate the issue and provide you solution at earlier.
Regards,
Pradeep Kumar B
AZ
André Ziegler
February 26, 2019 02:11 PM UTC
Thanks, I made a 2nd call in my code and this was a mistake. Now the function is only called once it works ok so far when I round the value:
| (int)Math.Round((dataGrid.Height - (dataGrid.GetRowHeight(dataGrid.GetHeaderIndex()) - dataGrid.Padding.Top - dataGrid.Padding.Bottom) - dataPager.Height) / dataGrid.RowHeight); |
André
SP
Subburaj Pandian Veluchamy
Syncfusion Team
February 27, 2019 05:55 AM UTC
Hi André,
Thank you for the update.
We are happy that the given solution has meet your requirement and resolved the issue at your end.
Please let us know, if you need any further assistance.
Regards,
Subburaj Pandian V
Subburaj Pandian V
SIGN IN To post a reply.
- 10 Replies
- 5 Participants
-
AZ André Ziegler
- Jan 21, 2019 09:49 AM UTC
- Feb 27, 2019 05:55 AM UTC