Skip to content

Commit 6cc6935

Browse files
authored
Merge pull request #146 from KasperHeyndrickx/JENKINS-64376
[JENKINS-64376] Add hidden columns
2 parents 6f3892e + 840ba07 commit 6cc6935

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ public enum ColumnCss {
166166
*/
167167
NUMBER("text-right"),
168168
/** Disables sorting of the column. Rendering is the same as with {@code NONE}. */
169-
NO_SORT("nosort");
169+
NO_SORT("nosort"),
170+
/** Hides the column for view. It still exists and responds to searching */
171+
HIDDEN("hidden");
170172

171173
private final String cssClass;
172174

src/main/resources/data-tables/table.jelly

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
</j:if>
3636
<table class="table table-hover table-striped data-table ${class}"
3737
data-columns-definition="${model.columnsDefinition}" id="${model.id}"
38-
data-table-configuration="${model.tableConfigurationDefinition}">
38+
data-table-configuration="${model.tableConfigurationDefinition}"
39+
style="width: 100%;">
3940
<colgroup>
4041
<j:forEach var="c" items="${model.columns}">
4142
<col class="col-width-${c.width}"/>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ div.details-control {
5252
/* ------------------------------------------------------------------------------------------------------------------- */
5353
/* Custom column widths for property tables */
5454
/* ------------------------------------------------------------------------------------------------------------------- */
55-
55+
.col-width-0 {
56+
width: 0%;
57+
}
5658
.col-width-1 {
5759
width: 8.333333%;
5860
}

src/main/webapp/js/table.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ jQuery3(document).ready(function () {
4040
return data;
4141
}
4242
}
43+
},
44+
{
45+
targets: 'hidden', // All columns with the '.hidden' class in the <th>
46+
visible: false,
47+
searchable: true,
48+
orderable: false // There is no point in allowing sort by this column if it's not visible.
4349
}
4450
],
4551
columns: JSON.parse(table.attr('data-columns-definition'))

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,19 @@ void shouldCreateDetailsColumnDiv() {
6565
+ "</svg>"
6666
+ "</div>");
6767
}
68+
69+
@Test
70+
void shouldCreateHiddenColumn() {
71+
TableColumn column = new TableColumn(LABEL, "Hidden", "String")
72+
.setHeaderClass(ColumnCss.HIDDEN)
73+
.setWidth(0);
74+
75+
assertThat(column).hasHeaderLabel(LABEL);
76+
assertThat(column).hasDefinition("{ \"type\": \"String\", "
77+
+ "\"data\": \"Hidden\", "
78+
+ "\"defaultContent\": \"\", "
79+
+ "\"render\": { \"_\": \"display\", \"sort\": \"sort\" }}");
80+
assertThat(column).hasHeaderClass("hidden");
81+
assertThat(column).hasWidth(0);
82+
}
6883
}

0 commit comments

Comments
 (0)