|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+/**
|
|
|
2
|
+ * @author zhixin wen <wenzhixin2010@gmail.com>
|
|
|
3
|
+ * @version: v1.0.1
|
|
|
4
|
+ * Modificated 16.08.16 by Aleksej Tokarev (Loecha)
|
|
|
5
|
+ * - Sorting Problem solved
|
|
|
6
|
+ * - Recalculated Size of fixed Columns
|
|
|
7
|
+ */
|
|
|
8
|
+
|
|
|
9
|
+(function ($) {
|
|
|
10
|
+ 'use strict';
|
|
|
11
|
+
|
|
|
12
|
+ $.extend($.fn.bootstrapTable.defaults, {
|
|
|
13
|
+ fixedColumns: false,
|
|
|
14
|
+ fixedNumber: 1
|
|
|
15
|
+ });
|
|
|
16
|
+
|
|
|
17
|
+ var BootstrapTable = $.fn.bootstrapTable.Constructor,
|
|
|
18
|
+ _initHeader = BootstrapTable.prototype.initHeader,
|
|
|
19
|
+ _initBody = BootstrapTable.prototype.initBody,
|
|
|
20
|
+ _resetView = BootstrapTable.prototype.resetView,
|
|
|
21
|
+ _getCaret = BootstrapTable.prototype.getCaret; // Add: Aleksej
|
|
|
22
|
+
|
|
|
23
|
+ BootstrapTable.prototype.initFixedColumns = function () {
|
|
|
24
|
+ this.$fixedHeader = $([
|
|
|
25
|
+ '<div class="fixed-table-header-columns">',
|
|
|
26
|
+ '<table>',
|
|
|
27
|
+ '<thead></thead>',
|
|
|
28
|
+ '</table>',
|
|
|
29
|
+ '</div>'].join(''));
|
|
|
30
|
+
|
|
|
31
|
+ this.timeoutHeaderColumns_ = 0;
|
|
|
32
|
+ this.$fixedHeader.find('table').attr('class', this.$el.attr('class'));
|
|
|
33
|
+ this.$fixedHeaderColumns = this.$fixedHeader.find('thead');
|
|
|
34
|
+ this.$tableHeader.before(this.$fixedHeader);
|
|
|
35
|
+
|
|
|
36
|
+ this.$fixedBody = $([
|
|
|
37
|
+ '<div class="fixed-table-body-columns">',
|
|
|
38
|
+ '<table>',
|
|
|
39
|
+ '<tbody></tbody>',
|
|
|
40
|
+ '</table>',
|
|
|
41
|
+ '</div>'].join(''));
|
|
|
42
|
+
|
|
|
43
|
+ this.timeoutBodyColumns_ = 0;
|
|
|
44
|
+ this.$fixedBody.find('table').attr('class', this.$el.attr('class'));
|
|
|
45
|
+ this.$fixedBodyColumns = this.$fixedBody.find('tbody');
|
|
|
46
|
+ this.$tableBody.before(this.$fixedBody);
|
|
|
47
|
+ };
|
|
|
48
|
+
|
|
|
49
|
+ BootstrapTable.prototype.initHeader = function () {
|
|
|
50
|
+ _initHeader.apply(this, Array.prototype.slice.apply(arguments));
|
|
|
51
|
+
|
|
|
52
|
+ if (!this.options.fixedColumns) {
|
|
|
53
|
+ return;
|
|
|
54
|
+ }
|
|
|
55
|
+
|
|
|
56
|
+ this.initFixedColumns();
|
|
|
57
|
+
|
|
|
58
|
+ var that = this, $trs = this.$header.find('tr').clone(true); //Fix: Aleksej "clone()" mit "clone(true)" ersetzt
|
|
|
59
|
+ $trs.each(function () {
|
|
|
60
|
+ // This causes layout problems:
|
|
|
61
|
+ //$(this).find('th:gt(' + (that.options.fixedNumber -1) + ')').remove(); // Fix: Aleksej "-1" hinnzugefügt. Denn immer eine Spalte Mehr geblieben ist
|
|
|
62
|
+ $(this).find('th:gt(' + that.options.fixedNumber + ')').remove();
|
|
|
63
|
+ });
|
|
|
64
|
+ this.$fixedHeaderColumns.html('').append($trs);
|
|
|
65
|
+ };
|
|
|
66
|
+
|
|
|
67
|
+ BootstrapTable.prototype.initBody = function () {
|
|
|
68
|
+ _initBody.apply(this, Array.prototype.slice.apply(arguments));
|
|
|
69
|
+
|
|
|
70
|
+ if (!this.options.fixedColumns) {
|
|
|
71
|
+ return;
|
|
|
72
|
+ }
|
|
|
73
|
+
|
|
|
74
|
+ var that = this,
|
|
|
75
|
+ rowspan = 0;
|
|
|
76
|
+
|
|
|
77
|
+ this.$fixedBodyColumns.html('');
|
|
|
78
|
+ this.$body.find('> tr[data-index]').each(function () {
|
|
|
79
|
+ var $tr = $(this).clone(),
|
|
|
80
|
+ $tds = $tr.find('td');
|
|
|
81
|
+
|
|
|
82
|
+ var dataIndex = $tr.attr("data-index");
|
|
|
83
|
+ $tr = $("<tr></tr>");
|
|
|
84
|
+ $tr.attr("data-index", dataIndex);
|
|
|
85
|
+
|
|
|
86
|
+ var end = that.options.fixedNumber;
|
|
|
87
|
+ if (rowspan > 0) {
|
|
|
88
|
+ --end;
|
|
|
89
|
+ --rowspan;
|
|
|
90
|
+ }
|
|
|
91
|
+ for (var i = 0; i < end; i++) {
|
|
|
92
|
+ $tr.append($tds.eq(i).clone());
|
|
|
93
|
+ }
|
|
|
94
|
+ that.$fixedBodyColumns.append($tr);
|
|
|
95
|
+
|
|
|
96
|
+ if ($tds.eq(0).attr('rowspan')){
|
|
|
97
|
+ rowspan = $tds.eq(0).attr('rowspan') - 1;
|
|
|
98
|
+ }
|
|
|
99
|
+ });
|
|
|
100
|
+ };
|
|
|
101
|
+
|
|
|
102
|
+ BootstrapTable.prototype.resetView = function () {
|
|
|
103
|
+ _resetView.apply(this, Array.prototype.slice.apply(arguments));
|
|
|
104
|
+
|
|
|
105
|
+ if (!this.options.fixedColumns) {
|
|
|
106
|
+ return;
|
|
|
107
|
+ }
|
|
|
108
|
+
|
|
|
109
|
+ clearTimeout(this.timeoutHeaderColumns_);
|
|
|
110
|
+ this.timeoutHeaderColumns_ = setTimeout($.proxy(this.fitHeaderColumns, this), this.$el.is(':hidden') ? 100 : 0);
|
|
|
111
|
+
|
|
|
112
|
+ clearTimeout(this.timeoutBodyColumns_);
|
|
|
113
|
+ this.timeoutBodyColumns_ = setTimeout($.proxy(this.fitBodyColumns, this), this.$el.is(':hidden') ? 100 : 0);
|
|
|
114
|
+ };
|
|
|
115
|
+
|
|
|
116
|
+ BootstrapTable.prototype.fitHeaderColumns = function () {
|
|
|
117
|
+ var that = this,
|
|
|
118
|
+ visibleFields = this.getVisibleFields(),
|
|
|
119
|
+ headerWidth = 0;
|
|
|
120
|
+
|
|
|
121
|
+ this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
|
|
|
122
|
+ var $this = $(this),
|
|
|
123
|
+ index = i;
|
|
|
124
|
+
|
|
|
125
|
+ if (i >= that.options.fixedNumber) {
|
|
|
126
|
+ return false;
|
|
|
127
|
+ }
|
|
|
128
|
+
|
|
|
129
|
+ if (that.options.detailView && !that.options.cardView) {
|
|
|
130
|
+ index = i - 1;
|
|
|
131
|
+ }
|
|
|
132
|
+
|
|
|
133
|
+ var $th = that.$fixedHeader.find('th[data-field="' + visibleFields[index] + '"]');
|
|
|
134
|
+ $th.find('.fht-cell').width($this.innerWidth());
|
|
|
135
|
+ headerWidth += $this.outerWidth();
|
|
|
136
|
+
|
|
|
137
|
+ $th.data('fix-pos', index);
|
|
|
138
|
+ });
|
|
|
139
|
+ this.$fixedHeader.width(headerWidth + 1).show();
|
|
|
140
|
+
|
|
|
141
|
+ // fix click event
|
|
|
142
|
+ this.$fixedHeader.delegate("tr th", 'click', function() {
|
|
|
143
|
+ $(this).parents(".fixed-table-container").find(".fixed-table-body table thead tr th:eq("+$(this).data("fix-pos")+") .sortable").click();
|
|
|
144
|
+ })
|
|
|
145
|
+ };
|
|
|
146
|
+
|
|
|
147
|
+ /**
|
|
|
148
|
+ * Add: Aleksej
|
|
|
149
|
+ * Hook für getCaret. Aktualisieren Header bei Fixed-Columns wenn diese sortiert wurden
|
|
|
150
|
+ * @method getCaret
|
|
|
151
|
+ * @for BootstrapTable
|
|
|
152
|
+ */
|
|
|
153
|
+ BootstrapTable.prototype.getCaret = function () {
|
|
|
154
|
+ var result = _getCaret.apply(this, arguments);
|
|
|
155
|
+
|
|
|
156
|
+ if (this.options.fixedColumns && this.$fixedHeaderColumns instanceof jQuery) {
|
|
|
157
|
+ var that = this, $th;
|
|
|
158
|
+
|
|
|
159
|
+ $.each(this.$fixedHeaderColumns.find('th'), function (i, th) {
|
|
|
160
|
+ $th = $(th);
|
|
|
161
|
+ $th.find('.sortable').removeClass('desc asc').addClass($th.data('field') === that.options.sortName ? that.options.sortOrder : 'both');
|
|
|
162
|
+ });
|
|
|
163
|
+ }
|
|
|
164
|
+
|
|
|
165
|
+ return result;
|
|
|
166
|
+ };
|
|
|
167
|
+
|
|
|
168
|
+ /**
|
|
|
169
|
+ * Add: Aleksej, zum berechnen von Scrollbar-Größe
|
|
|
170
|
+ * @method calcScrollBarSize
|
|
|
171
|
+ * @return Number
|
|
|
172
|
+ */
|
|
|
173
|
+ BootstrapTable.prototype.calcScrollBarSize = function () {
|
|
|
174
|
+ // Es ist egal, ob Höhe oder Breite
|
|
|
175
|
+ var tmpWidth = 100,
|
|
|
176
|
+ $container = $('<div>').css({
|
|
|
177
|
+ width : tmpWidth,
|
|
|
178
|
+ overflow : 'scroll',
|
|
|
179
|
+ visibility : 'hidden'}
|
|
|
180
|
+ ).appendTo('body'),
|
|
|
181
|
+ widthWithScroll = $('<div>').css({
|
|
|
182
|
+ width: '100%'
|
|
|
183
|
+ }).appendTo($container).outerWidth();
|
|
|
184
|
+
|
|
|
185
|
+ $container.remove();
|
|
|
186
|
+ return tmpWidth - widthWithScroll;
|
|
|
187
|
+ };
|
|
|
188
|
+
|
|
|
189
|
+ BootstrapTable.prototype.fitBodyColumns = function () {
|
|
|
190
|
+ var that = this,
|
|
|
191
|
+ borderHeight = (parseInt(this.$el.css('border-bottom-width')) + parseInt(this.$el.css('border-top-width'))), // Add. Aleksej
|
|
|
192
|
+ top = this.$fixedHeader.outerHeight() + borderHeight, // Fix. Aleksej "-2" mit "+ borderHeight" ersetzt
|
|
|
193
|
+ // the fixed height should reduce the scorll-x height
|
|
|
194
|
+ height = this.$tableBody.height() - this.calcScrollBarSize(); // Fix. Aleksej "-14" mit "- this.calcScrollBarSize()" ersetzt
|
|
|
195
|
+
|
|
|
196
|
+ if (!this.$body.find('> tr[data-index]').length) {
|
|
|
197
|
+ this.$fixedBody.hide();
|
|
|
198
|
+ return;
|
|
|
199
|
+ }
|
|
|
200
|
+
|
|
|
201
|
+ if (!this.options.height) {
|
|
|
202
|
+ top = this.$fixedHeader.height();
|
|
|
203
|
+ height = height - top;
|
|
|
204
|
+ }
|
|
|
205
|
+
|
|
|
206
|
+ this.$fixedBody.css({
|
|
|
207
|
+ width: this.$fixedHeader.width(),
|
|
|
208
|
+ height: height,
|
|
|
209
|
+ top: top
|
|
|
210
|
+ }).show();
|
|
|
211
|
+
|
|
|
212
|
+ this.$body.find('> tr').each(function (i) {
|
|
|
213
|
+ that.$fixedBody.find('tr:eq(' + i + ')').height($(this).height() - 1);
|
|
|
214
|
+ });
|
|
|
215
|
+
|
|
|
216
|
+ // events
|
|
|
217
|
+ this.$tableBody.on('scroll', function () {
|
|
|
218
|
+ that.$fixedBody.find('table').css('top', -$(this).scrollTop());
|
|
|
219
|
+ });
|
|
|
220
|
+ this.$body.find('> tr[data-index]').off('hover').hover(function () {
|
|
|
221
|
+ var index = $(this).data('index');
|
|
|
222
|
+ that.$fixedBody.find('tr[data-index="' + index + '"]').addClass('hover');
|
|
|
223
|
+ }, function () {
|
|
|
224
|
+ var index = $(this).data('index');
|
|
|
225
|
+ that.$fixedBody.find('tr[data-index="' + index + '"]').removeClass('hover');
|
|
|
226
|
+ });
|
|
|
227
|
+ this.$fixedBody.find('tr[data-index]').off('hover').hover(function () {
|
|
|
228
|
+ var index = $(this).data('index');
|
|
|
229
|
+ that.$body.find('tr[data-index="' + index + '"]').addClass('hover');
|
|
|
230
|
+ }, function () {
|
|
|
231
|
+ var index = $(this).data('index');
|
|
|
232
|
+ that.$body.find('> tr[data-index="' + index + '"]').removeClass('hover');
|
|
|
233
|
+ });
|
|
|
234
|
+
|
|
|
235
|
+ // fix td width bug
|
|
|
236
|
+ var $first_tr = that.$body.find('tr:eq(0)');
|
|
|
237
|
+ that.$fixedBody.find('tr:eq(0)').find("td").each(function(index) {
|
|
|
238
|
+ $(this).width($first_tr.find("td:eq("+index+")").width())
|
|
|
239
|
+ });
|
|
|
240
|
+ };
|
|
|
241
|
+
|
|
|
242
|
+})(jQuery);
|