projects/wms-framework/src/lib/models/controls/DataGridLengthModel.ts
An object that is used to specify the width of a column object.
Properties |
|
Methods |
|
constructor(p1, p2)
|
||||||
Parameters :
|
Static Auto |
Default value : new ColumnWidth(1, ColumnWidthType.Auto)
|
Static InitialAuto |
Default value : new ColumnWidth(1, ColumnWidthType.InitialAuto)
|
Static SizeToCells |
Default value : new ColumnWidth(1, ColumnWidthType.SizeToCells)
|
Static SizeToHeader |
Default value : new ColumnWidth(1, ColumnWidthType.SizeToHeader)
|
Static Star |
Default value : new ColumnWidth(1, ColumnWidthType.Star)
|
Public Value |
Type : any
|
Default value : null
|
Gets/sets the value of the ColumnWidth property |
Public WidthType |
Type : ColumnWidthType
|
Default value : ColumnWidthType.Auto
|
Gets/sets the ColumnWidthType of the column. |
Static parse | ||||||
parse(input: string | ColumnWidth)
|
||||||
Returns a Thickness from a string, or
Parameters :
Returns :
ColumnWidth
{ThicknessModel} |
import { ColumnWidthType } from '../enums/ColumnWidthType';
import { DataGridLengthUnitType } from './DataGridLengthUnitType';
/**
* An object that is used to specify the width of a column object.
*
* @export
* @class ColumnWidth
* @wType Infragistics.Controls.Grids.ColumnWidth
*/
export class ColumnWidth {
constructor(value: number, isStar: boolean);
constructor(value: number, type: ColumnWidthType);
constructor(p1, p2) {
this.Value = p1;
if (typeof p2 === 'boolean') {
this.WidthType = p2 ? ColumnWidthType.Star : ColumnWidthType.Numeric;
} else {
this.WidthType = p2;
}
}
/**
* Gets/sets the value of the ColumnWidth property
*
* @type {*}
* @memberof ColumnWidth
*/
public Value: any = null;
/**
* Gets/sets the ColumnWidthType of the column.
*
* @type {ColumnWidthType}
* @memberof ColumnWidth
*/
public WidthType: ColumnWidthType = ColumnWidthType.Auto;
public static SizeToHeader = new ColumnWidth(1, ColumnWidthType.SizeToHeader);
public static Auto = new ColumnWidth(1, ColumnWidthType.Auto);
public static Star = new ColumnWidth(1, ColumnWidthType.Star);
public static SizeToCells = new ColumnWidth(1, ColumnWidthType.SizeToCells);
public static InitialAuto = new ColumnWidth(1, ColumnWidthType.InitialAuto);
/**
* Returns a Thickness from a string, or `null` if the string format is incorrect.
*
* @static
* @param {(string | ThicknessModel)} input
* @return {*} {ThicknessModel}
* @memberof ThicknessModel
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
public static parse(input: string | ColumnWidth): ColumnWidth {
if (input instanceof ColumnWidth) {
return input;
}
let lowerInput = String(input).toLowerCase();
if (Number(input)) {
return new ColumnWidth(Number(input), false);
} else if (
lowerInput === 'star' ||
lowerInput === '*' ||
lowerInput === 'auto*'
) {
return ColumnWidth.Star;
} else if (lowerInput.endsWith('*')) {
return new ColumnWidth(Number(input.replace('*', '')), true);
} else if (lowerInput.startsWith('*')) {
return new ColumnWidth(Number(input.replace('*', '')), true);
} else if (lowerInput === 'auto') {
return ColumnWidth.Auto;
} else if (lowerInput === 'initialauto') {
return ColumnWidth.InitialAuto;
} else if (lowerInput.startsWith('sizetocell')) {
return ColumnWidth.SizeToCells;
} else if (lowerInput === 'sizetoheader') {
return ColumnWidth.SizeToHeader;
} else {
return null;
}
}
}
/**
* Defines the size of a data grid column. The size can be indicated in absolute value or fractions using
* te '*' character such as:
*
* @wType System.Windows.Controls.DataGridLength
*/
export class DataGridLengthModel {
constructor(value: number, unitType?: DataGridLengthUnitType) {
this.Value = value;
this.UnitType =
unitType === undefined ? DataGridLengthUnitType.Pixel : unitType;
this.calculateHtmlValue();
this.AbsoluteZero =
(this.UnitType === DataGridLengthUnitType.Pixel && this.Value === 0) ||
(this.UnitType === DataGridLengthUnitType.Star && this.Value === 0);
}
/**
* The value of this data grid length in pixels
*/
public Value: number;
/**
* Gets/sets the unit of this data grid lenght object
*/
public UnitType: DataGridLengthUnitType;
/**
* Gets the matching html value of this data grid lenght object.
*
* @wIgnore
*/
public HtmlValue: string;
/**
* Indicates whether this {DataGridLengthModel} represents an absolute zero value (0 pixels)
*
* @type {boolean}
* @memberof DataGridLengthModel
* @wIgnore
*/
public AbsoluteZero: boolean;
public static SizeToCells: DataGridLengthModel = new DataGridLengthModel(
1,
DataGridLengthUnitType.SizeToCells
);
public static SizeToHeader: DataGridLengthModel = new DataGridLengthModel(
1,
DataGridLengthUnitType.SizeToHeader
);
/**
* Tries to create a new { DataGridLengthModel} object from the given value
* @param value the value used to create a new DataGridLength object
* @returns
*/
public static createDataGridLength(value: any): DataGridLengthModel {
if (typeof value == 'string') {
return DataGridLengthModel.createFromString(value as string);
} else if (typeof value == 'number') {
return new DataGridLengthModel(value as number);
}
return value;
}
/**
* Creates a new { DataGridLengthModel } object using the given string value. It validates if the string contains
* a '*' symbol or not.
* @param value the string value with the column width
* @returns a valid {DataGridLengthModel} object or null
*/
private static createFromString(value: string) {
let result: DataGridLengthModel = null;
let strValue = value as string;
if (isNaN(parseFloat(strValue)) || strValue.includes('*')) {
if (strValue === 'auto') {
result = new DataGridLengthModel(0, DataGridLengthUnitType.Auto);
} else if (strValue.includes('*')) {
strValue = strValue.replace('*', '');
result = new DataGridLengthModel(
strValue.length === 0 ? 1 : Number.parseInt(strValue),
DataGridLengthUnitType.Star
);
}
} else {
result = new DataGridLengthModel(Number.parseInt(strValue));
}
return result;
}
/**
* Calculates the column with in valid html format
*/
private calculateHtmlValue() {
this.HtmlValue = undefined; // defaulting to Auto
switch (this.UnitType) {
case DataGridLengthUnitType.Auto:
this.HtmlValue = undefined;
break;
case DataGridLengthUnitType.Star:
this.HtmlValue =
this.Value == 1 ? '100% ' : `minmax(0px, ${this.Value}fr) `;
break;
case DataGridLengthUnitType.Pixel:
this.HtmlValue = `${this.Value}px `;
break;
}
}
}