1 | import {Column} from "./column";
|
2 | import {Utils as _} from "../utils";
|
3 | import {GridRow} from "./gridRow";
|
4 |
|
5 |
|
6 | export interface GridCellDef {
|
7 | floating: string;
|
8 | rowIndex: number;
|
9 | column: Column;
|
10 | }
|
11 |
|
12 | export class GridCell {
|
13 |
|
14 | floating: string;
|
15 | rowIndex: number;
|
16 | column: Column;
|
17 |
|
18 | constructor(gridCellDef: GridCellDef) {
|
19 | this.rowIndex = gridCellDef.rowIndex;
|
20 | this.column = gridCellDef.column;
|
21 | this.floating = _.makeNull(gridCellDef.floating);
|
22 | }
|
23 |
|
24 | public getGridCellDef(): GridCellDef {
|
25 | return {
|
26 | rowIndex: this.rowIndex,
|
27 | column: this.column,
|
28 | floating: this.floating
|
29 | };
|
30 | }
|
31 |
|
32 | public getGridRow(): GridRow {
|
33 | return new GridRow(this.rowIndex, this.floating);
|
34 | }
|
35 |
|
36 | public toString(): string {
|
37 | return `rowIndex = ${this.rowIndex}, floating = ${this.floating}, column = ${this.column ? this.column.getId() : null}`;
|
38 | }
|
39 |
|
40 | public createId(): string {
|
41 | return `${this.rowIndex}.${this.floating}.${this.column.getId()}`;
|
42 | }
|
43 |
|
44 | public equals(other: GridCell): boolean {
|
45 | let colsMatch = this.column === other.column;
|
46 | let floatingMatch = this.floating === other.floating;
|
47 | let indexMatch = this.rowIndex === other.rowIndex;
|
48 | return colsMatch && floatingMatch && indexMatch;
|
49 | }
|
50 | }
|