Skip to content

Commit

Permalink
#1038 started to implement the checkbox column in a datatable
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanrauh committed Dec 15, 2018
1 parent 7c65962 commit 45384e1
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 12 deletions.
23 changes: 23 additions & 0 deletions gradleResources/staticResources/css/ext/dataTables.checkboxes.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
table.dataTable.dt-checkboxes-select tbody tr,
table.dataTable thead th.dt-checkboxes-select-all,
table.dataTable tbody td.dt-checkboxes-cell {
cursor: pointer;
}

table.dataTable thead th.dt-checkboxes-select-all,
table.dataTable tbody td.dt-checkboxes-cell {
text-align: center;
}

div.dataTables_wrapper span.select-info,
div.dataTables_wrapper span.select-item {
margin-left: 0.5em;
}

@media screen and (max-width: 640px) {
div.dataTables_wrapper span.select-info,
div.dataTables_wrapper span.select-item {
margin-left: 0;
display: block;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
table.dataTable.dt-checkboxes-select tbody tr,
table.dataTable thead th.dt-checkboxes-select-all,
table.dataTable tbody td.dt-checkboxes-cell {
cursor: pointer;
}

table.dataTable thead th.dt-checkboxes-select-all,
table.dataTable tbody td.dt-checkboxes-cell {
text-align: center;
}

div.dataTables_wrapper span.select-info,
div.dataTables_wrapper span.select-item {
margin-left: 0.5em;
}

@media screen and (max-width: 640px) {
div.dataTables_wrapper span.select-info,
div.dataTables_wrapper span.select-item {
margin-left: 0;
display: block;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,14 @@ public void setRowGroup(String _rowGroup) {
AddResourcesListener.addResourceIfNecessary("https://cdn.datatables.net/rowgroup/1.0.2/js/dataTables.rowGroup.min.js");
super.setRowGroup(_rowGroup);
}

@Override
public void setCheckboxColumn(String _checkboxColumn) {
super.setCheckboxColumn(_checkboxColumn);
if (_checkboxColumn != null && !_checkboxColumn.isEmpty() && !_checkboxColumn.equals("false")) {
AddResourcesListener.addBasicJSResource(C.BSF_LIBRARY, "js/dataTables.checkboxes.min.js");
AddResourcesListener.addExtCSSResource("dataTables.checkboxes.css");
}
}

}
36 changes: 26 additions & 10 deletions src/main/java/net/bootsfaces/component/dataTable/DataTableCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
public abstract class DataTableCore extends UIData implements net.bootsfaces.render.IHasTooltip {

protected enum PropertyKeys {
ajax, autoUpdate, border, caption, colLg, colMd, colSm, colXs, columnVisibility, contentDisabled, copy, csv,
customLangUrl, customOptions, delay, deselectOnBackdropClick, disabled, display, excel, fixedHeader, hidden,
immediate, info, lang, largeScreen, markSearchResults, mediumScreen, multiColumnSearch,
multiColumnSearchPosition, offset, offsetLg, offsetMd, offsetSm, offsetXs, onclick, oncomplete, ondblclick,
ondeselect, onerror, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onorder, onpage, onsearch,
onselect, onsuccess, pageLength, pageLengthMenu, paginated, pdf, print, process, responsive, rowGroup,
rowHighlight, rowStyleClass, saveState, scrollCollapse, scrollHorizontally, scrollSize, scrollX, searching,
select, selectedColumn, selectedItems, selectedRow, selectionInfo, selectionMode, smallScreen, span, striped,
style, styleClass, tinyScreen, tooltip, tooltipContainer, tooltipDelay, tooltipDelayHide, tooltipDelayShow,
tooltipPosition, update, visible, widgetVar;
ajax, autoUpdate, border, caption, checkboxColumn, colLg, colMd, colSm, colXs, columnVisibility,
contentDisabled, copy, csv, customLangUrl, customOptions, delay, deselectOnBackdropClick, disabled, display,
excel, fixedHeader, hidden, immediate, info, lang, largeScreen, markSearchResults, mediumScreen,
multiColumnSearch, multiColumnSearchPosition, offset, offsetLg, offsetMd, offsetSm, offsetXs, onclick,
oncomplete, ondblclick, ondeselect, onerror, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup,
onorder, onpage, onsearch, onselect, onsuccess, pageLength, pageLengthMenu, paginated, pdf, print, process,
responsive, rowGroup, rowHighlight, rowStyleClass, saveState, scrollCollapse, scrollHorizontally, scrollSize,
scrollX, searching, select, selectedColumn, selectedItems, selectedRow, selectionInfo, selectionMode,
smallScreen, span, striped, style, styleClass, tinyScreen, tooltip, tooltipContainer, tooltipDelay,
tooltipDelayHide, tooltipDelayShow, tooltipPosition, update, visible, widgetVar;
String toString;

PropertyKeys(String toString) {
Expand Down Expand Up @@ -112,6 +112,22 @@ public void setCaption(String _caption) {
getStateHelper().put(PropertyKeys.caption, _caption);
}

/**
* Setting this to true add a checkbox column on the left-hand side of the table. By passing a number instead of 'true', you can move the checkbox to another column. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public String getCheckboxColumn() {
return (String) getStateHelper().eval(PropertyKeys.checkboxColumn);
}

/**
* Setting this to true add a checkbox column on the left-hand side of the table. By passing a number instead of 'true', you can move the checkbox to another column. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setCheckboxColumn(String _checkboxColumn) {
getStateHelper().put(PropertyKeys.checkboxColumn, _checkboxColumn);
}

/**
* Integer value to specify how many columns to span on large screens (≥1200 pixels wide). The number may optionally be followed by "column" or "columns". Alternative legal values: half, one-third, two-thirds, one-fourth, three-fourths. <P>
* @return Returns the value of the attribute, or "-1", if it hasn't been set by the JSF file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
options = addOptions((BsfUtils.isStringValued(lang) ? " language: { url: '" + lang + "' } " : null), options);
options = addOptions(generateColumnInfos(dataTable.getColumnInfo()), options);
options = addOptions(dataTable.getCustomOptions(), options);
options = addOptions(generateColumnDefs(dataTable), options);
options = addOptions(getButtons(dataTable), options);
String selectCommand = "";
Object selectedRow = dataTable.getSelectedRow();
Expand Down Expand Up @@ -696,6 +697,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
rw.endElement("script");
}


private String getButtons(DataTable dataTable) {
StringBuilder b = new StringBuilder();
if (dataTable.isColumnVisibility()) {
Expand Down Expand Up @@ -755,6 +757,19 @@ private String generateScrollOptions(DataTable dataTable) {
return result + "scrollCollapse: " + dataTable.isScrollCollapse();
}

private String generateColumnDefs(DataTable dataTable) {
String c = dataTable.getCheckboxColumn();
if (null == c || c.isEmpty() || c.equals("false")) {
return "";
}
String result = "";
if (c.equals("true")) {
c = "0";
}
result = "'columnDefs': [{'targets':" + c + ", 'checkboxes': {'selectRow': true}}],'select':{'style':'multi'}";
return result;
}

private String generateColumnInfos(List<String> columnInfo) {
if (columnInfo == null) {
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,11 @@ private void enforceCorrectLoadOrder(UIViewRoot root, FacesContext context) {
if (resource instanceof InternalJavaScriptResource) {
datatable.add(resource);
} else if (name != null && (name.endsWith(".js"))) {
resources.add(resource);
if (name.contains("dataTables")) {
datatable.add(resource);
} else {
resources.add(resource);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/meta/META-INF/bootsfaces-b.taglib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6365,6 +6365,12 @@
<required>false</required>
<type>String</type>
</attribute>
<attribute>
<description><![CDATA[Setting this to true add a checkbox column on the left-hand side of the table. By passing a number instead of 'true', you can move the checkbox to another column.]]></description>
<name>checkboxColumn</name>
<required>false</required>
<type>String</type>
</attribute>
<attribute>
<description><![CDATA[Integer value to specify how many columns to span on large screens (≥1200 pixels wide). The number may optionally be followed by "column" or "columns". Alternative legal values: half, one-third, two-thirds, one-fourth, three-fourths.]]></description>
<name>col-lg</name>
Expand Down
3 changes: 2 additions & 1 deletion xtext/BootsFaces.jsfdsl
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,8 @@ widget dataTable
pdf Boolean default "false" "Adds a 'export PDF file' button."
print Boolean default "false" "Adds a 'print' button."
caption String "Optional attribute describing what the datatable is for. Usually, this attribute is used by screen readers to help the user to quickly grasp the intent of the table."
custom-lang-url String "Defines a custom lang file url for languages BootsFaces doesn't support out-of-the-box."
checkboxColumn String "Setting this to true add a checkbox column on the left-hand side of the table. By passing a number instead of 'true', you can move the checkbox to another column."
custom-lang-url String "Defines a custom lang file url for languages BootsFaces doesn't support out-of-the-box."
custom-options String "Allows you to pass an arbitrary option to the datatable widget. Separate the options by a comma if you pass more than one. Note that this may cause incompatibilities when the next version of BootsFaces is released. Use at own risk."
disabled Boolean "Boolean value to specify if the button is disabled."
fixed-header Boolean "Activates the fixed header plugin of the dataTable."
Expand Down

0 comments on commit 45384e1

Please sign in to comment.