datagrid.CellRenderers.Remove("Header");
datagrid.CellRenderers.Add("Header", new GridDataHeaderCellRendererExt());
public class GridDataHeaderCellRendererExt : GridDataHeaderCellRenderer
{
protected override Syncfusion.UI.Xaml.Grid.GridHeaderCellControl OnCreateEditUIElement()
{
return new GridHeaderCellControlExt();
}
public override void OnUpdateEditBinding(Syncfusion.UI.Xaml.Grid.DataColumnBase dataColumn, Syncfusion.UI.Xaml.Grid.GridHeaderCellControl element, object dataContext)
{
base.OnUpdateEditBinding(dataColumn, element, dataContext);
element.FilterIconVisiblity = System.Windows.Visibility.Collapsed;
}
} |
public class GridHeaderCellControlExt:GridHeaderCellControl
{
public GridHeaderCellControlExt()
: base()
{
}
protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e)
{
base.OnMouseEnter(e);
if(this.DataGrid.AllowFiltering && Column.AllowFiltering)
this.FilterIconVisiblity = System.Windows.Visibility.Visible;
else if(this.DataGrid.AllowFiltering && !Column.AllowFiltering)
this.FilterIconVisiblity = System.Windows.Visibility.Collapsed;
else if(!this.DataGrid.AllowFiltering && Column.AllowFiltering)
this.FilterIconVisiblity = System.Windows.Visibility.Visible;
else
this.FilterIconVisiblity = System.Windows.Visibility.Collapsed;
}
protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e)
{
base.OnMouseLeave(e);
if(Column.FilterPredicates.Count!=0)
this.FilterIconVisiblity = System.Windows.Visibility.Visible;
else
this.FilterIconVisiblity = System.Windows.Visibility.Collapsed;
}
} |
this.datagrid.FilterChanged += datagrid_FilterChanged;
void datagrid_FilterChanged(object sender, Syncfusion.UI.Xaml.Grid.GridFilterEventArgs e)
{
var headerRowBase = this.datagrid.GetRowGenerator().Items.FirstOrDefault(row => row.RowIndex == this.datagrid.GetHeaderIndex());
var columnBase = (headerRowBase as DataRowBase).VisibleColumns.FirstOrDefault(col => col.GridColumn != null && col.GridColumn.MappingName.Equals(e.Column.MappingName));
if (e.Column.FilterPredicates.Count != 0)
{
(columnBase.ColumnElement as GridHeaderCellControl).FilterIconVisiblity = Visibility.Visible;
}
else
(columnBase.ColumnElement as GridHeaderCellControl).FilterIconVisiblity = Visibility.Collapsed;
} |
public void OpenFilterPopup() { base.OpenFilterPopUp(); } |
public class GridHeaderCellControlExt:GridHeaderCellControl
{
public GridHeaderCellControlExt()
: base()
{
}
public void OpenFilterPopup()
{
this.FilterToggleButton.IsChecked = true;
base.OpenFilterPopUp();
}
} |
private static void OnFilterPopupOpened(object obj)
{
if (obj is GridColumnContextMenuInfo)
{
var dataGrid = (obj as GridColumnContextMenuInfo).DataGrid;
var column = (obj as GridColumnContextMenuInfo).Column;
(dataGrid.GetHeaderCell(column) as GridHeaderCellControlExt).OpenFilterPopup();
}
} |