Skip to content

Commit

Permalink
Add support for horizontal scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
eruiz committed Jul 5, 2013
1 parent 2322c9d commit bafa48e
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public enum Configuration {
FEATURE_DOM("feature.dom", "featureDom", String.class, StringProcessor.class),
FEATURE_SCROLLY("feature.scrollY", "featureScrolly", String.class, StringProcessor.class),
FEATURE_SCROLLCOLLAPSE("feature.scrollCollapse", "featureScrollCollapse", Boolean.class, BooleanProcessor.class),
FEATURE_SCROLLX("feature.scrollX", "featureScrollx", String.class, StringProcessor.class),
FEATURE_SCROLLINNER("feature.scrollInner", "featureScrollInner", String.class, StringProcessor.class),

EXTRA_THEME("extra.theme", "extraTheme", AbstractTheme.class, ExtraThemeProcessor.class),
EXTRA_THEMEOPTION("extra.themeOption", "extraThemeOption", ThemeOption.class, ExtraThemeOptionProcessor.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public class TableConfiguration {
private String featureDom;
private String featureScrolly;
private Boolean featureScrollCollapse;
private String featureScrollx;
private String featureScrollInner;

// CSS parameters
private StringBuilder cssStyle;
Expand Down Expand Up @@ -235,6 +237,8 @@ private TableConfiguration (TableConfiguration objectToClone, HttpServletRequest
featureDom = objectToClone.featureDom;
featureScrolly = objectToClone.featureScrolly;
featureScrollCollapse = objectToClone.featureScrollCollapse;
featureScrollx = objectToClone.featureScrollx;
featureScrollInner = objectToClone.featureScrollInner;

// CSS parameters
cssStyle = objectToClone.cssStyle;
Expand Down Expand Up @@ -735,6 +739,24 @@ public TableConfiguration setFeatureScrollCollapse(Boolean scrollCollapse) {
return this;
}

public String getFeatureScrollX() {
return featureScrollx;
}

public TableConfiguration setFeatureScrollx(String scrollX) {
this.featureScrollx = scrollX;
return this;
}

public String getFeatureScrollInner() {
return featureScrollInner;
}

public TableConfiguration setFeatureScrollInner(String scrollInner) {
this.featureScrollx = scrollInner;
return this;
}

public String getPluginFixedPosition() {
return pluginFixedPosition;
}
Expand Down Expand Up @@ -1129,7 +1151,8 @@ public String toString() {
+ ", featureStateSave=" + featureStateSave + ", featureJqueryUi=" + featureJqueryUi
+ ", featureLengthMenu=" + featureLengthMenu + ", featureDisplayLength=" + featureDisplayLength
+ ", featureDom=" + featureDom + ", featureScrolly=" + featureScrolly + ", featureScrollCollapse="
+ featureScrollCollapse + ", cssStyle=" + cssStyle + ", cssClass=" + cssClass + ", cssStripeClasses="
+ featureScrollCollapse + ", featureScrollx=" + featureScrollx + ", featureScrollInner=" + featureScrollInner
+ ", cssStyle=" + cssStyle + ", cssClass=" + cssClass + ", cssStripeClasses="
+ cssStripeClasses + ", ajaxProcessing=" + ajaxProcessing + ", ajaxDeferRender=" + ajaxDeferRender
+ ", ajaxServerSide=" + ajaxServerSide + ", ajaxSource=" + ajaxSource + ", ajaxPipelining="
+ ajaxPipelining + ", ajaxPipeSize=" + ajaxPipeSize + ", ajaxServerData=" + ajaxServerData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public class DTConstants {

// Extra features
public static final String DT_SCROLLY = "sScrollY";
public static final String DT_SCROLLX = "sScrollX";
public static final String DT_SCROLLINNER = "sScrollXInner";
public static final String DT_SCROLLCOLLAPSE = "bScrollCollapse";
public static final String DT_OFFSETTOP = "offsetTop";
public static final String DT_FILTER_TYPE = "type";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ public Map<String, Object> generateConfig(HtmlTable table) {
if(tableConfiguration.getFeatureScrollCollapse() != null){
mainConf.put(DTConstants.DT_SCROLLCOLLAPSE, tableConfiguration.getFeatureScrollCollapse());
}
if(StringUtils.isNotBlank(tableConfiguration.getFeatureScrollX())){
mainConf.put(DTConstants.DT_SCROLLX, tableConfiguration.getFeatureScrollX());
}
if(StringUtils.isNotBlank(tableConfiguration.getFeatureScrollInner())){
mainConf.put(DTConstants.DT_SCROLLINNER, tableConfiguration.getFeatureScrollInner());
}

// AJAX
if (tableConfiguration.getAjaxProcessing() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,26 @@ public void should_set_scroll_collapse() {
assertThat(mainConf.get(DTConstants.DT_SCROLLCOLLAPSE)).isEqualTo(true);
}

@Test
public void should_set_scroll_x() {
table.getTableConfiguration().setFeatureScrollx("100%");

Map<String, Object> mainConf = generator.generateConfig(table);

assertThat(mainConf).hasSize(2);
assertThat(mainConf.get(DTConstants.DT_SCROLLX)).isEqualTo("100%");
}

@Test
public void should_set_scroll_inner() {
table.getTableConfiguration().setFeatureScrollInner("110%");

Map<String, Object> mainConf = generator.generateConfig(table);

assertThat(mainConf).hasSize(2);
assertThat(mainConf.get(DTConstants.DT_SCROLLINNER)).isEqualTo("110%");
}

@Test
public void should_set_processing() {
table.getTableConfiguration().setAjaxProcessing(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ public void setScrollCollapse(String scrollCollapse) {
localConf.put(Configuration.FEATURE_SCROLLCOLLAPSE, scrollCollapse);
}

public void setScrollX(String scrollX) {
localConf.put(Configuration.FEATURE_SCROLLX, scrollX);
}

public void setScrollInner(String scrollInner) {
localConf.put(Configuration.FEATURE_SCROLLINNER, scrollInner);
}

public void setFixedPosition(String fixedPosition) {
localConf.put(Configuration.PLUGIN_FIXEDPOSITION, fixedPosition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@
Y height. (default : false)</description>
<name>scrollCollapse</name>
</attribute>
<attribute>
<description>Table's width to display in scrolling mode.
(default : disabled)</description>
<name>scrollX</name>
</attribute>
<attribute>
<description>Use more width than it might otherwise do when
x-scrolling is enabled.
(default : disabled)</description>
<name>scrollInner</name>
</attribute>

<!-- ColReorder -->
<attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
import com.github.dandelion.datatables.thymeleaf.processor.basic.TablePaginationTypeAttrProcessor;
import com.github.dandelion.datatables.thymeleaf.processor.basic.TableScrollCollapseAttrProcessor;
import com.github.dandelion.datatables.thymeleaf.processor.basic.TableScrollYAttrProcessor;
import com.github.dandelion.datatables.thymeleaf.processor.basic.TableScrollXAttrProcessor;
import com.github.dandelion.datatables.thymeleaf.processor.basic.TableScrollInnerAttrProcessor;
import com.github.dandelion.datatables.thymeleaf.processor.basic.TableSortAttrProcessor;
import com.github.dandelion.datatables.thymeleaf.processor.basic.TableStripeClassesAttrProcessor;
import com.github.dandelion.datatables.thymeleaf.processor.basic.ThFilterTypeAttrProcessor;
Expand Down Expand Up @@ -130,6 +132,8 @@ public enum DatatablesAttrProcessors {
BASIC_LENGTH_CHANGE(TableLengthChangeAttrProcessor.class, "lengthchange", "table"),
BASIC_SCROLL_Y(TableScrollYAttrProcessor.class, "scrolly", "table"),
BASIC_SCROLL_COLLAPSE(TableScrollCollapseAttrProcessor.class, "scrollcollapse", "table"),
BASIC_SCROLL_X(TableScrollXAttrProcessor.class, "scrollx", "table"),
BASIC_SCROLL_INNER(TableScrollInnerAttrProcessor.class, "scrollinner", "table"),
BASIC_DOM(TableDomAttrProcessor.class, "dom", "table"),
BASIC_SELECTOR(ThSelectorAttrProcessor.class, "selector", "th"),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* [The "BSD licence"]
* Copyright (c) 2012 Dandelion
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Dandelion nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.github.dandelion.datatables.thymeleaf.processor.basic;

import java.util.Map;

import org.thymeleaf.Arguments;
import org.thymeleaf.dom.Element;
import org.thymeleaf.processor.IAttributeNameProcessorMatcher;
import org.thymeleaf.processor.ProcessorResult;

import com.github.dandelion.datatables.core.configuration.Configuration;
import com.github.dandelion.datatables.core.html.HtmlTable;
import com.github.dandelion.datatables.thymeleaf.dialect.AbstractDatatablesAttrProcessor;
import com.github.dandelion.datatables.thymeleaf.util.Utils;

/**
* Attribute processor for the <code>scroll x</code> attribute.
*
* @author DISID TECHNOLOGIES S.L.
*/
public class TableScrollInnerAttrProcessor extends AbstractDatatablesAttrProcessor {

public TableScrollInnerAttrProcessor(IAttributeNameProcessorMatcher matcher) {
super(matcher);
}

@Override
public int getPrecedence() {
return 8000;
}

@Override
protected ProcessorResult doProcessAttribute(Arguments arguments, Element element,
String attributeName, HtmlTable table, Map<Configuration, Object> localConf) {

// Get attribute value
String attrValue = Utils.parseElementAttribute(arguments, element.getAttributeValue(attributeName), "", String.class);

localConf.put(Configuration.FEATURE_SCROLLINNER, attrValue);

return ProcessorResult.ok();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* [The "BSD licence"]
* Copyright (c) 2012 Dandelion
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Dandelion nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.github.dandelion.datatables.thymeleaf.processor.basic;

import java.util.Map;

import org.thymeleaf.Arguments;
import org.thymeleaf.dom.Element;
import org.thymeleaf.processor.IAttributeNameProcessorMatcher;
import org.thymeleaf.processor.ProcessorResult;

import com.github.dandelion.datatables.core.configuration.Configuration;
import com.github.dandelion.datatables.core.html.HtmlTable;
import com.github.dandelion.datatables.thymeleaf.dialect.AbstractDatatablesAttrProcessor;
import com.github.dandelion.datatables.thymeleaf.util.Utils;

/**
* Attribute processor for the <code>scroll x</code> attribute.
*
* @author DISID TECHNOLOGIES S.L.
*/
public class TableScrollXAttrProcessor extends AbstractDatatablesAttrProcessor {

public TableScrollXAttrProcessor(IAttributeNameProcessorMatcher matcher) {
super(matcher);
}

@Override
public int getPrecedence() {
return 8000;
}

@Override
protected ProcessorResult doProcessAttribute(Arguments arguments, Element element,
String attributeName, HtmlTable table, Map<Configuration, Object> localConf) {

// Get attribute value
String attrValue = Utils.parseElementAttribute(arguments, element.getAttributeValue(attributeName), "", String.class);

localConf.put(Configuration.FEATURE_SCROLLX, attrValue);

return ProcessorResult.ok();
}
}

0 comments on commit bafa48e

Please sign in to comment.