Skip to content

Commit

Permalink
Add the option to add a toolbar in the table top-left corner.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Mar 6, 2024
1 parent 9bea2bc commit 3378300
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/resources/data-tables/table.jelly
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<st:documentation>
Renders a JQuery DataTables instance. The table data is loaded asynchronously from the associated view using
an Ajax call. In order to correctly connect the jelly view with the Jenkins ModelObject via a Stapler proxy
Expand Down Expand Up @@ -37,7 +37,8 @@
<div class="table-buttons-container clearfix"/>
</j:if>
<table class="table table-hover data-table dt-responsive nowrap ${class}"
data-columns-definition="${model.columnsDefinition}" id="${model.id}"
data-columns-definition="${model.columnsDefinition}"
id="${model.id}"
data-table-configuration="${model.tableConfigurationDefinition}"
style="width: 100%;">
<thead>
Expand All @@ -48,6 +49,9 @@
</tr>
</thead>
</table>
<div id="toolbar-${model.id}" class="table-toolbar">
<d:invokeBody />
</div>
</div>

<st:bind var="tableDataProxy" value="${it}" />
Expand Down
17 changes: 17 additions & 0 deletions src/main/webapp/js/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,24 @@ jQuery3(document).ready(function () {
* Creates the data table instance for the specified table element.
*/
function createDataTable(table) {
const toolbar = $(table).next();
let toolbarContent;
let bottom;
if (toolbar.length && toolbar.children().length > 0) {
toolbarContent = toolbar;
bottom = ['pageLength', 'info'];
}
else {
toolbarContent = 'pageLength';
bottom = 'info';
}
const defaultConfiguration = {
layout: {
topStart: toolbarContent,
topEnd: 'search',
bottomStart: bottom,
bottomEnd: 'paging'
},
stateSave: true,
language: {
emptyTable: 'Loading - please wait ...'
Expand Down

0 comments on commit 3378300

Please sign in to comment.