sencha multiple filter in one property - extjs

I am creating a grid and i want to be able to insert multiple Not Filters.
I have a grid of invitations
then i add the filter
store.addFilter(
[{ property: 'invitationStatus',
operator: '<>',
value: 'IN_PROGRESS'
},
{
property: 'invitationStatus',
operator: '<>',
value: 'SENT_BY_COMPANY'
},
{
property: 'invitationStatus',
operator: '<>',
value: 'SENT_BY_SYSTEM'
}]);
But the only filter applyed is:
{
property: 'invitationStatus',
operator: '<>',
value: 'SENT_BY_SYSTEM'
}
How can i change this?

There doesn't seems to be an <> in the operators list. In your case, the suitable operator is notin, passing as value an array of elements that you don't want to be included in the filtered results.
Something like this:
store.addFilter({
property: 'invitationStatus',
operator: 'notin',
value: ['IN_PROGRESS', 'SENT_BY_COMPANY', 'SENT_BY_SYSTEM']
});

Related

How to push a new value to an array if the current value is an array or set the value as an array if it is not in a single MongoDB Query

I have a project where we have been using simple, unversioned values for documents:
{
_id: <someid>,
prop1: 'foo',
prop2: 'bar',
prop3: 'baz'
}
I would like to update the method that saves prop values to start saving values as versions in an array, to look like this:
{
_id: <someid>,
prop1: [{ value: 'foo', createdAt: <someDate>}],
prop2: [{ value: 'bar', createdAt: <someDate>}, { value: 'barrrrr', createdAt: <someDate>}],
prop3: 'baz'
}
I would like, in my update query, to $push the new prop value object if it's already an array, or to $set it to `[{ value: 'newvalue', createdAt: +new Date()}] if not. Ideally, this would let me seamlessly transition the data to be versioned over time. On the retrieval side, if it's not an array we just treat the only value that's there as the reference version, and whenever anything gets updated, that prop is converted to the new format.
I've been struggling to find an example of that same use case: can anyone point me in the right direction?
UPDATE:
After being pointed in the right direction, I was able to use the aggregation pipeline in combination with update to do what I wanted. Part of the key was to abandon trying to pivot between setting and pulling--instead, I could use the helper method $concatArrays to accomplish the array addition a different way. Here's the basic shell code I got to work, purely to show the structure:
db.test.docs.update({ key: 2 }, [
{
$set: {
prop2: {
$cond: {
if: { $isArray: '$prop2' },
then: {
$concatArrays: [
'$prop2',
[
{
value: 'CONCAT!'
}
]
]
},
else: [
{
value: 'SET!'
}
]
}
}
}
}
]);
In MongoDB 4.2 you can use the pipeline form of update to use aggregation stages and operators to do that.
You would likely need to use $cond and $type to find out if the field already contains an array, and then $concatArrays to combine the values.

How to create a remote filter on multiple fields? Ext Js 5

How can I create a filter on multiple fields, which filters on the server, and not in the local store?
So far I've only gotten locally.
onFilter: function(field, newValue, oldValue, options){
var grid = Ext.getCmp('grid');
grid.store.clearFilter();
if (newValue) {
var matcher = new RegExp(Ext.String.escapeRegex(newValue), "i");
grid.store.filter({
filterFn: function(record) {
return matcher.test(record.get('id')) ||
matcher.test(record.get('names'));
}
});
}
}
You cannot set filters with filterFn on remote filtering. Remote filtering can only take property-value-operator combinations that are sent to the backend, and have to be evaluated and acted on by the backend.
To filter on multiple properties, you can of course send multiple filters to the backend:
store.addFilters([{
id: 'idFilter',
property: 'id',
operator: 'eq',
value: newValue
},{
id: 'nameFilter',
property: 'names',
operator: 'like',
value: newValue
}]);
The backend then has to evaluate and apply these filters to the data. The values are sent to the backend without client-side validation or usage, so you could even send arbitrary property or operator names to the backend:
store.addFilters([{
id: 'idOrNameFilter',
property: 'idOrName',
operator: 'somethingsomething',
value: newValue
}]);
You would just have to tell your backend to parse the property name correctly from the parameter string and act accordingly.

Array to multiple object in underscore

I have an array that looks like this:
[{
LocalBond:"0",
LocalCash:"2.42",
LocalEquity:"0",
ForeignEquity: "4",
...
}]
What I want it look like:
[{
Source: "LocalBond",
Value: "0"
},
Source: "LocalCash",
Value: "2.42"
},
Source: "LocalEquity",
Value: "0"
},
{...}
]
I want to turn a single object into many objects. I also need the exclude the 'ForeignEquity' result.
I tried using _.map, and returning the fields I want, but I am struggling a bit. Am I on the right track? When I pass more than one parameter into my function, I don't get the desired result.
The most simple code is pure javascript:
Using for..in access to the property of the object, and inside of the for loop build the array.
http://www.w3schools.com/jsref/jsref_forin.asp
Example:
https://jsfiddle.net/jewrsL8a/5/
var collection = [{
LocalBond:"0",
LocalCash:"2.42",
LocalEquity:"0",
ForeignEquity: "4"
}];
var result = [];
for (var property in collection[0]) {
if(property!=='ForeignEquity'){
result.push({'Source': property, 'Value': collection[0][property]});
}
}
console.log(result);

Filters with two properties in extjs

I need to create a filter that has two properties or operators.
I need to filter the Type AND the Number to put in combobox. The data are shown in the same table in the database. In this filter below I can just filter the number, it ignores the type.
Does anyone know if there is any way to do? Thanks.
filters: [
{
property: 'type',
operator: '=',
value: 'recorder'
},
{
property: 'number',
operator: '=',
value: '{number.value}'
}
Without knowing the type of data you want to filter, it's hard to say why the type fiilter is not working. On a first glance, the filter config looks fine.
However, if the filter config won't work for any reason, you can also pass in a function for filtering:
filters: [
function(item) {
return item.get('type') == 'recorder';
},
{
property: 'number',
operator: '=',
value: '{number.value}'
}
]
Using a function also has the advantage, that you can set a break point and check which value is actually validated.

How to filter store by few items

Can enyone help me?
I need to filter store items by some ids.
I have a store and a model for it:
Ext.regModel('rt.models.Situation', {
fields: [
{ name: 'sitId', type: 'int' },
{ name: 'sitName', type: 'string' },
{ name: 'typeId', type: 'int' }
]
});
and I need to filter my store by ids like this
var filterIds=[1,2,3];
store.filter('typeId', filterIds);
but it is not working.
When I use only one id for filtering it works fine, but with array of ids it doesn't work.
For this situation you need to use store.filterBy(fn) method and supply your own filtering function (fn) that will test if id is contained in the filterIds array.

Resources