Skip to content

Commit

Permalink
Allow control of scroll buffer size. Allow attribute selection over a…
Browse files Browse the repository at this point in the history
…ssociation.
  • Loading branch information
mgroeneweg committed Oct 25, 2017
1 parent 2da7c72 commit a95948f
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 11 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ All features can be seen in action in the test/demo project.

## Backlog

- Currently only XPath can be used to get the grid data. Datasource microflows will be supported in a future release.
- Currently only XPath can be used to get the grid data.

## Configuration

Expand Down Expand Up @@ -131,6 +131,7 @@ The widget does not display search filter inputs. To provide search filters, def
__Filtering on booleans.__ Filtering on booleans is a little tricky because there is no way to tell the difference between off/false or no selection made. To overcome this, the widget expects an enumeration as attribute on your context entity. The modeler does not allow the value _true_ for an enumeration. For the true value, use enumeration value ___t___. For the false value, anything else, but ___f___ would be a good one. The caption can be any value.

- _Context entity attribute_ - The attribute on the context entity to get the filter value.
- _Reference name_ - Optional. Reference name (module.refname) to search on an attribute in a referenced entity, can be multiple levels deep.
- _Attribute name_ - Attribute name to filter on, this is case sensitive.
- _Operator_ - Operator to use. For booleans and enumerations, only _Equals_ makes sense.

Expand Down Expand Up @@ -242,4 +243,5 @@ Please be sure to turn on the apply entity access setting on your export microfl

### Advanced

- _Placement delay_ - Delay (ms) before placing or moving buttons. Depending on complexity of the page, browsers may need more time to properly render the buttons.
- _Placement delay_ - Delay (ms) before placing or moving buttons. Depending on complexity of the page, browsers may need more time to properly render the buttons.
- _Scroll multiplier_ - Scroll buffer multiplier. This value determines how much data is pre-fetched when infinite scroll is used. Lower values cause less data to be requested from the server but will require more server calls when the user keeps scrolling.
11 changes: 11 additions & 0 deletions src/DataTables/DataTables.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@
<enumerationValue key="gt">Greater than</enumerationValue>
</enumerationValues>
</property>
<property key="refName" type="string" required="false">
<caption>Reference name</caption>
<category>Search</category>
<description>Optional. Reference name (module.refname) to search on an attribute in a referenced entity, can be multiple levels deep.</description>
</property>
</properties>
</property>
<property key="refSearchFilterList" type="object" isList="true" required="false">
Expand Down Expand Up @@ -553,6 +558,12 @@
<description>Delay (ms) before placing or moving buttons. Depending on complexity of the page, browsers may need more time to properly render the buttons.</description>
</property>

<property key="scrollBufferMultiplier" type="integer" defaultValue="9">
<caption>Scroll multiplier</caption>
<category>Advanced</category>
<description>Scroll buffer multiplier. This value determines how much data is pre-fetched when infinite scroll is used. Lower values cause less data to be requested from the server but will require more server calls when the user keeps scrolling.</description>
</property>

</properties>
</widget>

45 changes: 36 additions & 9 deletions src/DataTables/widget/DataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ define([
refSearchFilterList: null,
buttonDefinitionList: null,
buttonPlacementDelay: 0,
scrollBufferMultiplier: 9,
allowExport: false,
exportButtonCaption: "",
exportVisibleColumnsOnly: true,
Expand Down Expand Up @@ -387,6 +388,8 @@ define([
// Override so start position and search data are not saved.
dataTablesOptions.stateSaveParams = function (settings, data) {
data.start = 0;
data.iScroller = 0;
data.iScrollerTopRow = 0;
data.search.search = "";
};

Expand All @@ -403,7 +406,8 @@ define([
if (this.infiniteScroll) {
// for normal paging, show the page length drop down.
dataTablesOptions.scroller = {
loadingIndicator: true
loadingIndicator: true,
displayBuffer: this.scrollBufferMultiplier
};
}

Expand Down Expand Up @@ -892,14 +896,17 @@ define([
}

dojoArray.forEach(this.attrSearchFilterList, function (searchFilter, i) {
var constraintValue = this._getConstraintValue(searchFilter.contextEntityAttr, searchFilter.attrName);
var constraintValue = this._getConstraintValue(searchFilter.contextEntityAttr, searchFilter.attrName, searchFilter.refName);
if (constraintValue) {
if (hasConstraint) {
xpath += " and ";
} else {
xpath += "[";
}
hasConstraint = true;
if (searchFilter.refName) {
xpath += searchFilter.refName + "[";
}
switch (searchFilter.operatorType) {
case "st":
xpath += "starts-with(" + searchFilter.attrName + ", " + constraintValue + ")";
Expand Down Expand Up @@ -928,6 +935,9 @@ define([
default:
xpath += searchFilter.attrName + " = " + constraintValue;
}
if (searchFilter.refName) {
xpath += "]";
}
}
}, this);

Expand Down Expand Up @@ -1099,23 +1109,36 @@ define([
/**
* Get the attribute value for use as constraint value
*
* @param attrName The attribute name
* @returns {string} The value
*/
_getConstraintValue : function (contextEntityAttr, attrName) {
_getConstraintValue : function (contextEntityAttr, attrName, refName) {

var attrType,
attrValue,
dateFormat,
refEntity,
refMetaData,
result;

if (!this._contextObjMetaData.has(contextEntityAttr)) {
logger.error(this._contextObj.getEntity() + " does not have attribute " + contextEntityAttr);
return null;
}
if (!this._entityMetaData.has(attrName)) {
logger.error(this._contextObj.getEntity() + " does not have attribute " + attrName);
return null;
if (refName) {
refEntity = refName.substring(refName.lastIndexOf("/") + 1);
refMetaData = mx.meta.getEntity(refEntity);
if (!refMetaData) {
logger.error("No meta data found for entity " + refEntity);
return null;
}
if (!refMetaData.has(attrName)) {
logger.error(refEntity + " does not have attribute " + attrName);
return null;
}
} else {
if (!this._entityMetaData.has(attrName)) {
logger.error(this.tableEntity + " does not have attribute " + attrName);
return null;
}
}

attrValue = this._contextObj.get(contextEntityAttr);
Expand All @@ -1125,7 +1148,11 @@ define([
}

// Use the type of the grid entity attribute. Important for boolean because the context entity attribute will be an enum.
attrType = this._entityMetaData.getAttributeType(attrName);
if (refName) {
attrType = refMetaData.getAttributeType(attrName);
} else {
attrType = this._entityMetaData.getAttributeType(attrName);
}

switch (attrType) {
case "String":
Expand Down
Binary file modified test/DataTablesTest.mpr
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum MemberNames
DateValue("DateValue"),
DecimalValue("DecimalValue"),
BooleanFilter("BooleanFilter"),
CountryCode("CountryCode"),
ExportConfig("ExportConfig"),
ExportXPath("ExportXPath"),
DataTableContextEntity_Person_Current("DataTablesTestModule.DataTableContextEntity_Person_Current"),
Expand Down Expand Up @@ -574,6 +575,42 @@ public final void setBooleanFilter(com.mendix.systemwideinterfaces.core.IContext
getMendixObject().setValue(context, MemberNames.BooleanFilter.toString(), null);
}

/**
* @return value of CountryCode
*/
public final java.lang.String getCountryCode()
{
return getCountryCode(getContext());
}

/**
* @param context
* @return value of CountryCode
*/
public final java.lang.String getCountryCode(com.mendix.systemwideinterfaces.core.IContext context)
{
return (java.lang.String) getMendixObject().getValue(context, MemberNames.CountryCode.toString());
}

/**
* Set value of CountryCode
* @param countrycode
*/
public final void setCountryCode(java.lang.String countrycode)
{
setCountryCode(getContext(), countrycode);
}

/**
* Set value of CountryCode
* @param context
* @param countrycode
*/
public final void setCountryCode(com.mendix.systemwideinterfaces.core.IContext context, java.lang.String countrycode)
{
getMendixObject().setValue(context, MemberNames.CountryCode.toString(), countrycode);
}

/**
* @return value of ExportConfig
*/
Expand Down
Binary file modified test/widgets/DataTables.mpk
Binary file not shown.

0 comments on commit a95948f

Please sign in to comment.