igniteui-react-grids
Version:
Ignite UI React grid components.
283 lines (279 loc) • 7.31 kB
JavaScript
import { IgrColumn } from "./igr-column";
import { IgrRowType } from "./igr-row-type";
import { IgrGridCellIdentifier } from "./igr-grid-cell-identifier";
import { CellType as CellType_internal } from "./CellType";
import { ensureBool, interfaceToInternal } from "igniteui-react-core";
import { GridValidationState } from "./GridValidationState";
/**
* Interface representing a cell in the grid. It is essentially the blueprint to a cell object.
* Contains definitions of properties and methods, relevant to a cell
*/
export class IgrCellType {
createImplementation() {
return new CellType_internal();
}
get nativeElement() {
return this._implementation.nativeElement;
}
/**
* @hidden
*/
get i() {
return this._implementation;
}
onImplementationCreated() {
}
constructor() {
this.mounted = false;
this._implementation = this.createImplementation();
this._implementation.externalObject = this;
this.onImplementationCreated();
if (this._initializeAdapters) {
this._initializeAdapters();
}
}
_provideImplementation(i) {
this._implementation = i;
this._implementation.externalObject = this;
this.onImplementationCreated();
if (this._initializeAdapters) {
this._initializeAdapters();
}
}
/**
* The current value of the cell.
*/
get value() {
return this.i.u;
}
set value(v) {
this.i.u = v;
}
/**
* The value to display when the cell is in edit mode.
*/
get editValue() {
return this.i.r;
}
set editValue(v) {
this.i.r = v;
}
/**
* Indicates whether the cell is currently selected. It is false, if the sell is not selected, and true, if it is.
*/
get selected() {
return this.i.m;
}
set selected(v) {
this.i.m = ensureBool(v);
}
/**
* Indicates whether the cell is currently active (focused).
*/
get active() {
return this.i.i;
}
set active(v) {
this.i.i = ensureBool(v);
}
/**
* Indicates whether the cell can be edited.
*/
get editable() {
return this.i.j;
}
set editable(v) {
this.i.j = ensureBool(v);
}
/**
* Indicates whether the cell is currently in edit mode.
*/
get editMode() {
return this.i.k;
}
set editMode(v) {
this.i.k = ensureBool(v);
}
/**
* Represents the column that the cell belongs to.
*/
get column() {
const r = this.i.b;
if (r == null) {
return null;
}
if (!r.externalObject) {
let e = IgrColumn._createFromInternal(r);
if (e) {
e._implementation = r;
}
r.externalObject = e;
}
return r.externalObject;
}
set column(v) {
v == null ? this.i.b = null : this.i.b = v.i;
}
/**
* Represents the row that the cell belongs to
*/
get row() {
const r = this.i.f;
if (r == null) {
return null;
}
if (!r.externalObject) {
let e = new IgrRowType();
if (r.$type) {
e._implementation = r;
}
else {
if (e.i.setNativeElement) {
e.i.setNativeElement(r);
}
}
r.externalObject = e;
}
return r.externalObject;
}
set row(v) {
v == null ? this.i.f = null : this.i.f = v.i;
}
/**
* Represents the grid instance containing the cell
*/
get grid() {
const r = this.i.c;
if (r == null) {
return null;
}
return r.externalObject;
}
set grid(v) {
v == null ? this.i.c = null : this.i.c = v.i;
}
/**
* Optional; An object identifying the cell. It contains rowID, columnID, and rowIndex of the cell.
*/
get id() {
const r = this.i.d;
if (r == null) {
return null;
}
if (!r.externalObject) {
let e = new IgrGridCellIdentifier();
if (r.$type) {
e._implementation = r;
}
else {
if (e.i.setNativeElement) {
e.i.setNativeElement(r);
}
}
r.externalObject = e;
}
return r.externalObject;
}
set id(v) {
v == null ? this.i.d = null : this.i.d = v.i;
}
/**
* Optional; The `cellID` is the unique key, used to identify the cell
*/
get cellID() {
return this.i.q;
}
set cellID(v) {
this.i.q = v;
}
/**
* Optional; An object representing the validation state of the cell.
* Whether it's valid or invalid, and if it has errors
*/
get validation() {
return this.i.e.nativeElement;
}
set validation(v) {
this.i.e = interfaceToInternal(v, () => new GridValidationState());
}
get readonly() {
return this.i.l;
}
set readonly(v) {
this.i.l = ensureBool(v);
}
/**
* An optional title to display for the cell
*/
get title() {
return this.i.t;
}
set title(v) {
this.i.t = v;
}
/**
* The CSS width of the cell as a string.
*/
get width() {
return this.i.v;
}
set width(v) {
this.i.v = v;
}
/**
* The index of the column that the cell belongs to. It counts only the visible (not hidden) columns
*/
get visibleColumnIndex() {
return this.i.o;
}
set visibleColumnIndex(v) {
this.i.o = +v;
}
findByName(name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(name);
}
}
if (this.column && this.column.name && this.column.name == name) {
return this.column;
}
if (this.row && this.row.name && this.row.name == name) {
return this.row;
}
if (this.grid && this.grid.name && this.grid.name == name) {
return this.grid;
}
if (this.id && this.id.name && this.id.name == name) {
return this.id;
}
if (this.validation && this.validation.name && this.validation.name == name) {
return this.validation;
}
return null;
}
setNativeElement(element) {
this.i.setNativeElement(element);
}
/**
* A method definition to update the value of the cell.
*/
update(value) {
this.i.y(value);
}
/**
* A method definition to start or end the edit mode of the cell. It takes a boolean value as an argument
*/
setEditMode(value) {
this.i.w(value);
}
/**
* Optional;
* A method definition to calculate the size of the cell to fit the content
* The method can be used to calculate the size of the cell with the longest content and resize all cells to that size
*/
calculateSizeToFit(range) {
let iv = this.i.n(range);
return (iv);
}
}