In Editable when a Cell is edited, edit automatically another Cell .
In Editable when a Cell is edited, edit automatically another Cell .
Hi all!
Im new in datatables and I have a question, I hope you can show me the way .
((And sorry for my bad english , I'm going to try to explain me as good as I can )
The case is:
I have an Editable with some columns , where the user will insert different numbers.
When the number is inserted , I would like to calculate automatically the value of the other cell.
For example :
If we put "1000"" in the row[5] , i would like to set automatically the row[6] with 1000 * 10 = 10.000.
Note: I will inform by php the cost "10" in order to calculate the result.
So, informing the user a single field, two cells are updated updated in the table; one manually and another one automatically.
Best .
This question has an accepted answers - jump to answer
Answers
In editor 1.4 this was easy with setFormatter on the PHP side as it submitted the whole row. Trying to figure this out w/ 1.5 myself.
Where do you want the calculation to occur?
My suggestion for generated values is normally to go with the last option and use the
columns.render
option.@jtoler5 - Yes, Editor's inline editing only submits the field in question now I'm afraid. I did look into submitting the whole form, but the internal mechanics mean that fields are now placed into an editing state individually, and it got really messy with inline editing. That isn't to say that I won't put it back if this turns out to be a mistake.
However, you could use the
preSubmit
event to add the row's information to the submitted data. For example:I know that's a bit messy and I will review this.
Regards,
Allan
I don't mean to 'highjack' this thread but... Allan, I love the new Editor and really want to have it working the best way. So my last question would be, is that the best way to do what I am trying to achieve? For example: I used to have a setFormatter that would append a 2 digit number (year) onto certain columns. So I would get the FY variable from the $data row in the formatter. Is there a better way to do this with 1.5 now?
What is the
FY
variable? Could you show me the code you were using for 1.4?@iamneox - Reply back with any question you have in this thread as well - we'll just mix the two conversations for this one :-). Keep me on my toes!
Allan
FY = Fiscal Year
What I had in 1.4:
I hate this database, but I did not design this database so I am limited to working with what is already in use. Fund number can change from year to year so each Fund number has the FY appended to it (FBFY).
I see yes. Unfortunately, in 1.5.0 that would require a database lookup, or using
preSubmit
to add the additional data as I described above.I will look at this again for 1.5.1!
Thanks,
Allan
Hi again!
Sorry for my very very late reply, I was on vacation.
Sorry @allan but I'm too newbie and I don't understand exactly how the "render" works.
I tried to do this very simple thing:
When I just edit one cell, I would like edit automatically another cell with a static string.
Like this :
But it doesn't work... Could you explain me like I'm 5 ?
Thanks in advance.
Best regards,
columns.render
should be a Javascript function (normally) that will transform data from one from to another. You generally will not want to use a string as its value. Thecolumns.render
documentation has further information and examples.Allan
@allan , thanks for your fast reply. I hope you are doing well.
Following your suggestion I'm trying to concatenate using the function like this :
It doesn't work, but there are no errors either.
Thanks!
Is that an Editor field definition? There is no
fields.render
method. As the documentation forcolumns.render
shows, it is a DataTables column option.Allan
Omg sorry it was a mistake, you are right x_X.
Now I made the changes in the columns (not in the Editor field definition)
And it works ^^.
My problem now is to know how to make it work with other rows.
I though I could do it using the Object row[x] like in this example : https://datatables.net/examples/advanced_init/column_render.html
But I'm doing something wrong.
Also another thing that concerns me is how to edit the field. I mean, for example If I have a field with the word "Good" and using the render I concatenate it with "Bye" I would like when I will push the cell to edit it shows "GoodBye" not only "Good".
For sure, I will make a control in order to render runs only once.
A lot of thanks @allan !!
Best