Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Uni Osnabrück
Stud.IP
Commits
b2bbd291
Commit
b2bbd291
authored
2 years ago
by
Jan-Hendrik Willms
Committed by
Rasmus Fuhse
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
allow widgets to be passed to tablesorter, fixes #1307
Closes #1307 Merge request
studip/studip!804
parent
0e194a69
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
resources/assets/javascripts/lib/table.js
+68
-44
68 additions, 44 deletions
resources/assets/javascripts/lib/table.js
with
68 additions
and
44 deletions
resources/assets/javascripts/lib/table.js
+
68
−
44
View file @
b2bbd291
function
enhanceSortableTable
(
table
)
{
var
headers
=
{};
$
(
'
thead tr:last th
'
,
table
).
each
(
function
(
index
,
element
)
{
/**
* This class is used to enhance sortable tables in Stud.IP by using the
* tablesorter plugin.
*
* @see https://mottie.github.io/tablesorter/docs/
*/
class
Table
{
/**
* This method will make the given sortable. The table my be given as a
* DOM element or wrapped in a jQuery object.
*
* Additional widgets for the tablesorter may be passed as an array via
* the attribute [data-sort-widgets].
* (see https://mottie.github.io/tablesorter/docs/example-widgets.html)
*
* @param table
*/
static
async
enhanceSortableTable
(
table
)
{
// Unjquerify table
if
(
table
instanceof
jQuery
)
{
table
=
table
.
get
(
0
);
}
await
STUDIP
.
loadChunk
(
'
tablesorter
'
);
// Iterate over the header columns and determine sorting mechanism
let
headers
=
{};
$
(
'
thead tr:last th
'
,
table
).
each
((
index
,
element
)
=>
{
headers
[
index
]
=
{
sorter
:
$
(
element
)
.
data
()
.
sort
||
false
sorter
:
element
.
data
set
.
sort
??
false
};
});
// Handle potential fixed rows
if
(
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
length
>
0
)
{
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
each
(
function
()
{
$
(
this
).
data
(
'
sort-fixed
'
,
{
...
...
@@ -13,18 +41,14 @@ function enhanceSortableTable(table) {
tbody
:
$
(
this
).
closest
(
'
table
'
).
find
(
'
tbody
'
).
index
(
$
(
this
).
parent
())
});
});
$
(
table
)
.
on
(
'
sortStart
'
,
function
()
{
$
(
table
).
on
(
'
sortStart
'
,
()
=>
{
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
each
(
function
()
{
var
hidden
=
$
(
this
).
is
(
'
:hidden
'
);
const
hidden
=
$
(
this
).
is
(
'
:hidden
'
);
$
(
this
).
data
(
'
sort-hidden
'
,
hidden
);
});
})
.
on
(
'
sortEnd
'
,
function
()
{
$
(
'
tbody tr[data-sort-fixed]
'
,
table
)
.
detach
()
.
each
(
function
()
{
var
pos
=
$
(
this
).
data
(
'
sort-fixed
'
);
}).
on
(
'
sortEnd
'
,
()
=>
{
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
detach
().
each
(
function
()
{
const
pos
=
$
(
this
).
data
(
'
sort-fixed
'
);
if
(
$
(
`tbody:eq(
${
pos
.
tbody
}
) tr:eq(
${
pos
.
index
}
)`
,
table
).
length
>
0
)
{
$
(
`tbody:eq(
${
pos
.
tbody
}
) tr:eq(
${
pos
.
index
}
)`
,
table
).
before
(
this
);
}
else
{
...
...
@@ -38,18 +62,18 @@ function enhanceSortableTable(table) {
});
}
// Get additional widgets
const
widgets
=
$
(
table
).
data
().
sortWidgets
??
[];
// Actually activate table sorter
$
(
table
).
tablesorter
({
headers
:
headers
,
sortLocaleCompare
:
true
,
sortRestart
:
true
,
widthFixed
:
false
widthFixed
:
false
,
widgets
:
Array
.
isArray
(
widgets
)
?
widgets
:
[]
});
}
const
Table
=
{
enhanceSortableTable
:
function
(
table
)
{
STUDIP
.
loadChunk
(
'
tablesorter
'
).
then
(()
=>
enhanceSortableTable
(
table
));
}
};
export
default
Table
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment