Skip to content

Commit f22507e

Browse files
author
Damian Peralta
committed
WIP...
1 parent 7948b47 commit f22507e

File tree

1 file changed

+66
-66
lines changed

1 file changed

+66
-66
lines changed

js/fixed_table_rc.js

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2525
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2626
*/
2727
(function ($) {
28-
28+
2929
$.fn.fxdHdrCol = function (o) {
3030
var cfg = {
3131
height: 0,
32-
width: 0,
32+
width: 0,
3333
fixedCols: 0,
34-
colModal: [],
34+
colModal: [],
3535
tableTmpl: function () {
36-
return '<table />';
36+
return '<table />';
3737
},
3838
sort: false
3939
};
4040
$.extend(cfg, o);
41-
41+
4242
return this.each (function () {
4343
var lc = {
4444
ft_container: null,
@@ -49,22 +49,22 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4949
ft_c: null,
5050
tableWidth: 0
5151
};
52-
52+
5353
var $this = $(this);
5454
$this.addClass('ui-widget-header');
5555
$this.find('tbody tr').addClass('ui-widget-content');
56-
56+
5757
$this.wrap('<div class="ft_container" />');
58-
lc.ft_container = $this.parent().css({width: cfg.width, height: cfg.height});
59-
58+
lc.ft_container = $this.parent().css({width: cfg.width, height: cfg.height});
59+
6060
var $ths = $('thead tr', $this).first().find('th');
61-
62-
if (cfg.sort && sorttable && cfg.fixedCols == 0) {
63-
$ths.addClass('fx_sort_bg');
61+
62+
if (cfg.sort && sorttable && cfg.fixedCols == 0) {
63+
$ths.addClass('fx_sort_bg');
6464
}
6565

6666
var $thFirst = $ths.first();
67-
var thSpace = parseInt($thFirst.css('paddingLeft'), 10) + parseInt($thFirst.css('paddingRight'), 10);
67+
var thSpace = parseInt($thFirst.css('paddingLeft'), 0) + parseInt($thFirst.css('paddingRight'), 0);
6868

6969
/* set width and textAlign from colModal */
7070
var ct = 0;
@@ -75,30 +75,30 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7575
ct++;
7676
}
7777
$(el).css({width: calcWidth, textAlign: cfg.colModal[ct-1].align});
78-
78+
7979
lc.tableWidth += calcWidth + thSpace + ((i == 0)?2:1);
8080
});
81-
81+
8282
$('tbody', $this).find('tr').each(function (i, el) {
8383
$('td', el).each(function (i, tdel) {
8484
tdel.style.textAlign = cfg.colModal[i].align;
8585
});
8686
});
87-
87+
8888
$this.width(lc.tableWidth);
8989

9090
//add relative container
9191
$this.wrap('<div class="ft_rel_container" />');
9292
lc.ft_rel_container = $this.parent();
93-
93+
9494
//add wrapper to base table which will have the scrollbars
9595
$this.wrap('<div class="ft_scroller" />');
9696
lc.ft_wrapper = $this.parent().css('width', cfg.width - 5);
97-
97+
9898
var theadTr = $('thead', $this);
99-
//clone the thead->tr
99+
//clone the thead->tr
100100
var theadTrClone = theadTr.clone();
101-
101+
102102
//construct fixed row (full row)
103103
lc.ft_rel_container
104104
.prepend($(cfg.tableTmpl(), {'class': 'ft_r ui-widget-header'})
@@ -107,135 +107,135 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
107107
//an instance of fixed row
108108
lc.ft_r = $('.ft_r', lc.ft_rel_container);
109109
lc.ft_r.wrap($('<div />', {'class': 'ft_rwrapper'}));
110-
110+
111111
lc.ft_r.width(lc.tableWidth);
112-
112+
113113
if (cfg.fixedCols > 0) {
114-
//clone the thead again to construct the
114+
//clone the thead again to construct the
115115
theadTrClone = theadTr.clone();
116-
117-
//calculate the actual column's count (support for colspan)
118-
var r1c1ColSpan = 0;
116+
117+
//calculate the actual column's count (support for colspan)
118+
var r1c1ColSpan = 0;
119119
for (var i = 0; i < cfg.fixedCols; i++ ) {
120-
r1c1ColSpan += this.rows[0].cells[i].colSpan;
121-
}
122-
120+
r1c1ColSpan += this.rows[0].cells[i].colSpan;
121+
}
122+
123123
//prepare rows/cols for fixed row col section
124124
var tdct = 0;
125125
$('tr', theadTrClone).first().find('th').filter( function () {
126126
tdct += this.colSpan;
127127
return tdct > r1c1ColSpan;
128128
}).remove();
129-
129+
130130
//add fixed row col section
131131
lc.ft_rel_container
132132
.prepend($(cfg.tableTmpl(), {'class': 'ft_rc ui-widget-header'})
133133
.append(theadTrClone));
134-
134+
135135
//an instance of fixed row column
136136
lc.ft_rc = $('.ft_rc', lc.ft_rel_container);
137-
137+
138138
//now clone the fixed row column and append tbody for the remaining rows
139139
lc.ft_c = lc.ft_rc.clone();
140140
lc.ft_c[0].className = 'ft_c';
141-
141+
142142
//append tbody
143143
lc.ft_c.append('<tbody />');
144-
144+
145145
//append row by row while just keeping the frozen cols
146-
var ftc_tbody = lc.ft_c.find('tbody');
146+
var ftc_tbody = lc.ft_c.find('tbody');
147147
$.each ($this.find('tbody > tr'), function (idx, el) {
148148
var tr = $(el).clone();
149-
149+
150150
tdct = 0;
151151
tr.find('td').filter(function (){
152152
tdct += this.colSpan;
153153
return tdct > r1c1ColSpan;
154154
}).remove();
155-
155+
156156
ftc_tbody.append(tr);
157157
});
158-
158+
159159
lc.ft_rc.after(lc.ft_c);
160160
lc.ft_c.wrap($('<div />', {'class': 'ft_cwrapper'}));
161161

162162
var tw = 0;
163163
for (var i = 0; i < cfg.fixedCols; i++) {
164164
tw += $(this.rows[0].cells[i]).outerWidth(true);
165165
}
166-
lc.ft_c.add(lc.ft_rc).width(tw);
166+
lc.ft_c.add(lc.ft_rc).width(tw);
167167
lc.ft_c.height($this.outerHeight(true));
168-
168+
169169
//set height of fixed_rc and fixed_c
170170
for (var i = 0; i < this.rows.length; i++) {
171171
var ch = $(this.rows[i]).outerHeight();
172172
var fch = $(lc.ft_c[0].rows[i]).outerHeight(true);
173-
173+
174174
ch = (ch>fch)?ch:fch;
175-
175+
176176
if (i < lc.ft_rc[0].rows.length) {
177177
$(lc.ft_r[0].rows[i])
178-
.add(lc.ft_rc[0].rows[i])
178+
.add(lc.ft_rc[0].rows[i])
179179
.height(ch);
180180
}
181-
181+
182182
$(lc.ft_c[0].rows[i])
183183
.add(this.rows[i])
184184
.height(ch);
185185
}
186-
187-
lc.ft_c
186+
187+
lc.ft_c
188188
.parent()
189189
.css({height: lc.ft_container.height() - 17})
190190
.width(lc.ft_rc.outerWidth(true) + 1);
191-
}
191+
}
192192

193193
lc.ft_r
194194
.parent()
195195
.css({width: lc.ft_wrapper.width()- 17});
196-
196+
197197
//events (scroll and resize)
198198
lc.ft_wrapper.scroll(function () {
199-
if (cfg.fixedCols > 0) {
199+
if (cfg.fixedCols > 0) {
200200
lc.ft_c.css('top', ($(this).scrollTop()*-1));
201201
}
202202
lc.ft_r.css('left', ($(this).scrollLeft()*-1));
203203
});
204-
204+
205205
/*$(window).on('resize', function () {
206206
lc.ft_r
207207
.parent()
208-
.css({width: lc.ft_rel_container.width()- 17});
208+
.css({width: lc.ft_rel_container.width()- 17});
209209
});*/
210-
210+
211211
if (cfg.sort && sorttable && cfg.fixedCols == 0) {
212-
212+
213213
$('table', lc.ft_container).addClass('sorttable');
214-
214+
215215
sorttable.makeSortable(this);
216-
216+
217217
var $sortableTh = $('.fx_sort_bg', lc.ft_rel_container);
218-
218+
219219
$sortableTh.click (function () {
220220
var $this = $(this);
221-
var isAscSort = $this.hasClass('fx_sort_asc');
222-
221+
var isAscSort = $this.hasClass('fx_sort_asc');
222+
223223
$sortableTh.removeClass('fx_sort_asc fx_sort_desc');
224-
225-
if (isAscSort) {
226-
$this.addClass('fx_sort_desc').removeClass('fx_sort_asc');
227-
} else {
228-
$this.addClass('fx_sort_asc').removeClass('fx_sort_desc');
224+
225+
if (isAscSort) {
226+
$this.addClass('fx_sort_desc').removeClass('fx_sort_asc');
227+
} else {
228+
$this.addClass('fx_sort_asc').removeClass('fx_sort_desc');
229229
}
230-
230+
231231
var idx = $(this).index();
232-
232+
233233
sorttable.innerSortFunction.apply(lc.ft_wrapper.find('th').get(idx), []);
234234
});
235235
}
236236

237237
});
238238

239-
};
239+
};
240240

241241
})(jQuery);

0 commit comments

Comments
 (0)