This repository has been archived by the owner on May 5, 2021. It is now read-only.
forked from 6pac/SlickGrid
-
Notifications
You must be signed in to change notification settings - Fork 5
/
slick.formatters.ts
104 lines (95 loc) · 2.18 KB
/
slick.formatters.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
95
96
97
98
99
100
101
102
103
104
/***
* Contains basic SlickGrid formatters.
*
* NOTE: These are merely examples. You will most likely need to implement something more
* robust/extensible/localizable/etc. for your use!
*
* @module Formatters
* @namespace Slick
*/
(function ($) {
function PercentCompleteFormatter(
_row: number,
_cell: number,
value: number | string,
_columnDef: unknown,
_dataContext: unknown
) {
if (value == null || value === "") {
return "-";
} else if (value < 50) {
return "<span style='color:red;font-weight:bold;'>" + value + "%</span>";
} else {
return "<span style='color:green'>" + value + "%</span>";
}
}
function PercentCompleteBarFormatter(
_row: number,
_cell: number,
value: number | string,
_columnDef: unknown,
_dataContext: unknown
) {
if (value == null || value === "") {
return "";
}
var color;
if (value < 30) {
color = "red";
} else if (value < 70) {
color = "silver";
} else {
color = "green";
}
return (
"<span class='percent-complete-bar' style='background:" +
color +
";width:" +
value +
"%'></span>"
);
}
function YesNoFormatter(
_row: number,
_cell: number,
value: number | string,
_columnDef: unknown,
_dataContext: unknown
) {
return value ? "Yes" : "No";
}
function CheckboxFormatter(
_row: number,
_cell: number,
value: number | string,
_columnDef: unknown,
_dataContext: unknown
) {
return (
'<img class="slick-edit-preclick" src="../images/' +
(value ? "CheckboxY" : "CheckboxN") +
'.png">'
);
}
function CheckmarkFormatter(
_row: number,
_cell: number,
value: number | string,
_columnDef: unknown,
_dataContext: unknown
) {
return value ? "<img src='../images/tick.png'>" : "";
}
// exports
$.extend(true, window, {
Slick: {
Formatters: {
PercentComplete: PercentCompleteFormatter,
PercentCompleteBar: PercentCompleteBarFormatter,
YesNo: YesNoFormatter,
Checkmark: CheckmarkFormatter,
Checkbox: CheckboxFormatter,
},
},
});
})(jQuery);