Okay
  Public Ticket #2435506
Calculated table column not updatable
Closed

Comments

  •  2
    Perla started the conversation

    I created a view which has a column that calculates AGE based on date of birth (DOB).

    create view test_view1 as select *, FLOOR(DATEDIFF(CURDATE(), DOB)/365.25) as AGE from wpdatatable_12;

    Then, in WPDataTables I created a table from the view (method learned from one of your YouTube tutorials) using select * from test_view1.

    The behavior I expected was if I added a new record or changed the DOB of an existing record, AGE would be calculated or recalculated. However, I get an error message that the AGE field is not updatable.

    Any idea what I'm doing wrong?

    Thanks.

  •  2
    Perla replied

    Also, I believe what I'm trying to do could be accomplished by adding a Formula Column to my table. Unfortunately, I am limited to rudimentary math only on Number columns, whereas my calculation is on a Date field and external functions, DATEDIFF and CURDATE. 

    Is there a workaround for this? Could I calculate AGE in a shortcode and set it in the Formula Column?

    Thanks.

  •  2,507
    Aleksandar replied

    Hi again Perla

    Unfortunately, you won't be able to use date columns in Formulas, as only integer and float values will work there.

    Now, the issue here is that you are trying to modify a view, and unfortunately MySQL Views cannot be edited properly – only one of the underlying tables can be edited if you pass the proper ID.

    Since you're pulling the data from wpdatatable_12, you would be able to modify that table, and the table created from the view will respond.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables