Skip to content

Commit

Permalink
Anysearch - play nice with LVC part 2
Browse files Browse the repository at this point in the history
Removed a subscription handler for object refreshes
Updated flow for firing searches when LVC widgets are involved. Minimizes the number of queries sent to the server.
  • Loading branch information
tieniber committed Apr 24, 2020
1 parent 6098c1a commit 0206761
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 24 deletions.
Binary file modified dist/GridSearch.mpk
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "GridSearch",
"version": "3.1.0",
"version": "3.1.1",
"description": "Search Mendix Grids and Lists using a number of search widgets.",
"license": "Apache 2",
"author": "Eric Tieniber",
Expand Down
10 changes: 6 additions & 4 deletions src/GridSearch/widget/AnySearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,15 @@ define([
this.subscribe({
guid: this._contextObj.getGuid(),
attr: this.xpathAttribute,
callback: this._fireSearch
callback: () => {
this._fireSearch();
}
});
this.subscribe({
/*this.subscribe({
guid: this._contextObj.getGuid(),
callback: this._fireSearch
});
this._fireSearch();
});*/
//this._fireSearch();
},

_isEmptyObject: function (obj) {
Expand Down
37 changes: 19 additions & 18 deletions src/GridSearch/widget/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,28 @@ define([
}

if (datasource._constraints !== constraints) {
datasource.setConstraints(constraints);
//if the grid is set to wait for search, ensure we set the "_searchFilled" flag
if (grid.config && grid.config.gridpresentation && grid.config.gridpresentation.waitforsearch) {
if (constraints) {
grid._searchFilled = true;
} else {
//grid._searchFilled = false; //grid doesn't refresh or empty if you do this
datasource.setConstraints("[1=0]");
if (grid.__customWidgetDataSourceHelper) {
//Using ListViewControls
grid.__customWidgetDataSourceHelper.store.constraints._none["GridSearch"] = constraints;
} else {
//No ListViewControls
datasource.setConstraints(constraints);
//if the grid is set to wait for search, ensure we set the "_searchFilled" flag
if (grid.config && grid.config.gridpresentation && grid.config.gridpresentation.waitforsearch) {
if (constraints) {
grid._searchFilled = true;
} else {
//grid._searchFilled = false; //grid doesn't refresh or empty if you do this
datasource.setConstraints("[1=0]");
}
}
}
}
self.onSearchChanged();
self._reloadOneGrid(grid);
console.log("set constraints for grid: " + grid.id)
self.onSearchChanged();
self._reloadOneGrid(grid);
console.log("set constraints for grid: " + grid.id)
} else {
console.log("did not set constraints for grid as they did not change: " + grid.id)
}
//duct tape and glue connection to the List View Controls widget
if (grid.__customWidgetDataSourceHelper) {
grid.__customWidgetDataSourceHelper.store.constraints._none["GridSearch"] = constraints;
}
},
_getSearchConstraintAllSearchBoxes: function () {
var searchWidgets = this._searchWidgets[this.targetGridClass];
Expand All @@ -189,7 +191,6 @@ define([
for (var i = 0; i < searchWidgets.length; i++) {
searchWidgets[i]._clear();
}

this._fireSearch();
},
_reloadGrid: function () {
Expand All @@ -202,7 +203,7 @@ define([
if (grid.__customWidgetDataSourceHelper) {
var dsh = grid.__customWidgetDataSourceHelper
dsh.requiresUpdate = true;
dsh.iterativeUpdateDataSource();
dsh.updateDataSource(function() {});
} else {
this._startProgressBarDelay();
if (grid.reload) {
Expand Down
2 changes: 1 addition & 1 deletion src/package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://www.mendix.com/package/1.0/">
<clientModule name="GridSearch" version="3.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
<clientModule name="GridSearch" version="3.1.1" xmlns="http://www.mendix.com/clientModule/1.0/">
<widgetFiles>
<widgetFile path="GridSearch/Comparison.xml"/>
<widgetFile path="GridSearch/GridFilter.xml"/>
Expand Down
Binary file modified test/widgets/GridSearch.mpk
Binary file not shown.

1 comment on commit 0206761

@cdcharlebois
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hurrah! 🎉

Please sign in to comment.