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
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Marcus Eibrink-Lunzenauer
Stud.IP
Commits
b2bbd291
Commit
b2bbd291
authored
1 year ago
by
Jan-Hendrik Willms
Committed by
Rasmus Fuhse
1 year 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
Hide 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
=
{};
* This class is used to enhance sortable tables in Stud.IP by using the
$
(
'
thead tr:last th
'
,
table
).
each
(
function
(
index
,
element
)
{
* tablesorter plugin.
headers
[
index
]
=
{
*
sorter
:
$
(
element
).
data
().
sort
||
false
* @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
);
}
if
(
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
length
>
0
)
{
await
STUDIP
.
loadChunk
(
'
tablesorter
'
);
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
each
(
function
()
{
$
(
this
).
data
(
'
sort-fixed
'
,
{
// Iterate over the header columns and determine sorting mechanism
index
:
$
(
this
).
index
(),
let
headers
=
{};
tbody
:
$
(
this
).
closest
(
'
table
'
).
find
(
'
tbody
'
).
index
(
$
(
this
).
parent
())
$
(
'
thead tr:last th
'
,
table
).
each
((
index
,
element
)
=>
{
});
headers
[
index
]
=
{
sorter
:
element
.
dataset
.
sort
??
false
};
});
});
$
(
table
)
.
on
(
'
sortStart
'
,
function
()
{
// Handle potential fixed rows
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
each
(
function
()
{
if
(
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
length
>
0
)
{
var
hidden
=
$
(
this
).
is
(
'
:hidden
'
);
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
each
(
function
()
{
$
(
this
).
data
(
'
sort-fixed
'
,
{
index
:
$
(
this
).
index
(),
tbody
:
$
(
this
).
closest
(
'
table
'
).
find
(
'
tbody
'
).
index
(
$
(
this
).
parent
())
});
});
$
(
table
).
on
(
'
sortStart
'
,
()
=>
{
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
each
(
function
()
{
const
hidden
=
$
(
this
).
is
(
'
:hidden
'
);
$
(
this
).
data
(
'
sort-hidden
'
,
hidden
);
$
(
this
).
data
(
'
sort-hidden
'
,
hidden
);
});
});
})
}).
on
(
'
sortEnd
'
,
()
=>
{
.
on
(
'
sortEnd
'
,
function
()
{
$
(
'
tbody tr[data-sort-fixed]
'
,
table
).
detach
().
each
(
function
()
{
$
(
'
tbody tr[data-sort-fixed]
'
,
table
)
const
pos
=
$
(
this
).
data
(
'
sort-fixed
'
);
.
detach
()
if
(
$
(
`tbody:eq(
${
pos
.
tbody
}
) tr:eq(
${
pos
.
index
}
)`
,
table
).
length
>
0
)
{
.
each
(
function
()
{
$
(
`tbody:eq(
${
pos
.
tbody
}
) tr:eq(
${
pos
.
index
}
)`
,
table
).
before
(
this
);
var
pos
=
$
(
this
).
data
(
'
sort-fixed
'
);
}
else
{
if
(
$
(
`tbody:eq(
${
pos
.
tbody
}
) tr:eq(
${
pos
.
index
}
)`
,
table
).
length
>
0
)
{
$
(
`tbody:eq(
${
pos
.
tbody
}
)`
,
table
).
append
(
this
);
$
(
`tbody:eq(
${
pos
.
tbody
}
) tr:eq(
${
pos
.
index
}
)`
,
table
).
before
(
this
);
}
}
else
{
$
(
`tbody:eq(
${
pos
.
tbody
}
)`
,
table
).
append
(
this
);
}
if
(
$
(
this
).
data
(
'
sort-hidden
'
))
{
if
(
$
(
this
).
data
(
'
sort-hidden
'
))
{
setTimeout
(()
=>
$
(
this
).
hide
(),
100
);
setTimeout
(()
=>
$
(
this
).
hide
(),
100
);
}
}
});
});
});
});
}
}
$
(
table
).
tablesorter
({
// Get additional widgets
headers
:
headers
,
const
widgets
=
$
(
table
).
data
().
sortWidgets
??
[];
sortLocaleCompare
:
true
,
sortRestart
:
true
,
widthFixed
:
false
});
}
const
Table
=
{
// Actually activate table sorter
enhanceSortableTable
:
function
(
table
)
{
$
(
table
).
tablesorter
({
STUDIP
.
loadChunk
(
'
tablesorter
'
).
then
(()
=>
enhanceSortableTable
(
table
));
headers
:
headers
,
sortLocaleCompare
:
true
,
sortRestart
:
true
,
widthFixed
:
false
,
widgets
:
Array
.
isArray
(
widgets
)
?
widgets
:
[]
});
}
}
}
;
}
export
default
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