Skip to content

Commit 60f8c1f

Browse files
committed
#436 fixed a bug in the generated JavaScript code
1 parent 9720cc5 commit 60f8c1f

File tree

5 files changed

+107
-18
lines changed

5 files changed

+107
-18
lines changed

src/main/java/net/bootsfaces/component/dataTable/DataTableCore.java

+17
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ protected enum PropertyKeys {
3636
colSm,
3737
colXs,
3838
customLangUrl,
39+
customOptions,
3940
disabled,
4041
display,
4142
fixedHeader,
@@ -215,6 +216,22 @@ public void setCustomLangUrl(String _customLangUrl) {
215216
getStateHelper().put(PropertyKeys.customLangUrl, _customLangUrl);
216217
}
217218

219+
/**
220+
* 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. <P>
221+
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
222+
*/
223+
public String getCustomOptions() {
224+
return (String) getStateHelper().eval(PropertyKeys.customOptions);
225+
}
226+
227+
/**
228+
* 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. <P>
229+
* Usually this method is called internally by the JSF engine.
230+
*/
231+
public void setCustomOptions(String _customOptions) {
232+
getStateHelper().put(PropertyKeys.customOptions, _customOptions);
233+
}
234+
218235
/**
219236
* Boolean value to specify if the button is disabled. <P>
220237
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.

src/main/java/net/bootsfaces/component/dataTable/DataTableRenderer.java

+47-18
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ private void generateHeader(FacesContext context, DataTable dataTable, ResponseW
315315
List<String> infos = dataTable.getColumnInfo();
316316
String s = infos.get(index);
317317
if (s == null) {
318-
infos.set(index, "'orderDataType': '" + orderBy + "', type: 'string'");
318+
infos.set(index, "'orderDataType': '" + orderBy+"'");
319319
} else {
320-
infos.set(index, s + ",'orderDataType': '" + orderBy + "', type: 'string'");
320+
infos.set(index, s + ",'orderDataType': '" + orderBy+"'");
321321
}
322322

323323
}
@@ -355,6 +355,24 @@ private void generateHeader(FacesContext context, DataTable dataTable, ResponseW
355355
infos.set(index, s + ",'orderable': false");
356356
}
357357
}
358+
if (column.getAttributes().get("customOptions") != null) {
359+
String customOptions = column.getAttributes().get("customOptions").toString();
360+
if (customOptions !=null && customOptions.length()>0) {
361+
if (dataTable.getColumnInfo() == null) {
362+
List<String> infos = new ArrayList<String>(dataTable.getChildren().size());
363+
for (int k = 0; k < dataTable.getChildren().size(); k++) {
364+
infos.add(null);
365+
}
366+
dataTable.setColumnInfo(infos);
367+
}
368+
List<String> infos = dataTable.getColumnInfo();
369+
String s = infos.get(index);
370+
if (s == null) {
371+
infos.set(index, customOptions);
372+
} else
373+
infos.set(index, s + "," +customOptions);
374+
}
375+
}
358376
rw.endElement("th");
359377
index++;
360378
}
@@ -426,23 +444,26 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
426444
// # Start enclosure
427445
rw.writeText("$(document).ready(function() {", null);
428446
// # Enclosure-scoped variable initialization
447+
String options = "";
448+
options = addOptions(" fixedHeader: " + dataTable.isFixedHeader(), options);
449+
options = addOptions( " responsive: " + dataTable.isResponsive(), options);
450+
options = addOptions( " paging: " + dataTable.isPaginated(), options);
451+
options = addOptions( " pageLength: " + pageLength, options);
452+
options = addOptions( " lengthMenu: " + getPageLengthMenu(dataTable), options);
453+
options = addOptions( " searching: " + dataTable.isSearching() , options);
454+
options = addOptions( " order: " + orderString, options);
455+
options = addOptions( " stateSave: " + dataTable.isSaveState(), options);
456+
options = addOptions( " select: true", options);
457+
options = addOptions( generateScrollOptions(dataTable), options);
458+
options = addOptions( (BsfUtils.isStringValued(lang) ? " language: { url: '" + lang + "' } " : null), options);
459+
options = addOptions( generateColumnInfos(dataTable.getColumnInfo()), options);
460+
options = addOptions( dataTable.getCustomOptions(), options);
429461
rw.writeText(widgetVar + " = $('." + clientId + "Table" + "');" +
430462
// # Get instance of wrapper, and replace it with the unwrapped table.
431463
"var wrapper = $('#" + clientIdRaw.replace(":", "\\\\:") + "_wrapper');" + "wrapper.replaceWith("
432464
+ widgetVar + ");"
433465
+ "var table = " + widgetVar + ".DataTable({"
434-
+ " fixedHeader: " + dataTable.isFixedHeader() + ","
435-
+ " responsive: " + dataTable.isResponsive() + ", "
436-
+ " paging: " + dataTable.isPaginated() + ", "
437-
+ " pageLength: " + pageLength + ", "
438-
+ " lengthMenu: " + getPageLengthMenu(dataTable) + ", "
439-
+ " searching: " + dataTable.isSearching() + ", "
440-
+ " order: " + orderString + ", "
441-
+ " stateSave: " + dataTable.isSaveState() + ", "
442-
+ " select: true,"
443-
+ generateScrollOptions(dataTable)
444-
+ (BsfUtils.isStringValued(lang) ? " language: { url: '" + lang + "' } " : "")
445-
+ generateColumnInfos(dataTable.getColumnInfo()) + "});", null);
466+
+ options + "});", null);
446467

447468
if (dataTable.isMultiColumnSearch()) {
448469
// # Footer stuff:
@@ -452,10 +473,9 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
452473
+ "$(this).html('<input class=\"input-sm\" type=\"text\" placeholder=\"Search ' + title + '\" />');"
453474
+ "});\n", null);
454475
// # Add event listeners for each multisearch input
455-
rw.writeText("table.columns().every( function (col) {" + "var that = this;\ndebugger;\n" + "var inputs = $("
476+
rw.writeText("table.columns().every( function (col) {" + "var that = this;\n" + "var inputs = $("
456477
+ widgetVar + ".find('.bf-multisearch input'));\n"
457478
+ "$(inputs[col]).on( 'keyup change', function () {" + " if ( that.search() !== this.value ) {"
458-
+ "console.log(this.value);" + "console.log(that);"
459479
+ " that.search( this.value ).draw('page');" + " }" + "} );" +
460480

461481
"} );", null);
@@ -465,6 +485,15 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
465485
rw.endElement("script");
466486
}
467487

488+
private String addOptions(String newOption, String options) {
489+
if (newOption!=null && newOption.length()>0) {
490+
if (options.length()>0)
491+
options += ",";
492+
options += newOption;
493+
}
494+
return options;
495+
}
496+
468497
private String generateScrollOptions(DataTable dataTable) {
469498
String scrollY = dataTable.getScrollSize();
470499
boolean scrollX = dataTable.isScrollX();
@@ -486,7 +515,7 @@ private String generateScrollOptions(DataTable dataTable) {
486515
result += "scrollX: true,";
487516
}
488517

489-
return result + "scrollCollapse: " + dataTable.isScrollCollapse() + ",";
518+
return result + "scrollCollapse: " + dataTable.isScrollCollapse();
490519
}
491520

492521
private String generateColumnInfos(List<String> columnInfo) {
@@ -509,7 +538,7 @@ private String generateColumnInfos(List<String> columnInfo) {
509538
}
510539
result = result.substring(0, result.length() - 1); // remove the
511540
// trailing comma
512-
result += "],";
541+
result += "]";
513542
return result;
514543
}
515544

src/main/java/net/bootsfaces/component/dataTableColumn/DataTableColumnCore.java

+17
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public abstract class DataTableColumnCore extends UIOutput {
2828
protected enum PropertyKeys {
2929
contentStyle,
3030
contentStyleClass,
31+
customOptions,
3132
dataType,
3233
footerStyle,
3334
footerStyleClass,
@@ -85,6 +86,22 @@ public void setContentStyleClass(String _contentStyleClass) {
8586
getStateHelper().put(PropertyKeys.contentStyleClass, _contentStyleClass);
8687
}
8788

89+
/**
90+
* 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. <P>
91+
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
92+
*/
93+
public String getCustomOptions() {
94+
return (String) getStateHelper().eval(PropertyKeys.customOptions);
95+
}
96+
97+
/**
98+
* 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. <P>
99+
* Usually this method is called internally by the JSF engine.
100+
*/
101+
public void setCustomOptions(String _customOptions) {
102+
getStateHelper().put(PropertyKeys.customOptions, _customOptions);
103+
}
104+
88105
/**
89106
* Specifies order-by more precisely. Is also used by the filtering methods. Legal values are 'string', 'date', 'numeric'. <P>
90107
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.

src/main/meta/META-INF/bootsfaces-b.taglib.xml

+24
Original file line numberDiff line numberDiff line change
@@ -4878,6 +4878,18 @@
48784878
<required>false</required>
48794879
<type>String</type>
48804880
</attribute>
4881+
<attribute>
4882+
<description><![CDATA[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.]]></description>
4883+
<name>custom-options</name>
4884+
<required>false</required>
4885+
<type>String</type>
4886+
</attribute>
4887+
<attribute>
4888+
<description><![CDATA[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.]]></description>
4889+
<name>customOptions</name>
4890+
<required>false</required>
4891+
<type>String</type>
4892+
</attribute>
48814893
<attribute>
48824894
<description><![CDATA[Boolean value to specify if the button is disabled.]]></description>
48834895
<name>disabled</name>
@@ -5390,6 +5402,18 @@
53905402
<required>false</required>
53915403
<type>java.lang.String</type>
53925404
</attribute>
5405+
<attribute>
5406+
<description><![CDATA[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.]]></description>
5407+
<name>custom-options</name>
5408+
<required>false</required>
5409+
<type>String</type>
5410+
</attribute>
5411+
<attribute>
5412+
<description><![CDATA[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.]]></description>
5413+
<name>customOptions</name>
5414+
<required>false</required>
5415+
<type>String</type>
5416+
</attribute>
53935417
<attribute>
53945418
<description><![CDATA[Specifies order-by more precisely. Is also used by the filtering methods. Legal values are 'string', 'date', 'numeric'.]]></description>
53955419
<name>data-type</name>

xtext/BootsFaces.jsfdsl

+2
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ widget dataTable
465465
ajax Boolean "Activates AJAX. The default value is false (no AJAX)."
466466
border Boolean default "true" "If set, this will surround the table by a border. Defaults to true."
467467
custom-lang-url String "Defines a custom lang file url for languages BootsFaces doesn't support out-of-the-box."
468+
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."
468469
disabled Boolean "Boolean value to specify if the button is disabled."
469470
fixed-header Boolean "Activates the fixed header plugin of the dataTable."
470471
id inherited "Unique identifier of the component in a namingContainer."
@@ -508,6 +509,7 @@ widget dataTable
508509
}
509510

510511
widget dataTableColumn {
512+
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."
511513
label "Label in the header of the colum."
512514
order "Is the table to be sorted by this column? Legal values are 'asc' and 'desc'."
513515
order-by "Allows you to sort input field. Legal values are dom-text, dom-text-numeric, dom-select and dom-checkbox."

0 commit comments

Comments
 (0)