Make editor use a predefined obj model when saving new row into datatable

Make editor use a predefined obj model when saving new row into datatable

Red SniperRed Sniper Posts: 47Questions: 9Answers: 0

Link to test case:
http://live.datatables.net/hovopoce/3/edit

Description of problem:
in some tables i have some data that I might want to show to the user, but he shouldn't be able to modify.
So , I have set up the editor with the fields he can edit only.
The problem I encounter is that after I create a new row with inlineCreate() , the obj that datatables adds to his data array contains only the fields the user was allowed to edit.
In the example table, the 3rd columns uses the values from valA and valB to show a sum (it is just an example, it would be avoidable if I would calculate it on the fly rather than have a property in the data array).
In other situations I need to store row properties I receive from the server (for later computations) , that the user must not see.

How can I tell editor to use a predefined object as a row model obj upon which overwrite users' inputs? (something like the obj returned from method newRowModelObj())
Thanks in advance for the help!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    I think you would indeed be better served here by calculating the row sum values on the fly with a rendering function.

    If that isn't possible, then I think you'll need to create that calculation in preCreate and preEdit, where you have access to the data object and can modify it (i.e. add the missing properties via their calculation).

    Regards,
    Allan

  • Red SniperRed Sniper Posts: 47Questions: 9Answers: 0

    Yep, I've tried using the preCreate but couldn't figure out how to update the data receveid as parameter .

    I have updated the test case, but had no idea on how to update the data obj
    http://live.datatables.net/hovopoce/7/edit

  • Red SniperRed Sniper Posts: 47Questions: 9Answers: 0
    edited February 2022

    Nevermind, I thought I could make the data point to the new object, but it was enough adding the missing properties with Object.assign()

    http://live.datatables.net/hovopoce/10/edit

    thanks for the help!

Sign In or Register to comment.