-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathcaption-cell-renderer.ts
94 lines (88 loc) · 4.21 KB
/
caption-cell-renderer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { isNullOrUndefined } from '@syncfusion/ej2-base';
import { Column } from '../models/column';
import { Cell } from '../models/cell';
import { ICellRenderer } from '../base/interface';
import { CellRenderer } from './cell-renderer';
import { IGrid } from '../base/interface';
import { appendChildren, templateCompiler } from '../base/util';
import { GroupedData } from '../services/group-model-generator';
/**
* GroupCaptionCellRenderer class which responsible for building group caption cell.
*
* @hidden
*/
export class GroupCaptionCellRenderer extends CellRenderer implements ICellRenderer<Column> {
public element: HTMLElement = this.parent
.createElement('TD', { className: 'e-groupcaption',
attrs: { id: this.parent.element.id + 'captioncell', role: 'gridcell', tabindex: '-1' } });
/**
* Function to render the cell content based on Column object.
*
* @param {Cell} cell - specifies the cell
* @param {Object} data - specifies the GroupedData
* @returns {Element} returns the element
*/
public render(cell: Cell<Column>, data: GroupedData): Element {
const node: Element = this.element.cloneNode() as Element;
const gObj: IGrid = this.parent;
let result: Element[];
let fKeyValue: string;
data.headerText = cell.column.headerText;
if (cell.isForeignKey) {
fKeyValue = this.format(cell.column, (cell.column.valueAccessor as Function)('foreignKey', data, cell.column));
}
const value: string = cell.isForeignKey ? fKeyValue : cell.column.enableGroupByFormat ? data.key :
this.format(cell.column, (cell.column.valueAccessor as Function)('key', data, cell.column));
if (!isNullOrUndefined(gObj.groupSettings.captionTemplate)) {
const isReactCompiler: boolean = this.parent.isReact && typeof (gObj.groupSettings.captionTemplate) !== 'string';
if (isReactCompiler) {
const tempID: string = gObj.element.id + 'captionTemplate';
templateCompiler(gObj.groupSettings.captionTemplate as string)(data, this.parent, 'captionTemplate', tempID, null, null, node);
this.parent.renderTemplates();
} else if (this.parent.isVue) {
result = templateCompiler(gObj.groupSettings.captionTemplate as string)(data, this.parent);
} else {
result = templateCompiler(gObj.groupSettings.captionTemplate as string)(data);
}
if (!isReactCompiler) {
appendChildren(node, result);
}
} else {
if (gObj.groupSettings.enableLazyLoading) {
node.innerHTML = cell.column.headerText + ': ' + value;
} else {
node.innerHTML = cell.column.headerText + ': ' + value + ' - ' + data.count + ' ' +
(data.count < 2 ? this.localizer.getConstant('Item') : this.localizer.getConstant('Items'));
}
}
node.setAttribute('colspan', cell.colSpan.toString());
node.setAttribute('aria-label', node.innerHTML + ' is groupcaption cell');
node.setAttribute('title', node.innerHTML);
return node;
}
}
/**
* GroupCaptionEmptyCellRenderer class which responsible for building group caption empty cell.
*
* @hidden
*/
export class GroupCaptionEmptyCellRenderer extends CellRenderer implements ICellRenderer<Column> {
public element: HTMLElement = this.parent.createElement('TD', { className: 'e-groupcaption' });
/**
* Function to render the cell content based on Column object.
*
* @param {Cell} cell - specifies the cell
* @param {Object} data - specifies the Object
* @param {string} data.field - Defines the field
* @param {string} data.key - Defines the key
* @param {number} data.count - Defines the count
* @returns {Element} returns the element
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public render(cell: Cell<Column>, data: { field: string, key: string, count: number }): Element {
const node: Element = this.element.cloneNode() as Element;
node.innerHTML = ' ';
node.setAttribute('colspan', cell.colSpan.toString());
return node;
}
}