- Home
- Forum
- Xamarin.Forms
- Hide column based on content
Hide column based on content
Hello,
Is there a way to hide a column based on its content? For example, if all the cells in the column contains 0 or empty string
Thanks in advance.
SIGN IN To post a reply.
3 Replies
SK
Shivagurunathan Kamalakannan
Syncfusion Team
February 8, 2018 05:22 PM UTC
Hi Juan Carlos Gonzalez Salazar,
We have checked your query. Yes you can hide a column based on the column element. Your requirement can be achieved by the GridLoaded event. The grid loaded event triggers when the SfDataGrid has been loaded.
Refer the UG for more details:
Refer the below code for more details:
|
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
dataGrid.GridLoaded += DataGrid_GridLoaded;
}
private void DataGrid_GridLoaded(object sender, GridLoadedEventArgs e)
{
if (viewModel.OrderInfoCollection.All(x => x.CustomerID == ""))
dataGrid.Columns["CustomerID"].IsHidden = true;
}
}
|
We have prepared a sample based on your requirement and you can download the same from below link.
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SfGrid_Sample1661524288
Regards,
Shivagurunathan. K
JC
Juan Carlos Gonzalez Salazar
February 14, 2018 05:16 PM UTC
Hi Shivagurunathan,
I implemented something like this
foreach (GridColumn column in dataGridMonth.Columns)
{
var value = totals.GetType().GetProperty(column.MappingName).GetValue(totals, null);
if (!(value is double)) continue;
column.IsHidden = (double)value == 0;
}
But I'm having a lot of delay in the process of rendering. Is there something I can do to improve the performance?
SK
Shivagurunathan Kamalakannan
Syncfusion Team
February 15, 2018 02:48 PM UTC
Hi Juan Carlos Gonzalez Salazar,
We have checked your query. The Column can be hidden based on the data,
Eg: If all the values in a particular column are empty string. The required column can be hidden.
The below given code will help you to improve the performance.
Refer the below code for more details:
|
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
dataGrid.Columns.FirstOrDefault(column => column.MappingName == "CustomerID").IsHidden
= !viewModel.OrderInfoCollection.Any(order => order.CustomerID != "");
}
}
|
We have prepared a sample based on your requirement and you can download the same from the below link.
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SfGrid_Sample1196646433
Regards,
Shivagurunathan. K
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
JC Juan Carlos Gonzalez Salazar
- Feb 7, 2018 04:07 PM UTC
- Feb 15, 2018 02:48 PM UTC