V8-archive: Automatic calcule on field through hook or interface?

Created on 10 Feb 2020  Â·  5Comments  Â·  Source: directus/v8-archive

• Version of Directus
8.4.0 (Digital Ocean)

How to do automatic calculation to place a field.
Example: 3 fields:
A. Field: quantity.
B. Field: unit value.
C. Field: total value (A*B).

example

I don't know, how to do this method in interface or hook or other for field C?

app

Most helpful comment

I'd love to be able to have a custom function interface that allows for SQL functions in select statements. So that we could run things like:

CONCAT(name, "-", age) Or MAX(col1, col2, col3) or multiplication like what @andgar2010 was talking about.

All 5 comments

@benhaynes this could be a good use case for that readonly interface idea we had before 🙂

@andgar2010 we're thinking of having a couple "read-only" interfaces that would be able to display information like this in a more 'presentation' way

@rijkvanzanten agree with you to set "read-only".
as a field sample: Product Total Amount "$ 200.000"

I'd love to be able to have a custom function interface that allows for SQL functions in select statements. So that we could run things like:

CONCAT(name, "-", age) Or MAX(col1, col2, col3) or multiplication like what @andgar2010 was talking about.

I love that idea! It's hard to bring vanilla SQL into App/API since everything has to go through our database abstraction layer (for vendor support)... and also for security reasons. Still, I'd love to figure out a good/safe way to handle this. In the meantime, you can always create a custom interface/endpoint/hook to handle this... that's what those extension modules are for! 😉

@rijkvanzanten — yeah! I think we could look into a good way to have a readonly "metric" interface that also has some interface options for these common operators (eg: concat could be done with a template string).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vuhrmeister picture vuhrmeister  Â·  3Comments

gitlabisbetterthangithub picture gitlabisbetterthangithub  Â·  3Comments

chintohere picture chintohere  Â·  3Comments

andgar2010 picture andgar2010  Â·  3Comments

cdwmhcc picture cdwmhcc  Â·  3Comments