UNPKG

1.88 kBJavaScriptView Raw
1/***
2 * Contains basic SlickGrid formatters.
3 *
4 * NOTE: These are merely examples. You will most likely need to implement something more
5 * robust/extensible/localizable/etc. for your use!
6 *
7 * @module Formatters
8 * @namespace Slick
9 */
10
11(function ($) {
12 function PercentCompleteFormatter(row, cell, value, columnDef, dataContext) {
13 if (value == null || value === "") {
14 return "-";
15 } else if (value < 50) {
16 return "<span style='color:red;font-weight:bold;'>" + value + "%</span>";
17 } else {
18 return "<span style='color:green'>" + value + "%</span>";
19 }
20 }
21
22 function PercentCompleteBarFormatter(row, cell, value, columnDef, dataContext) {
23 if (value == null || value === "") {
24 return "";
25 }
26
27 var color;
28
29 if (value < 30) {
30 color = "red";
31 } else if (value < 70) {
32 color = "silver";
33 } else {
34 color = "green";
35 }
36
37 return "<span class='percent-complete-bar' style='background:" + color + ";width:" + value + "%' title='" + value + "%'></span>";
38 }
39
40 function YesNoFormatter(row, cell, value, columnDef, dataContext) {
41 return value ? "Yes" : "No";
42 }
43
44 function CheckboxFormatter(row, cell, value, columnDef, dataContext) {
45 return '<img class="slick-edit-preclick" src="../images/' + (value ? "CheckboxY" : "CheckboxN") + '.png">';
46 }
47
48 function CheckmarkFormatter(row, cell, value, columnDef, dataContext) {
49 return value ? "<img src='../images/tick.png'>" : "";
50 }
51
52 // exports
53 $.extend(true, window, {
54 "Slick": {
55 "Formatters": {
56 "PercentComplete": PercentCompleteFormatter,
57 "PercentCompleteBar": PercentCompleteBarFormatter,
58 "YesNo": YesNoFormatter,
59 "Checkmark": CheckmarkFormatter,
60 "Checkbox": CheckboxFormatter
61
62 }
63 }
64 });
65})(jQuery);