Skip to content

Commit 42cb67f

Browse files
committed
Added selection for data tables
1 parent e5d9adf commit 42cb67f

File tree

7 files changed

+99
-0
lines changed

7 files changed

+99
-0
lines changed

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"datatables.net-buttons-bs5": "^2.2.2",
1111
"datatables.net-colreorder-bs5": "^1.5.5",
1212
"datatables.net-responsive-bs5": "^2.2.9",
13+
"datatables.net-select-bs5": "^1.3.4",
1314
"datatables.mark.js": "^2.1.0",
1415
"mark.js": "^8.11.1",
1516
"remark-cli": "^10.0.1",

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@
156156
<directory>${project.basedir}/node_modules/datatables.net-responsive-bs5/js</directory>
157157
<filtering>false</filtering>
158158
</resource>
159+
<resource>
160+
<directory>${project.basedir}/node_modules/datatables.net-select/js</directory>
161+
<filtering>false</filtering>
162+
</resource>
163+
<resource>
164+
<directory>${project.basedir}/node_modules/datatables.net-select-bs5/js</directory>
165+
<filtering>false</filtering>
166+
</resource>
159167
<resource>
160168
<directory>${project.basedir}/node_modules/datatables.mark.js/dist</directory>
161169
<filtering>false</filtering>
@@ -198,6 +206,10 @@
198206
<directory>${project.basedir}/node_modules/datatables.net-responsive-bs5/css</directory>
199207
<filtering>false</filtering>
200208
</resource>
209+
<resource>
210+
<directory>${project.basedir}/node_modules/datatables.net-select-bs5/css</directory>
211+
<filtering>false</filtering>
212+
</resource>
201213
</resources>
202214
</configuration>
203215
</execution>

src/main/java/io/jenkins/plugins/datatables/TableConfiguration.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class TableConfiguration {
1818
private boolean useResponsive = false;
1919
private boolean useColReorder = false;
2020
private boolean useButtons = false;
21+
private boolean useSelect = false;
2122

2223
/**
2324
* Make the table responsive, i.e. the columns wrap over to a child column.
@@ -101,6 +102,31 @@ public boolean isUseButtons() {
101102
return useButtons;
102103
}
103104

105+
/**
106+
* Enable selection.
107+
*
108+
* @param selectionStyle
109+
* The <a href="https://datatables.net/reference/option/select.style">select.style</a> option
110+
*
111+
* @return this {@link TableConfiguration} for chaining methods
112+
*
113+
* @see <a href="https://datatables.net/reference/option/select">https://datatables.net/reference/option/select</a>
114+
*/
115+
public TableConfiguration select(final String selectionStyle) {
116+
configuration.put("select", selectionStyle);
117+
useSelect = true;
118+
return this;
119+
}
120+
121+
/**
122+
* Returns whether select is configured to be used.
123+
*
124+
* @return true, if select should be used, false otherwise
125+
*/
126+
public boolean isUseSelect() {
127+
return useSelect;
128+
}
129+
104130
/**
105131
* Enable saving of the table state.
106132
*
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?jelly escape-by-default='true'?>
2+
<!--
3+
Use it like <st:adjunct includes="io.jenkins.plugins.data-tables-select"/>
4+
-->
5+
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
6+
7+
<j:new var="h" className="hudson.Functions"/>
8+
${h.initPageVariables(context)}
9+
10+
<st:adjunct includes="io.jenkins.plugins.jquery3"/>
11+
<st:adjunct includes="io.jenkins.plugins.bootstrap5"/>
12+
<st:adjunct includes="io.jenkins.plugins.data-tables"/>
13+
14+
<link type="text/css" rel="stylesheet" href="${resURL}/plugin/data-tables-api/css/select.bootstrap5.min.css"/>
15+
16+
<script type="text/javascript" src="${resURL}/plugin/data-tables-api/js/dataTables.select.min.js"/>
17+
<script type="text/javascript" src="${resURL}/plugin/data-tables-api/js/select.bootstrap5.min.js"/>
18+
19+
</j:jelly>

src/main/webapp/css/jenkins-style.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,14 @@ div.details-control {
8181
.form-select-sm, .form-control-sm {
8282
margin: 0.2em;
8383
}
84+
85+
/* ------------------------------------------------------------------------------------------------------------------- */
86+
/* DataTables select */
87+
/* ------------------------------------------------------------------------------------------------------------------- */
88+
table.dataTable tbody > tr.selected, table.dataTable tbody > tr > .selected {
89+
background-color: #b4b4b4 !important;
90+
}
91+
92+
table.dataTable tbody tr.selected, table.dataTable tbody th.selected, table.dataTable tbody td.selected {
93+
color: black !important;
94+
}

src/test/java/io/jenkins/plugins/datatables/TableConfigurationTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ void shouldCreateResponsiveConfiguration() {
3232
assertThat(configuration).isUseResponsive();
3333
}
3434

35+
@Test
36+
void shouldCreateSelectConfiguration() {
37+
TableConfiguration configuration = new TableConfiguration().select("single");
38+
39+
assertThat(configuration).hasConfiguration("{\"select\":\"single\"}");
40+
assertThat(configuration).isNotUseButtons();
41+
assertThat(configuration).isNotUseColReorder();
42+
assertThat(configuration).isNotUseResponsive();
43+
assertThat(configuration).isUseSelect();
44+
}
45+
3546
@Test
3647
void shouldCreateColReorderConfiguration() {
3748
TableConfiguration configuration = new TableConfiguration()

0 commit comments

Comments
 (0)