-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.LockTableColumn.js
executable file
·68 lines (67 loc) · 2.13 KB
/
jquery.LockTableColumn.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
(function ($) {
var attr = {
target: '',
container: '',
mask: '',
index: '',
handle: '',
maskId: '',
targetId: ''
}
var methods = {
init: function () {
attr.target = this;
attr.targetId = $(attr.target).attr("id");
methods.setup();
methods.creatIndex();
methods.fixHeightRows();
methods.startScroll();
},
setup: function(){
$(attr.target).wrap('<div class="handle" />');
attr.handle = $(attr.target).parent();
$(attr.handle).wrap('<div class="DynamicTable_mask dragdealer" />');
attr.mask = $(attr.handle).parent();
attr.maskId = attr.targetId + "_dragdealer"
$(attr.mask).attr("id", attr.maskId)
$(attr.mask).wrap('<div class="DynamicTable_container" />');
attr.container = $(attr.mask).parent();
$(attr.container).prepend('<table class="DynamicTable_index" />');
attr.index = $(".DynamicTable_index", attr.container);
},
creatIndex: function(){
var item = $("tr > *:first-child", attr.container);
$("tr > *:first-child", attr.container).remove();
var str = "";
for(var i = 0; i < item.length; i++){
if(i == 0) {
$(attr.index).append("<tr><th>"+$(item[i]).html()+"</th></tr>");
} else {
$(attr.index).append("<tr><td>"+$(item[i]).html()+"</td></tr>");
}
}
},
fixHeightRows: function(){
var item = $("tr", attr.target);
var itemIndex = $("tr", attr.index);
for(var i = 0; i < item.length; i++){
$(itemIndex[i]).css("height", item[i].clientHeight);
}
},
startScroll: function(){
var ti = $(attr.index).outerHeight(true);
$(attr.mask).height(ti);
var itemId = $(attr.mask).attr("id");
new Dragdealer(itemId);
}
}
$.fn.locktable = function (method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method "' + method + '" does not exist on jQuery.locktable');
}
};
})(jQuery)