Dependent Field update on inline editing

Dependent Field update on inline editing

rangaranga Posts: 31Questions: 12Answers: 2
edited April 2019 in Free community support

I have a dependent field in my table and needed to update it with some calculation on inline editing .
{ data: null, "render": function (data, type, row) { var t = (data["_Exapnd_Value"] - data["_Item_TotalAmount"]) return t.toLocaleString()+".00" }
But the thing is i needed to update the database also with this value . and display in the table also.
any ideas how i can achieve this ?

Thank You

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Just to confirm, you are storing the calculated value in the database? But also calculating it on the client-side? If so, then two options spring to mind:

    1. Use a database trigger to update the calculated value in the db whenever one of the component values change.
    2. Use a server-side event to calculate the value (use the field's ->setValue() method to set the calculated value).

    Allan

  • rangaranga Posts: 31Questions: 12Answers: 2

    @allan Thanks Allan
    Value is calculated by a another value entered by the client . so then it should save to database with the calculated value and displayed in the table. i think setvalue() mehod is great . do you know anywhere i can find example calculation done using setvalue() method?

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    I'm not clear why you are doing the calculation, storing the result in the database, and then doing the calculation again when drawing the table?

    There is a setValue example here. The data submitted from the form is available in the $values array.

    Allan

  • rangaranga Posts: 31Questions: 12Answers: 2
    1. its a very simple scenario @allan .a table contains two fields which are "current
      payment" and "current total".

    2. client has to enter and value which is a payment he put monthly .

    3. and the amount he entered should deduct from the total amount he took as a loan.
      it is a also a field in the datatbase. (total = total -payment)

    4. so when he enteres the value it should deduct from the total value.

    5. so as you can see calculation should happen within the time he enters the payment
      and also both fields should update as last payment and current total.

    im doing a C# MVC project. so where can i perform the calculation at run time? is it possible within setvalue() method like :

    .setvalue( "total" , "total" -"payment")

    Extremely sorry for the disturbance.

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    im doing a C# MVC project. so where can i perform the calculation at run time? is it possible within setvalue() method like :smile:

    You'd do it in PreEdit event handler. I linked to the PHP docs before not realising you were using C#. The C# docs might help a little more!.

    Allan

  • rangaranga Posts: 31Questions: 12Answers: 2

    @allan Thanks a Lot ill put the code below for someone else who looks for the same

    using (var dbs = new DataTables.Database(setting.DbType, setting.DbConnection)) { var responsee = new Editor(dbs, "_IOU_Details", pke = "Detail_ID") .Model<DetailsDatatables>() .Where("Header_ID", j); responsee.Field(new Field("_TotalIOUAmount")); responsee.Field(new Field("_IOUAmount")); responsee.PreEdit += (sender, e) =>responsee.Field("_TotalIOUAmount").SetValue(Convert.ToDecimal(e.Values["_TotalIOUAmount"].ToString()) + Convert.ToDecimal(e.Values["_IOUAmount"].ToString())); var response = responsee .Process(reques) .Data(); }

This discussion has been closed.