Field Value

Field Value

karliekarlie Posts: 83Questions: 17Answers: 0

Hi, is it possible to have a field that is Col 1 * Col 2 but can also let the user overwrite it with a manually entered figure if they wish?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin
    Answer ✓

    Yes - what I would do in this case is have that column in the database as null. Use column.render to check if the value is null - if so then perform the calculation (perhaps marking it in italics to show that it is calculated and not an actual value) - if it isn't null, then just return the value.

    On the Editor side of things you'd use a plain text field and the ifEmpty set formatter on the server-side to write null to the database if an empty string is submitted.

    Allan

  • karliekarlie Posts: 83Questions: 17Answers: 0

    Thanks Allan, I used this code

    {
                    "data": "each_price",
                    render: function (data, type, row, meta) {return (data == null) ? '£'+ row['ct'] * row['ppct'] : '£'+ data;}
                },
    

    It dawned on me that this solution isn't going to work though as I will be using the data in the database for something else, so rendering the column will just give me a null in the database (there's a saying about planning that comes to mind!). I'll need to look at a solution on the database side as I need the data rather than just null.

  • karliekarlie Posts: 83Questions: 17Answers: 0
    edited March 2018

    Unless there's any way of writing the rendered value back to the database?

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    Do you mean to convert what you currently have? I wouldn't do a write on each call to render - that would kill performance (and probably the server!), but you could pre-process the SQL data if that is the issue.

    Allan

  • karliekarlie Posts: 83Questions: 17Answers: 0

    The table cell displays a user entered value. If it's blank it will multiply 2 other table cells together and render that figure in the cell. What I'm wondering is if there is any way to write that rendered value back to the database? Currently it has null stored in the DB (which is the situation that causes the rendered contents to be produced.)

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    If you are using Editor for this, I would suggest using a server-side event - have a condition that will check to see if the user has entered a value for your target cell, and if so, set the value per your calculation for the other field, and that can then be saved into the db.

    Having said that, if its just a calculated value, why bother saving it into the db at all?

    Allan

This discussion has been closed.