igniteui-react-grids
Version:
Ignite UI React grid components.
393 lines (388 loc) • 9.73 kB
JavaScript
import { IgrGroupByRecord } from "./igr-group-by-record";
import { IgrTreeGridRecord } from "./igr-tree-grid-record";
import { RowType as RowType_internal } from "./RowType";
import { ensureBool, interfaceToInternal } from "igniteui-react-core";
import { GridValidationState } from "./GridValidationState";
import { IgrCellType } from "./igr-cell-type";
/**
* Interface representing a row in the grid. It is essentially the blueprint to a row object.
* Contains definitions of properties and methods, relevant to a row
*/
export class IgrRowType {
createImplementation() {
return new RowType_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 index of the row within the grid
*/
get index() {
return this.i.u;
}
set index(v) {
this.i.u = +v;
}
get viewIndex() {
return this.i.v;
}
set viewIndex(v) {
this.i.v = +v;
}
/**
* Indicates whether the row is grouped.
*/
get isGroupByRow() {
return this.i.q;
}
set isGroupByRow(v) {
this.i.q = ensureBool(v);
}
get isSummaryRow() {
return this.i.r;
}
set isSummaryRow(v) {
this.i.r = ensureBool(v);
}
get groupRow() {
const r = this.i.e;
if (r == null) {
return null;
}
if (!r.externalObject) {
let e = new IgrGroupByRecord();
if (r.$type) {
e._implementation = r;
}
else {
if (e.i.setNativeElement) {
e.i.setNativeElement(r);
}
}
r.externalObject = e;
}
return r.externalObject;
}
set groupRow(v) {
v == null ? this.i.e = null : this.i.e = v.i;
}
get key() {
return this.i.z;
}
set key(v) {
this.i.z = v;
}
get validation() {
return this.i.d.nativeElement;
}
set validation(v) {
this.i.d = interfaceToInternal(v, () => new GridValidationState());
}
get data() {
return this.i.x;
}
set data(v) {
this.i.x = v;
}
/**
* Optional
* A list or an array of cells, that belong to the row
*/
get cells() {
if (!this.i.a) {
return undefined;
}
let ret = [];
for (let i = 0; i < this.i.a.length; i++) {
let impl = this.i.a[i];
if (!impl.externalObject) {
if (impl instanceof IgrCellType) {
ret.push(impl);
continue;
}
let e = new IgrCellType();
e._implementation = impl;
impl.externalObject = e;
}
ret.push(impl.externalObject);
}
return ret;
}
set cells(v) {
let arr = [];
for (let i = 0; i < v.length; i++) {
arr.push(v[i].i);
}
this.i.a = arr;
}
/**
* Optional
* Indicates whether the current row is disabled
*/
get disabled() {
return this.i.l;
}
set disabled(v) {
this.i.l = ensureBool(v);
}
/**
* Optional
* Indicates whether the current row is pinned.
*/
get pinned() {
return this.i.s;
}
set pinned(v) {
this.i.s = ensureBool(v);
}
/**
* Optional
* Indicates whether the current row is selected
*/
get selected() {
return this.i.t;
}
set selected(v) {
this.i.t = ensureBool(v);
}
/**
* Optional
* Indicates whether the current row is expanded.
* The value is true, if the row is expanded and false, if it is collapsed
*/
get expanded() {
return this.i.m;
}
set expanded(v) {
this.i.m = ensureBool(v);
}
/**
* Optional
* Indicates whether the row is marked for deletion.
*/
get deleted() {
return this.i.k;
}
set deleted(v) {
this.i.k = ensureBool(v);
}
/**
* Optional
* Indicates whether the row is currently being edited.
*/
get inEditMode() {
return this.i.p;
}
set inEditMode(v) {
this.i.p = ensureBool(v);
}
/**
* Optional
* Contains the child rows of the current row, if there are any.
*/
get children() {
if (!this.i.b) {
return undefined;
}
let ret = [];
for (let i = 0; i < this.i.b.length; i++) {
let impl = this.i.b[i];
if (!impl.externalObject) {
if (impl instanceof IgrRowType) {
ret.push(impl);
continue;
}
let e = new IgrRowType();
e._implementation = impl;
impl.externalObject = e;
}
ret.push(impl.externalObject);
}
return ret;
}
set children(v) {
let arr = [];
for (let i = 0; i < v.length; i++) {
arr.push(v[i].i);
}
this.i.b = arr;
}
/**
* Optional
* Contains the parent row of the current row, if it has one.
* If the parent row exist, it means that the current row is a child row
*/
get parent() {
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 parent(v) {
v == null ? this.i.f = null : this.i.f = v.i;
}
/**
* Optional
* Indicates whether the current row has any child rows
*/
get hasChildren() {
return this.i.o;
}
set hasChildren(v) {
this.i.o = ensureBool(v);
}
/**
* Optional
* Represents the hierarchical record associated with the row (for tree grids).
* It is of type ITreeGridRecord, which contains the data, children, the hierarchical level, etc.
*/
get treeRow() {
const r = this.i.g;
if (r == null) {
return null;
}
if (!r.externalObject) {
let e = new IgrTreeGridRecord();
if (r.$type) {
e._implementation = r;
}
else {
if (e.i.setNativeElement) {
e.i.setNativeElement(r);
}
}
r.externalObject = e;
}
return r.externalObject;
}
set treeRow(v) {
v == null ? this.i.g = null : this.i.g = v.i;
}
get addRowUI() {
return this.i.j;
}
set addRowUI(v) {
this.i.j = ensureBool(v);
}
/**
* Optional
* Indicates whether the row is currently focused.
*/
get focused() {
return this.i.n;
}
set focused(v) {
this.i.n = ensureBool(v);
}
/**
* Represent the grid instance, the row belongs to
*/
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;
}
get ephemeralKey() {
return this.i.ab;
}
findByName(name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(name);
}
}
if (this.groupRow && this.groupRow.name && this.groupRow.name == name) {
return this.groupRow;
}
if (this.validation && this.validation.name && this.validation.name == name) {
return this.validation;
}
if (this.parent && this.parent.name && this.parent.name == name) {
return this.parent;
}
if (this.treeRow && this.treeRow.name && this.treeRow.name == name) {
return this.treeRow;
}
if (this.grid && this.grid.name && this.grid.name == name) {
return this.grid;
}
return null;
}
setNativeElement(element) {
this.i.setNativeElement(element);
}
/**
* Optional
* A method to handle changing the value of elements of the row
* It takes the new value as an argument
*/
update(value) {
this.i.af(value);
}
/**
* Optional
* A method to handle deleting rows
*/
del() {
let iv = this.i.y();
return (iv);
}
/**
* Optional
* A method to handle pinning a row
*/
pin() {
this.i.ac();
}
/**
* Optional
* A method to handle unpinning a row, that has been pinned
*/
unpin() {
this.i.ae();
}
}