Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
morpheus.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Daria Zenkova
morpheus.js
Commits
cadb0099
Commit
cadb0099
authored
May 10, 2016
by
Joshua Gould
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed errant text
parent
697922f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
180 additions
and
180 deletions
+180
-180
src/ui/table.js
src/ui/table.js
+180
-180
No files found.
src/ui/table.js
View file @
cadb0099
...
...
@@ -14,203 +14,203 @@
* visible, name, field, renderer
*/
items
:
[],
morpheus
.
Table
=
function
(
options
)
{
options
=
morpheus
.
Table
.
createOptions
(
options
);
this
.
options
=
options
;
if
(
!
options
.
width
)
{
options
.
width
=
options
.
$el
.
attr
(
'
class
'
);
}
var
_this
=
this
;
var
height
=
options
.
height
;
var
$gridDiv
=
$
(
'
<div class="slick-table
'
+
(
options
.
tableClass
?
(
'
'
+
options
.
tableClass
)
:
''
)
+
'
" style="width:
'
+
options
.
fixedWidth
+
'
;height:
'
+
height
+
'
"></div>
'
);
this
.
$gridDiv
=
$gridDiv
;
$gridDiv
.
appendTo
(
options
.
$el
);
var
columns
=
options
.
columns
;
this
.
columns
=
columns
;
var
visibleColumns
=
columns
.
filter
(
function
(
c
)
{
return
c
.
visible
;
morpheus
.
Table
=
function
(
options
)
{
options
=
morpheus
.
Table
.
createOptions
(
options
);
this
.
options
=
options
;
if
(
!
options
.
width
)
{
options
.
width
=
options
.
$el
.
attr
(
'
class
'
);
}
var
_this
=
this
;
var
height
=
options
.
height
;
var
$gridDiv
=
$
(
'
<div class="slick-table
'
+
(
options
.
tableClass
?
(
'
'
+
options
.
tableClass
)
:
''
)
+
'
" style="width:
'
+
options
.
fixedWidth
+
'
;height:
'
+
height
+
'
"></div>
'
);
this
.
$gridDiv
=
$gridDiv
;
$gridDiv
.
appendTo
(
options
.
$el
);
var
columns
=
options
.
columns
;
this
.
columns
=
columns
;
var
visibleColumns
=
columns
.
filter
(
function
(
c
)
{
return
c
.
visible
;
});
var
grid
=
new
morpheus
.
Grid
({
gridOptions
:
{
select
:
options
.
select
,
rowHeight
:
options
.
rowHeight
,
autoEdit
:
false
,
editable
:
false
,
autoHeight
:
options
.
height
===
'
auto
'
,
enableTextSelectionOnCells
:
true
,
},
$el
:
$gridDiv
,
items
:
options
.
items
,
columns
:
visibleColumns
});
this
.
grid
=
grid
;
if
(
options
.
search
)
{
var
tableSearch
=
new
morpheus
.
TableSearchUI
();
tableSearch
.
$el
.
prependTo
(
options
.
$el
);
tableSearch
.
setTable
(
this
);
this
.
tableSearch
=
tableSearch
;
}
if
(
visibleColumns
.
length
!==
this
.
columns
.
length
)
{
var
select
=
[];
select
.
push
(
'
<select data-selected-text-format="static" title="Columns..." multiple class="form-control selectpicker show-tick pull-right">
'
);
this
.
columns
.
forEach
(
function
(
c
,
i
)
{
select
.
push
(
'
<option value="
'
+
i
+
'
"
'
);
if
(
c
.
visible
)
{
select
.
push
(
'
selected
'
);
}
select
.
push
(
'
>
'
);
select
.
push
(
c
.
name
);
select
.
push
(
'
</option>
'
);
});
var
grid
=
new
morpheus
.
Grid
({
gridOptions
:
{
select
:
options
.
select
,
rowHeight
:
options
.
rowHeight
,
autoEdit
:
false
,
editable
:
false
,
autoHeight
:
options
.
height
===
'
auto
'
,
enableTextSelectionOnCells
:
true
,
},
$el
:
$gridDiv
,
items
:
options
.
items
,
columns
:
visibleColumns
select
.
push
(
'
</select>
'
);
var
$select
=
$
(
select
.
join
(
''
));
var
$div
=
$
(
'
<div class="pull-right"></div>
'
);
$select
.
appendTo
(
$div
);
$div
.
prependTo
(
options
.
$el
);
$select
.
selectpicker
({
iconBase
:
'
fa
'
,
tickIcon
:
'
fa-check
'
,
style
:
'
btn-default btn-sm
'
});
this
.
grid
=
grid
;
if
(
options
.
search
)
{
var
tableSearch
=
new
morpheus
.
TableSearchUI
();
tableSearch
.
$el
.
prependTo
(
options
.
$el
);
tableSearch
.
setTable
(
this
);
this
.
tableSearch
=
tableSearch
;
}
if
(
visibleColumns
.
length
!==
this
.
columns
.
length
)
{
var
select
=
[];
select
.
push
(
'
<select data-selected-text-format="static" title="Columns..." multiple class="form-control selectpicker show-tick pull-right">
'
);
this
.
columns
.
forEach
(
function
(
c
,
i
)
{
select
.
push
(
'
<option value="
'
+
i
+
'
"
'
);
if
(
c
.
visible
)
{
select
.
push
(
'
selected
'
);
}
select
.
push
(
'
>
'
);
select
.
push
(
c
.
name
);
select
.
push
(
'
</option>
'
);
$select
.
on
(
'
change
'
,
function
()
{
var
selectedItems
=
$select
.
val
();
var
selectedItemsSet
=
new
morpheus
.
Set
();
selectedItems
.
forEach
(
function
(
item
)
{
selectedItemsSet
.
add
(
parseInt
(
item
));
});
select
.
push
(
'
</select>
'
);
var
$select
=
$
(
select
.
join
(
''
));
var
$div
=
$
(
'
<div class="pull-right"></div>
'
);
$select
.
appendTo
(
$div
);
$div
.
prependTo
(
options
.
$el
);
$select
.
selectpicker
({
iconBase
:
'
fa
'
,
tickIcon
:
'
fa-check
'
,
style
:
'
btn-default btn-sm
'
visibleColumns
=
[];
_this
.
columns
.
forEach
(
function
(
c
,
i
)
{
if
(
selectedItemsSet
.
has
(
i
))
{
visibleColumns
.
push
(
c
);
}
});
$select
.
on
(
'
change
'
,
function
()
{
var
selectedItems
=
$select
.
val
();
var
selectedItemsSet
=
new
morpheus
.
Set
();
selectedItems
.
forEach
(
function
(
item
)
{
selectedItemsSet
.
add
(
parseInt
(
item
));
});
visibleColumns
=
[];
_this
.
columns
.
forEach
(
function
(
c
,
i
)
{
if
(
selectedItemsSet
.
has
(
i
))
{
visibleColumns
.
push
(
c
);
}
});
grid
.
setColumns
(
visibleColumns
);
_this
.
resize
();
_this
.
redraw
();
grid
.
setColumns
(
visibleColumns
);
_this
.
resize
();
_this
.
redraw
();
});
});
}
var
collapsed
=
false
;
var
lastWidth
=
-
1
;
var
resize
=
function
()
{
if
(
!
_this
.
options
.
responsive
)
{
return
;
}
var
collapsed
=
false
;
var
lastWidth
=
-
1
;
var
resize
=
function
()
{
if
(
!
_this
.
options
.
responsive
)
{
return
;
}
var
gridWidth
=
options
.
$el
.
width
();
if
(
gridWidth
===
lastWidth
)
{
return
;
}
lastWidth
=
gridWidth
;
$gridDiv
.
css
(
'
width
'
,
gridWidth
+
'
px
'
);
// if (options.responsiveHeight) {
// var verticalPosition = _this.$gridDiv[0].getBoundingClientRect().top
// + window.pageYOffset;
// $gridDiv.css('height',
// (document.body.clientHeight - verticalPosition) + 'px');
// }
if
(
!
collapsed
&&
gridWidth
<
options
.
collapseBreakpoint
&&
visibleColumns
.
length
>
1
)
{
collapsed
=
true
;
$gridDiv
.
addClass
(
'
slick-stacked
'
);
_this
.
grid
.
grid
.
getOptions
().
rowHeight
=
(
options
.
collapsedRowHeight
?
options
.
collapsedRowHeight
:
options
.
rowHeight
)
*
visibleColumns
.
length
;
// collapse
_this
.
grid
.
grid
.
setColumns
([{
id
:
0
,
tooltip
:
function
(
item
,
value
)
{
var
html
=
[];
for
(
var
i
=
0
;
i
<
visibleColumns
.
length
;
i
++
)
{
var
text
=
visibleColumns
[
i
].
tooltip
(
item
,
visibleColumns
[
i
]
.
getter
(
item
));
if
(
text
!=
null
&&
text
!==
''
)
{
html
.
push
(
text
);
}
var
gridWidth
=
options
.
$el
.
width
();
if
(
gridWidth
===
lastWidth
)
{
return
;
}
lastWidth
=
gridWidth
;
$gridDiv
.
css
(
'
width
'
,
gridWidth
+
'
px
'
);
// if (options.responsiveHeight) {
// var verticalPosition = _this.$gridDiv[0].getBoundingClientRect().top
// + window.pageYOffset;
// $gridDiv.css('height',
// (document.body.clientHeight - verticalPosition) + 'px');
// }
if
(
!
collapsed
&&
gridWidth
<
options
.
collapseBreakpoint
&&
visibleColumns
.
length
>
1
)
{
collapsed
=
true
;
$gridDiv
.
addClass
(
'
slick-stacked
'
);
_this
.
grid
.
grid
.
getOptions
().
rowHeight
=
(
options
.
collapsedRowHeight
?
options
.
collapsedRowHeight
:
options
.
rowHeight
)
*
visibleColumns
.
length
;
// collapse
_this
.
grid
.
grid
.
setColumns
([{
id
:
0
,
tooltip
:
function
(
item
,
value
)
{
var
html
=
[];
for
(
var
i
=
0
;
i
<
visibleColumns
.
length
;
i
++
)
{
var
text
=
visibleColumns
[
i
].
tooltip
(
item
,
visibleColumns
[
i
]
.
getter
(
item
));
if
(
text
!=
null
&&
text
!==
''
)
{
html
.
push
(
text
);
}
return
html
.
join
(
'
<br />
'
);
},
collapsed
:
true
,
getter
:
function
(
item
)
{
return
item
;
},
formatter
:
function
(
row
,
cell
,
value
,
columnDef
,
dataContext
)
{
var
html
=
[];
html
.
push
(
'
<div class="slick-table-wrapper"><div class="slick-cell-wrapper">
'
);
if
(
options
.
rowHeader
)
{
// e.g. render checkbox
html
.
push
(
options
.
rowHeader
(
dataContext
));
}
return
html
.
join
(
'
<br />
'
);
},
collapsed
:
true
,
getter
:
function
(
item
)
{
return
item
;
},
formatter
:
function
(
row
,
cell
,
value
,
columnDef
,
dataContext
)
{
var
html
=
[];
html
.
push
(
'
<div class="slick-table-wrapper"><div class="slick-cell-wrapper">
'
);
if
(
options
.
rowHeader
)
{
// e.g. render checkbox
html
.
push
(
options
.
rowHeader
(
dataContext
));
html
.
push
(
'
<div style="height:4px;"></div>
'
);
}
for
(
var
i
=
0
;
i
<
visibleColumns
.
length
;
i
++
)
{
if
(
i
>
0
)
{
html
.
push
(
'
<div style="height:4px;"></div>
'
);
}
for
(
var
i
=
0
;
i
<
visibleColumns
.
length
;
i
++
)
{
if
(
i
>
0
)
{
html
.
push
(
'
<div style="height:4px;"></div>
'
);
}
var
c
=
visibleColumns
[
i
];
html
.
push
(
c
.
name
);
html
.
push
(
'
:
'
);
var
s
=
c
.
renderer
(
dataContext
,
c
.
getter
(
dataContext
));
html
.
push
(
s
);
}
html
.
push
(
'
</div></div>
'
);
return
html
.
join
(
''
);
},
sortable
:
false
,
name
:
''
}]);
$gridDiv
.
find
(
'
.slick-header
'
).
hide
();
_this
.
grid
.
grid
.
resizeCanvas
();
_this
.
grid
.
grid
.
invalidate
();
}
else
if
(
collapsed
&&
gridWidth
>=
options
.
collapseBreakpoint
)
{
$gridDiv
.
removeClass
(
'
slick-stacked
'
);
collapsed
=
false
;
if
(
options
.
showHeader
)
{
$gridDiv
.
find
(
'
.slick-header
'
).
show
();
}
_this
.
grid
.
grid
.
getOptions
().
rowHeight
=
options
.
rowHeight
;
_this
.
grid
.
grid
.
setColumns
(
visibleColumns
);
_this
.
grid
.
grid
.
resizeCanvas
();
if
(
options
.
select
)
{
_this
.
grid
.
grid
.
setSelectedRows
(
_this
.
grid
.
grid
.
getSelectedRows
());
}
_this
.
grid
.
grid
.
invalidate
();
}
else
{
_this
.
grid
.
grid
.
resizeCanvas
();
_this
.
grid
.
grid
.
invalidate
();
}
var
c
=
visibleColumns
[
i
];
html
.
push
(
c
.
name
);
html
.
push
(
'
:
'
);
var
s
=
c
.
renderer
(
dataContext
,
c
.
getter
(
dataContext
));
html
.
push
(
s
);
};
if
(
!
options
.
showHeader
)
{
}
html
.
push
(
'
</div></div>
'
);
return
html
.
join
(
''
);
},
sortable
:
false
,
name
:
''
}]);
$gridDiv
.
find
(
'
.slick-header
'
).
hide
();
}
if
(
options
.
responsive
)
{
$
(
window
).
on
(
'
resize orientationchange
'
,
resize
);
$gridDiv
.
on
(
'
remove
'
,
function
()
{
$
(
window
).
off
(
'
resize
'
,
resize
);
});
resize
();
}
this
.
resize
=
resize
;
if
(
visibleColumns
.
length
>
1
&&
options
.
items
!=
null
&&
options
.
items
.
length
>
0
)
{
this
.
setItems
(
options
.
items
);
_this
.
grid
.
grid
.
resizeCanvas
();
_this
.
grid
.
grid
.
invalidate
();
}
else
if
(
collapsed
&&
gridWidth
>=
options
.
collapseBreakpoint
)
{
$gridDiv
.
removeClass
(
'
slick-stacked
'
);
collapsed
=
false
;
if
(
options
.
showHeader
)
{
$gridDiv
.
find
(
'
.slick-header
'
).
show
();
}
_this
.
grid
.
grid
.
getOptions
().
rowHeight
=
options
.
rowHeight
;
_this
.
grid
.
grid
.
setColumns
(
visibleColumns
);
_this
.
grid
.
grid
.
resizeCanvas
();
if
(
options
.
select
)
{
_this
.
grid
.
grid
.
setSelectedRows
(
_this
.
grid
.
grid
.
getSelectedRows
());
}
_this
.
grid
.
grid
.
invalidate
();
}
else
{
_this
.
grid
.
grid
.
resizeCanvas
();
_this
.
grid
.
grid
.
invalidate
();
}
};
if
(
!
options
.
showHeader
)
{
$gridDiv
.
find
(
'
.slick-header
'
).
hide
();
}
if
(
options
.
responsive
)
{
$
(
window
).
on
(
'
resize orientationchange
'
,
resize
);
$gridDiv
.
on
(
'
remove
'
,
function
()
{
$
(
window
).
off
(
'
resize
'
,
resize
);
});
resize
();
}
this
.
resize
=
resize
;
if
(
visibleColumns
.
length
>
1
&&
options
.
items
!=
null
&&
options
.
items
.
length
>
0
)
{
this
.
setItems
(
options
.
items
);
}
};
morpheus
.
Table
.
defaultRenderer
=
function
(
item
,
value
)
{
if
(
_
.
isNumber
(
value
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment