Special filter

mariluzrm

Member
It's clear to me that it's possible in Fabrik filter a list by any field (Advanced search) (for example field measurent>3). But, is it posible filter by another condition for example, I have this list:

id-----cod_device-----measurement---- date
1--------A ---------------1.2-------------2022/01/01
2 -------B ---------------3.2-------------2022/01/01
1--------A---------------2.0-------------2023/01/01
2--------B---------------4.3-------------2023/01/01

I want the devices whose measurement difference is greater than 1 (the result would be B since 4.3-3.2>1)

Thanks!!
 
Last edited:
Sounds like a case for a MySQL view, where you can use your data to populate additional columns with the results of all calculations you might need. Then create a Fabrik list for the view with filters on the columns as required.
Obviously, a view will always be read-only.
 
You'll need two lists
- listA holding the data in a real DB table, where the user can add/edit
- listB linked to the MySQL view (which is "updated" automatically)

ListB will display the data, has the filters and needs custom Add and Edit links pointing to the ListA forms.
ListA form needs a redirect to listB.
 
Thanks. But I have a problem (I didn't explain it well), and I don't know if it can be solved with a View... In the table I will have more than two records for each cod_device and I only have to do the subtraction of the last two measurements (by date) of each . For example

id-----cod_device-----measurement---- date
1--------A ---------------0.9-------------2021/01/01
2 -------B ---------------2.8-------------2021/01/01
3--------A---------------1.2-------------2022/01/01
4--------B---------------3.2------------2022/01/01
5--------A---------------2.0-------------2023/01/01
6--------B---------------4.3-------------2023/01/01

cód_device=A --> 2.0-1.2=0.8 (They are the last two measurements by date for A, although it has 3 measurements)
cód_device=B --> 4.3-3.2=1.1 (They are the last two measurements by date for B, although it has 3 measurements)

In the view it should appear, to then be able to do the filters:

cod_device-----subtract_measurement
A-----------------0.8
B-----------------1.1

And I don't see that this can be done with a simple query to fill the view...

What I can do?

Thanks
 
It's a bit more complicated. So, no, it can't be "a simple query", indeed.

Can't go into every detail here but, as already indicated, you can have multiple (new) columns in the MySQL view, e.g. to set "markers" depending on relationships in between records, to contain results which you then can filter on, etc. You know, basically everything is possible with the right code. And the right plan/concept/structure to start with. ;)
 
I don't quite understand how to do it with a View. Isn't there a place in fabrik where I can write php, sql to do these "special filters"?

Thanks
 
You can also use an additional field used for filtering and fill it on form save via a php plugin.

If this data will change if other records are added or with changing dates you have to do it on every list load (e.g. via php events).
 
Thanks.
Where do I add this additional field? In the measurements table? But, would it repeat for each record?
 
It's just a normal Fabrik element which - yes - will be in each record.
It's up to you to fill it.
 
Could I put the field in Devices table instead of Measurements table? (so it doesn't repeat itself every time, only once per device). To fill the field in the Devices table, I would have to access the Measurements table with php to subtract the records. Is there some problem (it's another table...)? I would have to update the field on every list load (with php events), because there will be updates of measurements.
Is it correct?

Thanks
 
Thanks, I'll try it.
Another related question:
If I have two fields A and B and I want the records that meet a simple condition, for example: A+B>20, do I necessarily have to make a view with another field or can I write the query somewhere in Fabrik?
 
Thanks!!

But if I want a user-selectable filter, Is there something other than the default ones in predefined Advanced search?

Would the search plugin be useful for this?
 
But if I want a user-selectable filter, Is there something other than the default ones in predefined Advanced search?

Would the search plugin be useful for this?
No, you have to do it yourself with additional fields or MySQL views etc.
 
Last edited:
Thanks.
One last question regarding this: would Search Form be valid for what I asked? What is the difference from Advanced Search?
 
With a search form you are collecting some data and you can do with it what you want.

e.g. use build-in options of the redirect plugin
http://fabrikar.com/forums/index.php?wiki/create-a-search-form/

or add a php (onBefore) plugin, use the data (elements don't need to match any other element names in this case) to calculate some URL and redirect to this URL for list filtering http://fabrikar.com/forums/index.php?wiki/filtering-lists-tables/
e.g. calculate all ids matching whatever condition and do a URL filtering with IN
http://fabrikar.com/forums/index.php?wiki/filtering-lists-tables/#using-in-not-in
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top