Class GridColumnSizer
Represents a class that provides the implementation to calculate column widths based on different column sizer options for SfDataGrid(GridLengthUnitType).
Implements
Inherited Members
Namespace: Syncfusion.UI.Xaml.Grid
Assembly: Syncfusion.SfGrid.UWP.dll
Syntax
public class GridColumnSizer : ColumnSizerBase<SfDataGrid>, IDisposable
Constructors
GridColumnSizer()
Initializes a new instance of GridColumnSizer class.
Declaration
public GridColumnSizer()
GridColumnSizer(SfDataGrid)
Initializes a new instance of GridColumnSizer class.
Declaration
public GridColumnSizer(SfDataGrid dataGrid)
Parameters
Type | Name | Description |
---|---|---|
SfDataGrid | dataGrid | The SfDataGrid. |
Properties
DataGrid
Gets the reference to the SfDataGrid control.
Declaration
public SfDataGrid DataGrid { get; }
Property Value
Type |
---|
SfDataGrid |
FilterIconWidth
Gets or sets the width of filter icon for column sizing calculation..
Declaration
public double FilterIconWidth { get; set; }
Property Value
Type | Description |
---|---|
System.Double | The width of the filter icon. The default value is 28. |
Remarks
The SizeToHeader and Auto type of column sizer calculates the column width based on static filter icon width. When the filter icon width is customized, that is need to be initialized to this property for customizing column sizer calculation based on new filter icon width.
Methods
CalculateAutoFitWidth(GridColumn, Boolean)
Calculates the width for the column to fit the content when column sizer is Auto.
Declaration
protected virtual double CalculateAutoFitWidth(GridColumn column, bool isAuto = false)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to calculate the width based on Auto column sizer. |
System.Boolean | isAuto | Indicates whether the column sizer type is Auto. |
Returns
Type | Description |
---|---|
System.Double | Returns the column width based on Auto column sizer. |
Remarks
Override this method and customize the calculation of Auto column sizer.
CalculateCellWidth(GridColumn, Boolean)
Calculates the width for the column based on cell value when column sizer is SizeToCells or Auto.
Declaration
protected virtual double CalculateCellWidth(GridColumn column, bool setWidth = true)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to calculate the cell width. |
System.Boolean | setWidth | Indicates whether calculated cell width is set as an actual width of the column. |
Returns
Type | Description |
---|---|
System.Double | Returns the corresponding width for the specified column. |
Remarks
This method is invoked when the column sizer is SizeToCells and you can customize column width calculation by overriding this method.
CalculateHeaderWidth(GridColumn, Boolean)
Calculates the width of the column based on header text when column sizer is SizeToHeader or Auto.
Declaration
protected virtual double CalculateHeaderWidth(GridColumn column, bool setWidth = true)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to calculate its header width. |
System.Boolean | setWidth | Indicates whether calculated header width is set as an actual width of the column. |
Returns
Type | Description |
---|---|
System.Double | Returns the width of the specified column. |
Remarks
This method is invoked when the column sizer is SizeToHeader and you can customize column width calculation by overriding this method.
Dispose(Boolean)
Disposes all the resources used by GridColumnSizer class.
Declaration
protected override void Dispose(bool isDisposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | isDisposing | Indicates whether the call is from Dispose method or from a finalizer. |
Overrides
GetAutoCellHeight(RowColumnIndex, Boolean)
Calculates the cell height based on the cell contents.
Declaration
public double GetAutoCellHeight(RowColumnIndex rowColumnIndex, bool useEditValue = true)
Parameters
Type | Name | Description |
---|---|---|
RowColumnIndex | rowColumnIndex | The rowColumnIndex contains RowIndex and ColumnIndex. |
System.Boolean | useEditValue | Which specifies whether need to use the edit value while measuring the height of the cell content |
Returns
Type | Description |
---|---|
System.Double | Returns true if the cell height is calculated for a column, otherwise false. |
GetAutoRowHeight(Int32, GridRowSizingOptions, out Double, Boolean)
Sets the width for the specified column based on
Declaration
public bool GetAutoRowHeight(int RowIndex, GridRowSizingOptions options, out double rowHeight, bool useEditValue = false)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | RowIndex | |
GridRowSizingOptions | options | |
System.Double | rowHeight | |
System.Boolean | useEditValue |
Returns
Type | Description |
---|---|
System.Boolean | Returns the corresponding width for the specified column. |
GetAutoRowHeight(Object, GridRowSizingOptions, out Double)
Calculates the row height based on the cell contents of the row.
Declaration
public bool GetAutoRowHeight(object record, GridRowSizingOptions options, out double rowHeight)
Parameters
Type | Name | Description |
---|---|---|
System.Object | record | Records of the corresponding row to get row height. |
GridRowSizingOptions | options | GridRowSizingOptions to get row height. |
System.Double | rowHeight | Calculated height of the row. |
Returns
Type | Description |
---|---|
System.Boolean | Returns true if the row height is calculated for record and header rows, otherwise false. |
Remarks
This can be used inside QueryRowHeight event handler to auto-size the rows based on content for printing.
GetAutoWidth(GridColumn)
Gets the width for the specified column when the column sizer is SizeToCells or Auto .
Declaration
protected virtual double GetAutoWidth(GridColumn column)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to get the auto width. |
Returns
Type | Description |
---|---|
System.Double | Returns the auto width for the specified column. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the column is null. |
GetCellSize(Size, GridColumn, Object, GridQueryBounds)
Gets the size of the cell to calculate the width of the specified column when column sizer is SizeToCells or Auto.
Declaration
protected virtual Size GetCellSize(Size rect, GridColumn column, object data, GridQueryBounds bounds)
Parameters
Type | Name | Description |
---|---|---|
Windows.Foundation.Size | rect | The corresponding display rectangle of the cell to measure cell size. |
GridColumn | column | The corresponding column to measure its cell size. |
System.Object | data | The corresponding data to measure the text size in cell. |
GridQueryBounds | bounds | Indicates whether the cell size is measured based on the height or width of the cell. |
Returns
Type | Description |
---|---|
Windows.Foundation.Size | Returns the size of the cell. |
GetColumnToFill()
Gets the column to fill the remaining view port size based on AutoLastColumnFill or AutoWithLastColumnFill column sizer.
Declaration
protected virtual GridColumn GetColumnToFill()
Returns
Type | Description |
---|---|
GridColumn | the column to fill. |
GetControl(GridColumn, Object)
Gets the content presenter to measure the template when column sizer is SizeToCells.
Declaration
protected virtual ContentPresenter GetControl(GridColumn column, object record)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to get the content presenter. |
System.Object | record | The corresponding record to get the content presenter. |
Returns
Type | Description |
---|---|
Windows.UI.Xaml.Controls.ContentPresenter | Returns the |
GetDisplayText(GridColumn, Object)
Gets the display text of cell for the specified column and record.
Declaration
protected virtual string GetDisplayText(GridColumn column, object record)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to get the display text of cell. |
System.Object | record | The corresponding record to get the display text. |
Returns
Type | Description |
---|---|
System.String | Returns the display text of the corresponding column. |
GetEditingCellSize(Size, GridColumn, Object, GridQueryBounds)
Calculates the Size of the cell based on the content present in the cell.
Declaration
protected virtual Size GetEditingCellSize(Size rect, GridColumn column, object data, GridQueryBounds bounds)
Parameters
Type | Name | Description |
---|---|---|
Windows.Foundation.Size | rect | The corresponding display rectangle of the cell to measure cell size. |
GridColumn | column | The corresponding column to measure its cell size. |
System.Object | data | The corresponding data to measure the text size in cell. |
GridQueryBounds | bounds | Indicates whether the cell size is measured based on the height of the cell. |
Returns
Type | Description |
---|---|
Windows.Foundation.Size | Returns the size of the cell. |
GetTextBlock(GridColumn, Object, GridQueryBounds)
Gets the TextBlock to measure the text when the column sizer is SizeToCells or Auto.
Declaration
protected virtual TextBlock GetTextBlock(GridColumn column, object record, GridQueryBounds queryBounds)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to get the TextBlock. |
System.Object | record | The corresponding record to get the TextBlock. |
GridQueryBounds | queryBounds | Indicates whether the text is measured based on the height or width of the cell. |
Returns
Type | Description |
---|---|
Windows.UI.Xaml.Controls.TextBlock | Returns the TextBlock for the specified column and record. |
MeasureHeaderTemplate(GridColumn, Size, GridQueryBounds)
Measures the size of the header template for the specified column.
Declaration
protected virtual Size MeasureHeaderTemplate(GridColumn column, Size rect, GridQueryBounds bounds)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to measure the header template. |
Windows.Foundation.Size | rect | The corresponding display rectangle to measure the template. |
GridQueryBounds | bounds | Indicates whether the template is measured based on the height or width of the cell. |
Returns
Type | Description |
---|---|
Windows.Foundation.Size | Returns the size of the header template for the specified column. |
MeasureTemplate(Size, Object, GridColumn, GridQueryBounds)
Measures the size of the template when the column sizer is SizeToCells or Auto.
Declaration
protected virtual Size MeasureTemplate(Size rect, object record, GridColumn column, GridQueryBounds bounds)
Parameters
Type | Name | Description |
---|---|---|
Windows.Foundation.Size | rect | The corresponding display rectangle to measure the template. |
System.Object | record | The corresponding record to measure the template. |
GridColumn | column | The corresponding column to measure the template. |
GridQueryBounds | bounds | Indicates whether the template is measured based on the height or width of the cell. |
Returns
Type | Description |
---|---|
Windows.Foundation.Size | Returns the size of template. |
MeasureText(Size, String, GridColumn, Object, GridQueryBounds)
Measures the text of the specified column when the column sizing is SizeToCells or Auto.
Declaration
protected virtual Size MeasureText(Size rectangle, string displayText, GridColumn column, object record, GridQueryBounds queryBounds)
Parameters
Type | Name | Description |
---|---|---|
Windows.Foundation.Size | rectangle | The corresponding display rectangle to measure the text. |
System.String | displayText | The displayText to measure. |
GridColumn | column | The corresponding column to measure the text. |
System.Object | record | The corresponding record to measure the text. |
GridQueryBounds | queryBounds | Indicates whether the text is measured based on the height or width of the cell. |
Returns
Type | Description |
---|---|
Windows.Foundation.Size | Returns the size of text. |
OnColumnPropertyChanged(GridColumn, String)
Invoked when the GridColumn property value changes.
Declaration
protected virtual void OnColumnPropertyChanged(GridColumn column, string propertyName)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column on which the property value changes. |
System.String | propertyName | The name of property that value has been changed. |
Refresh()
Refreshes column widths when the ColumnSizer property value changes at SfDataGrid or GridColumn level.
Declaration
public void Refresh()
Refresh(Double)
Refreshes the column width when the ColumnSizer property value changes at SfDataGrid or GridColumn level.
Declaration
protected virtual void Refresh(double AvailableWidth)
Parameters
Type | Name | Description |
---|---|---|
System.Double | AvailableWidth | The available width to refresh the column width. |
ResetAutoCalculation(GridColumn)
Resets the auto width for the specified column.
Declaration
public void ResetAutoCalculation(GridColumn column)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to reset the auto width. |
Remarks
The column width is reset to double.Nan ,if the column sizing is need to recalculate based on the data.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the column is null. |
SetAutoWidth(GridColumn, Double)
Sets the width for the specified column based on Auto column sizer.
Declaration
public virtual void SetAutoWidth(GridColumn column, double width)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to set Auto width. |
System.Double | width | The corresponding width set as Auto width. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the column is null. |
SetColumnWidth(GridColumn, Double)
Sets the width for the specified column based on
Declaration
public virtual double SetColumnWidth(GridColumn column, double Width)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to set the width. |
System.Double | Width | The corresponding width to set. |
Returns
Type | Description |
---|---|
System.Double | Returns the corresponding width for the specified column. |
SetNoneWidth(GridColumn, Double)
Sets the width for the specified column based on None column sizer.
Declaration
protected virtual double SetNoneWidth(GridColumn column, double width)
Parameters
Type | Name | Description |
---|---|---|
GridColumn | column | The corresponding column to set None width. |
System.Double | width | The width to set as None width. |
Returns
Type | Description |
---|---|
System.Double | Returns the None width for the specified column. |
SetStarWidth(Double, IEnumerable<GridColumn>)
Sets the column width based on Star column sizer.
Declaration
protected virtual void SetStarWidth(double remainingColumnWidth, IEnumerable<GridColumn> remainingColumns)
Parameters
Type | Name | Description |
---|---|---|
System.Double | remainingColumnWidth | The available width to adjust the column based on Star column sizer. |
System.Collections.Generic.IEnumerable<GridColumn> | remainingColumns | The collection columns that need to be set star width. |
Remarks
Override this method to customize the Star width calculation in SfDataGrid.