forked from hungphambms/adpp-rowspanizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.rowspanizer.min.js
executable file
·124 lines (96 loc) · 3.78 KB
/
jquery.rowspanizer.min.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*!
* jQuery Rowspanizer Plugin v0.1 for ADPP
*
* https://github.com/hungphambms/adpp-rowspanizer.git
*
* Copyright 2018 @hungphambms
* Released under the MIT license
*
* https://github.com/hungphambms/adpp-rowspanizer.git
*/
;(function ($, window, document, undefined) {
"use strict";
var rowspanizer = "rowspanizer",
defaults = {
vertical_align: "top"
};
function f(element, options) {
this.element = element;
this.settings = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = rowspanizer;
this.init();
}
$.extend(f.prototype, {
init: function () {
var _this = this;
var $table = $(this.element);
var arr = [];
var columnHeight = 0;
if ($table.find('tbody td').length) {
columnHeight = $table.find('tbody td').outerHeight();
}
$table.find("tbody tr").each(function (r, tr) {
$(this).find("td").each(function (d, td) {
var $td = $(td);
var v_dato = $td.attr("data-value");
var group_id = $td.attr("data-group-id");
var metric_id = $td.attr("metric-id");
group_id = "COMBINE_ID_SAMPLE";
if (!v_dato || typeof v_dato === "undefined" || v_dato === 0 || v_dato === "0") {
return;
}
// check metric columns
if (metric_id
&& metric_id.indexOf("total_") === -1
&& metric_id.indexOf("group_") === -1
&& metric_id.indexOf("divergent_imp") === -1) {
return;
}
// check empty values
if (!v_dato || v_dato === "" || v_dato === " " || v_dato === "N/A") {
return;
}
// check empty values
// if (typeof arr[d] === "undefined" || !group_id || group_id === "" || group_id === " ") {
// return;
// }
if (typeof arr[d] != "undefined"
&& "dato" in arr[d]
&& arr[d].dato == v_dato
&& arr[d].group_id == group_id) {
var rs = arr[d].elem.data("rowspan");
if (rs == "undefined" || isNaN(rs)) rs = 1;
arr[d].elem.data("rowspan", parseInt(rs) + 1).addClass("rowspan-combine");
$td.addClass("rowspan-remove");
} else {
arr[d] = {dato: v_dato, elem: $td, group_id: group_id};
}
;
});
});
$(".rowspan-combine").each(function (r, tr) {
var $this = $(this);
$this.attr("rowspan", $this.data("rowspan")).css({"vertical-align": _this.settings.vertical_align});
});
$(".rowspan-remove").remove();
// re calculate height
$table.find("tbody td").each(function (d, td) {
var $td = $(td);
var rowspan = $td.attr("rowspan");
if (!rowspan) {
return;
}
$td.css('cssText', `height: ${34 * rowspan}px !important;`);
});
}
});
$.fn[rowspanizer] = function (options) {
return this.each(function () {
if (!$.data(this, "plugin_" + rowspanizer)) {
$.data(this, "plugin_" +
rowspanizer, new f(this, options));
}
});
};
})(jQuery, window, document);