GXT add filter to store - gwt

I'm having problems with a relatively simple piece of code.
I'm trying to set a filter for my store items (store associated with a GridView).
gridStore.addFilter(new StoreFilter<IncidentDto>() {
#Override
public boolean select(Store<IncidentDto> store, IncidentDto parent, IncidentDto item) {
if (item.getDescription().equals("WEEEE-TEST")) {
return true;
} else {
return false;
}
}
});
The problem is the store doesn't filter at all.
Thanks to anyone who will take the time to help me out with this.

Don't forget to enable the filters - this exists so that you can make several filter modifications without actually asking them to act:
gridStore.setEnableFilters(true);
Sorting doesn't have this as there isn't a concept of turning sorting 'off' - items are sorted to have a new order, then they stay that order. In contrast, filters can be turned back off to restore the items that are no longer visible.

If you trace the code, you will notice that the filter is not called in onLoad(). You have to manually call filter();

Related

flutter list contains check model not working

// ----- a list to store the favourites courses list
List<FavouriteModel> _favCourses = [];
void initAddToFav(FavouriteModel model, BuildContext context) {
if (_favCourses.contains(model)) {
_courseController.removeFromFavourite(model);
AlertHelper.showSanckBar(
context, 'Remove from favourites !', AnimatedSnackBarType.error);
notifyListeners();
} else {
_courseController.addToFavourite(model);
AlertHelper.showSanckBar(
context, 'Added to favourites !', AnimatedSnackBarType.success);
notifyListeners();
}
}
When try check _favCourses.contains favourite model then if condition not working even data exsist else part working
You are using .contains on a list of FavouriteModel objects. Dart doesn't automatically know how to test if one object is equal to another in the same way that it compares numbers or strings. So it will compare the item by memory address. That is unless you tell it how to test if the two objects are equal using a key.
Take a look at this answer here which uses a different way of checking if the list contains the item.
Check whether a list contain an attribute of an object in dart
you are check wrong condition because you applied the condition on _favCourses list and perform the task in _courseController.
Correct your if condition
If(_courseController.contains(model))
{
_courseController.removeFromFavourite(model);
AlertHelper.showSanckBar(context, 'Remove from favourites !', AnimatedSnackBarType.error);
notifyListeners();
}

Anybody who can help understand this Knockout Observable?

I am a complete beginner in Software Development, and got introduced to a project which I have a hard time understanding and knowing where to start
this.isConfirmationCar = ko.computed(() => {
if (this.selectedTemplate() && this.selectedTemplate().Id ===
<number>Enums.PolicyEmailTemplates.ConfirmationOfCoverCar) {
return true;
} else {
return false;
}
});
It looks to be returning a boolean value and storing it within this.isConfirmationCar.
This being either true/false dependant on the argument defined as -
{ if (this.selectedTemplate() && this.selectedTemplate().Id === Enums.PolicyEmailTemplates.ConfirmationOfCoverCar) { return true; } else { return false; }
FYI - Knockoutjs has a great website with an excellent tutorial http://learn.knockoutjs.com/#/?tutorial=intro
It covers the ko.computed function in the intro worth a look!
What you have there is a computed observable which is nothing more but a function which inside of its body tracks ANY other observable used. Not only it tracks it but it would execute itself again and again on those tracked observables values mutating.
Computed observables are extremely useful. Note that they have various "options" in terms of how to defined them and some interesting siblings like the pureComputed observables.
In this example the computed isConfirmationCar is used to track the values of the other observables selectedTemplate and selectedTemplate. The moment any of those change that computed with refresh its value which is why it is used in this context for tracking isConfirmationCar.
Hope this helps.

Are there any side effects of exiting a loop with return rather than break in Swift?

I need to match items in two different arrays (one with imported items and another with local items that share some properties with the imported items) to sync two databases that are quite different. I need to use several criteria to do the matching to increase the robustness of finding the right local item and match it with the imported item. I could check each criterium in the same loop, but that is too expensive, because the criteria are checked by the likelihood of success in descending order. Thus, in my first implementation I used a boolean flag called found to flag that the checking of other criteria should be ignored.
Using pseudo code:
// calling code for the matching
for item in importedItems {
item.match() }
In the imported item class:
match()
{
var found = false
for localItem in localItems
{
if (self.property == localItem.property)
{
// update the local item here
found = true
break
}
}
// match with less likely 2nd property
if (!found)
{
for localItem in localItems
{
if (self.property2 == localItem.property2)
{
// update the local item here
found = true
break
}
}
}
The if !found {...} pattern is repeated two additional times with even less likely criteria.
After reviewing this code, it is clear that this can be optimized by returning instead of breaking when there is a match.
So, my question is "are there any known side-effects of leaving a loop early by using return instead of break in Swift?" I could not find any definitive answer here in SO or in the Swift documentation or in blogs that discuss Swift flow control.
No, there are no side effects, quite the opposite it's more efficient.
It's like Short-circuit evaluation in a boolean expression.
But your code is a bad example because found cannot be used outside the function.
This is a more practical example returning a boolean value
func match() -> Bool
{
for localItem in localItems
{
if (self.property == localItem.property)
{
// update the local item here
return true
}
}
....
return false
}
If you know for sure that you can return because nothing else have to be done after the loop then there are no side effects of using return

Syncfusion GroupingGrid always expanded

I´m working with a GroupingGrid of the Syncfusion. And I realized that the ExpandAllGroups() operation is consuming many resources, than I thought that maybe GroupingGrid have some parameter that lets all groups expanded by default.
Any help?
An alternative way to expand the Groups is by using IsExpanded property. This is a Boolean property which could be set to true in order to set the groups to an expanded state.
public void iterate(Group g)
{
foreach (Group gr in g.Groups)
{
gr.IsExpanded = true;
iterate(gr);
}
}
The above method can be called by using the following code in form():
this.iterate(this.gridGroupingControl1.Table.TopLevelGroup);
Kindly, check with the above code and see if it resolves your issue

Zend Framework: is there a way to access the element name from within a custom validator?

I'm writing a custom validator that will validate against multiple other form element values. In my form, I call my custom validator like this:
$textFieldOne = new Zend_Form_Element_Text('textFieldOne');
$textFieldOne->setAllowEmpty(false)
->addValidator('OnlyOneHasValue', false, array(array('textFieldTwo', 'textFieldThree')));
My validator will check that only one of those three fields (textFieldOne, textFieldTwo, textFieldThree) has a value. I want to prevent a future developer from accidentally passing the same field twice.
$textFieldOne->addValidator('OnlyOneHasValue', false, array(array('textFieldOne', 'textFieldTwo', 'textFieldThree')));
So far, my validator works perfectly, except when I pass the same field name as the field that has the valiator set on it.
In my validator, you can see that I am checking that the value (of the element with the validator set on it). I'm also checking the values of the other fields that were passed to the validator.
public function isValid($value, $context = null) {
$this->_setValue($value);
$this->_context = $context;
if ($this->valueIsNotEmpty()) {
if ($this->numberOfFieldsWithAValue() == 0) {
return true;
}
$this->_error(self::MULTIPLE_VALUES);
return false;
}
if ($this->numberOfFieldsWithAValue() == 0) {
$this->_error(self::ALL_EMPTY);
return false;
}
if ($this->numberOfFieldsWithAValue() == 1) {
return true;
}
if ($this->numberOfFieldsWithAValue() > 1) {
$this->_error(self::MULTIPLE_VALUES);
return false;
}
}
private function valueIsNotEmpty() {
return Zend_Validate::is($this->_value, 'NotEmpty');
}
private function numberOfFieldsWithAValue() {
$fieldsWithValue = 0;
foreach ($this->_fieldsToMatch as $fieldName) {
if (isset($this->_context[$fieldName]) && Zend_Validate::is($this->_context[$fieldName], 'NotEmpty')) {
$fieldsWithValue++;
}
}
return $fieldsWithValue;
}
My solution is to either...
A. Let the developer figure out there is a certain way to do it.
B. Ignore $value, forcing you to pass all the elements (which isn't much different than the first option).
or C. (if possible) Find the name of the element that called my validator in the first place and ignore it from the list of $fieldsWithValue.
I don't think there is a way to apply a validator on a form without attaching it to an element, but that would be even better, if it were an option.
How can I solve this problem?
Normaly i'd advise against such things, but, in this case I believe a static member in your class would actually provide a good solution to this problem.
With a static member, you can set it to the value in the first time the isValid is called, and check against it in subsequent calls, thus giving you a mechanism for this.
You may want to set this up to use some array in the configuration options, so that you can namespace and allow multiple instances of the validator to exist happily alongside each other for different sets.
The only problem that you really have to decide how to overcome, is where you wish to display the error, as yes the form itself does not take validators. if you want all the duplicates after the first to display an error, it is not so much of a problem.