-
Notifications
You must be signed in to change notification settings - Fork 775
/
Copy pathutil.js
134 lines (119 loc) · 4.06 KB
/
util.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
125
126
127
128
129
130
131
132
133
134
/* eslint react/display-name: 0 */
import React from 'react';
import Const from './Const';
import classSet from 'classnames';
export default {
renderReactSortCaret(order, isBootstrap4) {
let orderClass;
if (isBootstrap4) {
orderClass = classSet('fa', {
'fa-sort-asc': order === Const.SORT_ASC,
'fa-sort-desc': order === Const.SORT_DESC
});
return (
<span className={ orderClass } style={ { margin: '10px 5px' } }></span>
);
} else {
orderClass = classSet('order', {
'dropup': order === Const.SORT_ASC
});
return (
<span className={ orderClass }>
<span className='caret' style={ { margin: '10px 5px' } }></span>
</span>
);
}
},
isFunction(obj) {
return obj && (typeof obj === 'function');
},
getScrollBarWidth() {
const inner = document.createElement('p');
inner.style.width = '100%';
inner.style.height = '200px';
const outer = document.createElement('div');
outer.style.position = 'absolute';
outer.style.top = '0px';
outer.style.left = '0px';
outer.style.visibility = 'hidden';
outer.style.width = '200px';
outer.style.height = '150px';
outer.style.overflow = 'hidden';
outer.appendChild(inner);
document.body.appendChild(outer);
const w1 = inner.getBoundingClientRect().width;
outer.style.overflow = 'scroll';
let w2 = inner.getBoundingClientRect().width;
if (w1 === w2) w2 = outer.clientWidth;
document.body.removeChild(outer);
return (w1 - w2);
},
canUseDOM() {
return typeof window !== 'undefined' && typeof window.document !== 'undefined';
},
// We calculate an offset here in order to properly fetch the indexed data,
// despite the page start index not always being 1
getNormalizedPage(pageStartIndex, page) {
pageStartIndex = this.getFirstPage(pageStartIndex);
if (page === undefined) page = pageStartIndex;
const offset = Math.abs(Const.PAGE_START_INDEX - pageStartIndex);
return page + offset;
},
getFirstPage(pageStartIndex) {
return pageStartIndex !== undefined ? pageStartIndex : Const.PAGE_START_INDEX;
},
isBootstrap4(version) {
return version === '4';
},
isSelectRowDefined(mode) {
return mode === Const.ROW_SELECT_SINGLE || mode === Const.ROW_SELECT_MULTI;
},
renderColGroup(columns, selectRow, expandColumnOptions = {}, version) {
let selectRowHeader = null;
let expandRowHeader = null;
const isBootstrap4 = this.isBootstrap4(version);
const isSelectRowDefined = this.isSelectRowDefined(selectRow.mode);
const columnWidth = isBootstrap4 ? '38px' : '30px';
if (isSelectRowDefined) {
const style = {
width: selectRow.columnWidth || columnWidth,
minWidth: selectRow.columnWidth || columnWidth
};
if (!selectRow.hideSelectColumn) {
selectRowHeader = (<col key='select-col' style={ style }></col>);
}
}
if (expandColumnOptions.expandColumnVisible) {
const style = {
width: expandColumnOptions.columnWidth || columnWidth,
minWidth: expandColumnOptions.columnWidth || columnWidth
};
expandRowHeader = (<col key='expand-col' style={ style }></col>);
}
const theader = columns.map(function(column, i) {
const style = {
display: column.hidden ? 'none' : null
};
if (column.width) {
const width = !isNaN(column.width) ? column.width + 'px' : column.width;
style.width = width;
/** add min-wdth to fix user assign column width
not eq offsetWidth in large column table **/
style.minWidth = width;
}
return (<col style={ style } key={ i }></col>);
});
return (
<colgroup>
{ expandColumnOptions.expandColumnVisible &&
expandColumnOptions.expandColumnBeforeSelectColumn &&
expandRowHeader }
{ selectRowHeader }
{ expandColumnOptions.expandColumnVisible &&
!expandColumnOptions.expandColumnBeforeSelectColumn &&
expandRowHeader }
{ theader }
</colgroup>
);
}
};