Skip to content

Commit

Permalink
#924 added an option to activate mark.js in a datatable
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanrauh committed Apr 15, 2018
1 parent e561b76 commit c86bfa6
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 84 deletions.
14 changes: 14 additions & 0 deletions src/main/java/net/bootsfaces/component/dataTable/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,18 @@ public void setSelectedItems(String _selectedItems) {
}

}

/**
* If true, search results are marked yellow as you type. Based on mark.js (see https://datatables.net/blog/2017-01-19). <P>
* Usually this method is called internally by the JSF engine.
*/
public void setMarkSearchResults(boolean _markSearchResults) {
if (_markSearchResults) {
AddResourcesListener.addResourceIfNecessary("https://cdn.datatables.net/plug-ins/1.10.13/features/mark.js/datatables.mark.min.css");
AddResourcesListener.addResourceIfNecessary("https://cdn.jsdelivr.net/g/mark.js(jquery.mark.min.js)");
AddResourcesListener.addResourceIfNecessary("https://cdn.datatables.net/plug-ins/1.10.13/features/mark.js/datatables.mark.js");
}
super.setMarkSearchResults(_markSearchResults);
}

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

protected enum PropertyKeys {
ajax,
border,
colLg,
colMd,
colSm,
colXs,
columnVisibility,
contentDisabled,
copy,
csv,
customLangUrl,
customOptions,
deselectOnBackdropClick,
disabled,
display,
excel,
fixedHeader,
hidden,
immediate,
info,
lang,
largeScreen,
mediumScreen,
multiColumnSearch,
multiColumnSearchPosition,
offset,
offsetLg,
offsetMd,
offsetSm,
offsetXs,
onclick,
oncomplete,
ondblclick,
ondeselect,
onmousedown,
onmousemove,
onmouseout,
onmouseover,
onmouseup,
onorder,
onpage,
onsearch,
onselect,
pageLength,
pageLengthMenu,
paginated,
pdf,
print,
process,
responsive,
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, border, colLg, colMd, colSm, colXs, columnVisibility, contentDisabled, copy, csv, customLangUrl, customOptions, deselectOnBackdropClick, disabled, display, excel, fixedHeader, hidden, immediate, info, lang, largeScreen, markSearchResults, mediumScreen, multiColumnSearch, multiColumnSearchPosition, offset, offsetLg, offsetMd, offsetSm, offsetXs, onclick, oncomplete, ondblclick, ondeselect, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onorder, onpage, onsearch, onselect, pageLength, pageLengthMenu, paginated, pdf, print, process, responsive, 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 @@ -469,6 +391,22 @@ public void setLargeScreen(String _largeScreen) {
getStateHelper().put(PropertyKeys.largeScreen, _largeScreen);
}

/**
* If true, search results are marked yellow as you type. Based on mark.js (see https://datatables.net/blog/2017-01-19). <P>
* @return Returns the value of the attribute, or , false, if it hasn't been set by the JSF file.
*/
public boolean isMarkSearchResults() {
return (boolean) (Boolean) getStateHelper().eval(PropertyKeys.markSearchResults, false);
}

/**
* If true, search results are marked yellow as you type. Based on mark.js (see https://datatables.net/blog/2017-01-19). <P>
* Usually this method is called internally by the JSF engine.
*/
public void setMarkSearchResults(boolean _markSearchResults) {
getStateHelper().put(PropertyKeys.markSearchResults, _markSearchResults);
}

/**
* Alternative spelling to col-md. Integer value to specify how many columns to span on medium screens (≥992 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 @@ -543,6 +543,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
options = addOptions("searching: " + dataTable.isSearching(), options);
options = addOptions("order: " + orderString, options);
options = addOptions("stateSave: " + dataTable.isSaveState(), options);
options = addOptions("mark: true", options);

if (dataTable.isSelect()) {
String json = "";
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/net/bootsfaces/listeners/AddResourcesListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ private void addResourceIfNecessary(UIViewRoot root, FacesContext context, UIOut
return;
}
root.addComponentResource(context, output, "head");
// System.out.println("++" + output.getClientId() + " " + nameToAdd + " " + libToAdd);
}

public static void addResourceIfNecessary(String url) {
Expand Down Expand Up @@ -539,7 +538,13 @@ public int compare(UIComponent o1, UIComponent o2) {
for (UIComponent resource : components) {
String name = (String) resource.getAttributes().get("name");
String library = (String) resource.getAttributes().get("library");
String key = library + "/" + name + "/" + resource.getClass().getName();
String url = (String) resource.getAttributes().get("url");
String key;
if (null != url) {
key = url;
} else {
key = library + "/" + name + "/" + resource.getClass().getName();
}
if (alreadyThere.containsKey(key)) {
resourcesToRemove.add(resource);
continue;
Expand All @@ -549,9 +554,10 @@ public int compare(UIComponent o1, UIComponent o2) {
for (UIComponent c : resourcesToRemove) {
c.setInView(false);
root.removeComponentResource(context, c);
//String name = (String) c.getAttributes().get("name");
//String library = (String) c.getAttributes().get("library");
//System.out.println("-1" + c.getClientId() + " " + name + " " + library + " " + c.getClass().getSimpleName() );
// String name = (String) c.getAttributes().get("name");
// String library = (String) c.getAttributes().get("library");
// String url = (String) c.getAttributes().get("url");
// System.out.println("-1" + c.getClientId() + " " + name + " " + library + " " + url + " " + c.getClass().getSimpleName() );
}
}

Expand Down
48 changes: 48 additions & 0 deletions src/main/meta/META-INF/bootsfaces-b.taglib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4601,6 +4601,12 @@
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Delays the AJAX request.]]></description>
<name>delay</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Direction indication for text that does not inherit directionality. Legal values: ltr (Default. Left-to-right text direction), rtl (Right-to-left text direction) and auto (let the browser figure out the direction of your alphabet, based on the page content).]]></description>
<name>dir</name>
Expand Down Expand Up @@ -5993,6 +5999,18 @@
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[If true, search results are marked yellow as you type. Based on mark.js (see https://datatables.net/blog/2017-01-19).]]></description>
<name>mark-search-results</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[If true, search results are marked yellow as you type. Based on mark.js (see https://datatables.net/blog/2017-01-19).]]></description>
<name>markSearchResults</name>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[Alternative spelling to col-md. Integer value to specify how many columns to span on medium screens (≥992 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>medium-screen</name>
Expand Down Expand Up @@ -18897,6 +18915,12 @@
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Delays the AJAX request.]]></description>
<name>delay</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Direction indication for text that does not inherit directionality. Legal values: ltr (Default. Left-to-right text direction), rtl (Right-to-left text direction) and auto (let the browser figure out the direction of your alphabet, based on the page content).]]></description>
<name>dir</name>
Expand Down Expand Up @@ -19259,6 +19283,12 @@
<required>false</required>
<type>javax.faces.component.UIComponent</type>
</attribute>
<attribute>
<description><![CDATA[Delays the AJAX request.]]></description>
<name>delay</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Boolean value to specify if the button is disabled.]]></description>
<name>disabled</name>
Expand Down Expand Up @@ -20851,6 +20881,12 @@
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Delays the AJAX request.]]></description>
<name>delay</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Direction indication for text that does not inherit directionality. Legal values: ltr (Default. Left-to-right text direction), rtl (Right-to-left text direction) and auto (let the browser figure out the direction of your alphabet, based on the page content).]]></description>
<name>dir</name>
Expand Down Expand Up @@ -21543,6 +21579,12 @@
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Delays the AJAX request.]]></description>
<name>delay</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Direction indication for text that does not inherit directionality. Legal values: ltr (Default. Left-to-right text direction), rtl (Right-to-left text direction) and auto (let the browser figure out the direction of your alphabet, based on the page content).]]></description>
<name>dir</name>
Expand Down Expand Up @@ -25891,6 +25933,12 @@
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<description><![CDATA[Delays the AJAX request.]]></description>
<name>delay</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<description><![CDATA[Boolean value to specify if the button is disabled.]]></description>
<name>disabled</name>
Expand Down
2 changes: 2 additions & 0 deletions xtext/BootsFaces.jsfdsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
attribute_list ajax {
ajax Boolean "Whether the Button submits the form with AJAX."
delay "Delays the AJAX request."
onclick "The onclick attribute."
oncomplete "JavaScript to be executed when ajax completes."
onerror "JavaScript to be executed when ajax results on an error (including both network errors and Java exceptions)."
Expand Down Expand Up @@ -568,6 +569,7 @@ widget dataTable
immediate Boolean "Flag indicating that, if this component is activated by the user, notifications should be delivered to interested listeners and actions immediately (that is, during Apply Request Values phase) rather than waiting until Invoke Application phase. Default is false."
info Boolean default "true" "If set, this will enable the information about record count. Defaults to true."
lang String "Configured lang for the dataTable. If no default language is configured, the language configured in the browser is used."
mark-search-results Boolean "If true, search results are marked yellow as you type. Based on mark.js (see https://datatables.net/blog/2017-01-19)."
multi-column-search Boolean "If true, &lt;b:inputText /&gt; fields will be generated at the bottom of each column which allow you to perform per-column filtering."
multi-column-search-position default "bottom" "Should the multi-column-search attributes be at the bottom or the top of the table? Legal values: 'top','botton', and 'both'. Default to 'bottom'."
onclick "The onclick attribute."
Expand Down

0 comments on commit c86bfa6

Please sign in to comment.