forked from fooplugins/FooTable
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfootable.striping.js
57 lines (45 loc) · 1.45 KB
/
footable.striping.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
(function ($, w, undefined) {
if (w.footable === undefined || w.foobox === null)
throw new Error('Please check and make sure footable.js is included in the page and is loaded prior to this script.');
var defaults = {
striping: {
enabled: true
},
classes: {
striping: {
odd: 'footable-odd',
even: 'footable-even'
}
}
};
function Striping() {
var p = this;
p.name = 'Footable Striping';
p.init = function (ft) {
p.footable = ft;
$(ft.table)
.unbind('striping')
.bind({
'footable_initialized.striping footable_row_removed.striping footable_redrawn.striping footable_sorted.striping footable_filtered.striping': function () {
if ($(this).data('striping') === false) return;
p.setupStriping(ft);
}
});
};
p.setupStriping = function (ft) {
var rowIndex = 0;
$(ft.table).find('> tbody > tr:not(.footable-row-detail)').each(function () {
var $row = $(this);
//Clean off old classes
$row.removeClass(ft.options.classes.striping.even).removeClass(ft.options.classes.striping.odd);
if (rowIndex % 2 === 0) {
$row.addClass(ft.options.classes.striping.even);
} else {
$row.addClass(ft.options.classes.striping.odd);
}
rowIndex++;
});
};
}
w.footable.plugins.register(Striping, defaults);
})(jQuery, window);