was working on some more advanced filtering options for our product that’s using smartclient 6.0 and ran into an interesting issue. When client-side filtered results such that none match we are getting a single null record being displayed instead of the empty message. Tracked through a whole bunch of stuff before finally checking if the isEmpty call was returning the correct value, and it was not. Looking at the code in 6.0 reveals the issue:
isEmpty : function () {
if (this.isPaged()) {
// If there's a full cache for the current filter criteria, check the length of the data
if (this.allRowsCriteria) {
return this.getLength() == 0;
// For a paged dataSet, the cachedRows attribute indicates we have successfully
// fetched rows from the server (so this is non empty)
} else if (this.cachedRows > 0) return false;
}
return !this.lengthIsKnown() || this.getLength() <= 0;
}
when the resultSet is paged (on by default for all those is use) and allRowsCriteria is empty (only see it being set in setCriteria and then only when it’s more restrictive than the last) it uses cachedRows to see if it’s got any data. Unsure why the special handling for paged results but what really strikes me is the use of the allRowsCriteria so see if it’s a locally filtered set, seems the method allMatchingRowsCached would be a better choice. Indeed once that if is changed to call this method the issue seems to disappear and we get the empty message as we should.
I have verified that the same code exists in 6.5 so would like to suggest a fix for this in your next release and/or a patch for the current version. the following is my suggestion:
isEmpty:function() {
if(this.isPaged()) {
if(this.allMatchingRowsCached()) {
return this.getLength()==0;
} else if(this.cachedRows>0) {
return false;
}
}
return(!this.lengthIsKnown()||this.getLength()<=0);
}
Thanks
-john
Hi John,
Thanks for taking the time to track this down and report it.
To confirm, this looks like a bug that could happen only if you had set useClientFiltering to false - otherwise, anytime allMatchingRowsCached() is true, allRowsCriteria should also be non-null. So I take it you ran into this as you turned client-side filtering off to do more sophisticated filtering?
Note by the way that you can mix server-side filtering that isn’t field-based (eg full text search) with client-side field-based filtering. Even with client-side filtering enabled, SmartClient will assume that any change in filter criteria in a field which is not declared in your DataSource requires a trip to the server.
useClientFiltering is true
Thanks for the reply, and glad to help.
Unfortunately I don’t think we have a complete handle on it yet as on this resultSet the useClientFiltering flag is set to true. Now I have implemented my own version of recordsMatchingFilter and fieldMatchesFilter in order to match the server side filtering logic and set the criteriaPolicy to dropOnChange so that compareCriteria will notice that things have changed when non field name criteria have changed. Now the way I read this is that the ResultSet.setCriteria (the only place allRowsCriteria is set) will call DataSource.compareCriteria will call DataSource.dropOnChange which will return -1 if anything’s changed, in the setCriteria if for -1 it will call filterLocalData (as I want) then will invalidateCache and set allRowsCriteria to null. This is why I needed to change the isEmpty function… Perhaps this is the true bug but I’m not really sure what you’re using allRowsCriteria for so may be appropriate to be null in this case.
Yes, realize it does that and use it in some cases, was hoping to avoid the server trip in this case as the logic can be implemented client side. The default “contains” style filter is great but needed “matches”, “is one of these”, “greater than”, “less than”, “between”, and the negative cases for each. Gave an interface for entering these advanced filters, hopefully will let them really get down to exactly what they want without any they don’t. If you’re interested contact me off forum for details.
Again thanks for the reply.
-john
allRowsCriteria is basically the criteria as they were when a complete cache was obtained and the ResultSet switches into local filtering mode. So in the existing isEmpty() implementation is being used as a shorthand for local filtering being active.
Might be able to save you a lot of work - have you seen the AdvancedFiltering features in 7.0 beta? It has the operators you need plus many more, as well as UI components for building advanced filter criteria, and full support for client and server-side filtering by those advanced criteria..
You can actually see it online in the SmartGWT Showcase, which is based on 7.0 beta.