Filters with two properties in extjs - 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.

Related

Extjs 7.4.0 - Remote Filtering problem with filter Operators

I am using gridfilterbar with remote filtering and there is a problem with any filter type with any filter operator. The filter param that is encoded for the service call, always has a default operator and can't recognize a different operator. My filter config is like this:
filter: {
type: 'list',
operators: ['=', '!='],
options: [0, 1, 2]
},
My solution for this problem was to override the Ext.data.proxy.Server and do a quick fix for the encodeFilters function. I check inside the loop that iterates through the filters and change the operator manually:
for (i = 0; i < length; i++) {
if(filters[i].config.operator != filters[i]._operator){
filters[i].config.operator = filters[i]._operator
}
encode |= filters[i].serializeTo(out);
}
I am wondering if I missed something or if this is a bug that needs fixing.
Instead of opperators, opperator works for me in this Fiddle:
columns: [{
text: 'id',
dataIndex: 'id',
filter: {
type: 'list',
operator: ['!=='],
options: [0, 1, 2]
}
}, {
text: 'name',
dataIndex: 'name',
filter: 'string',
flex: 1
}]
Your examples do not show the use of several operators. Overall I guess you have to write your own custom filter (e.g. number, list,...), as this only works for remote filtering.
I would not override the Server proxy, but create a new filter.
Probably this Fiddle helps you to find a proper solution for your work. It has a custom store for the filter, which could replace your override:
Fiddle 2

Searching for a boolean type field from mongo via angular formly

I got to implement a simple search (or it was that to my mind), the field I'm searching for is called "paymentStatus" on an Invoice and it's basically a boolean value in a mongo db (v3.4). The search comes from angular-formly input field (angularJS 1.6), and I can see it logged quite easily , as "paymentStatus - true", and "paymentStatus-false" when I send the info to search for -
{ paymentStatus: true }
Formly field looks like this -
{
key: 'paymentStatus',
type: 'horizontal-ui-select',
className: 'tooltipLabel',
templateOptions: {
optionsAttr: 'bs-options',
ngOptions: 'option[to.valueProp] as option in to.options | filter: $select.search',
label: $filter('translate')('Payment Status'),
placeholder: $filter('translate')('Payment Status'),
valueProp: 'paymentStatus',
labelProp: 'name',
searchable: true,
tooltipClass: 'wide-tooltip',
options: [
{"paymentStatus": true, "name": 'Paid'},
{"paymentStatus": false, "name": 'Unpaid'},
]
}
},
In the controller for backend to fill up the table with data to be displayed (which works correctly),
I have additional code for search filter which is like this -
if (where.paymentStatus && where.paymentStatus !== null && where.paymentStatus !== undefined) {
mongoQuery[0].$match["$and"].push({"paymentStatus": {$in: where.paymentStatus}});
}
I tried playing with $eq instead of $in and basic true false toggles instead of "where.paymentStatus" which give me half result half the time. "where" is from request.allParams().data.where. I'm a beginner with DB work/searches, especially with mongo and angular JS formly. It's legacy code that's sparsely documented. Thanks for all the help.
Never mind, where.paymentStatus annuled my querying for false status. Replaced $in with $eq also. Works properly now.

AngularJS ui-grid re-using a custom filter

I have a basic grid with a couple of columns that are ranges, i.e. 10 - 50, 0 - 9, etc. and I've written a custom filter on one of the columnDefs;
filter: {
condition: function(searchTerm, cellValue) { ... }
}
The filter works perfectly, but I'd like to strip it out and re-use it, only I can't figure out how.
I've tried defining it in the controller as function rangeFilter(...) and vm.rangeFilter = rangeFilter and then assigning it to the condition as grid.appScope.filterRange(searchTerm, cellValue) but that doesn't work.
I'm not really sure how else I'd do it, I haven't been able to find anything in the documentation or by googling for it.
Here's a plunkr of it in action; http://next.plnkr.co/edit/mbtXzfWqBg8FIALu
As you did, move the function out of the column definitions.
function rangeFilter() {
...
}
And in the column definitions pass a reference to the function in both.
vm.gridOptions = {
...
columnDefs: [
// default
{ field: 'name' },
{ field: 'range', cellFilter: 'range', filter: {condition: rangefilter}},
// I want to reuse the same filter as 'range' for this column somehow...
{ field: 'anotherRange', cellFilter: 'range', filter: {condition: rangefilter}}
],
...
};
Plunker

sencha multiple filter in one property

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']
});

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