Render function data doesn't return to database
Render function data doesn't return to database
Hi
I have two render functions in my columns. All the rest of the data from the columns returns to database after editing, but these two doesn't. I also wonder how datatable knows which column to use in the database since there is no indication of it from my render functions? Am I missing something?
First the code of a render function and then the corresponding php code:
(....)
{ data: "hold", render: "[, ].init" },//koden der kan vise flere hold
{ data: null,//TIMER: = faktor * fordelt
render: function ( data, type, row ) {
var num = (row.budget.faktor *
(intVal(row.budget.u31)+intVal(row.budget.u32)+intVal(row.budget.u33)
+intVal(row.budget.u34)+intVal(row.budget.u35)+intVal(row.budget.u36)
+intVal(row.budget.u37)+intVal(row.budget.u38)+intVal(row.budget.u39)
+intVal(row.budget.u40)+intVal(row.budget.u41)+intVal(row.budget.u42)
+intVal(row.budget.u43)+intVal(row.budget.u44)+intVal(row.budget.u45)
+intVal(row.budget.u46)+intVal(row.budget.u47)+intVal(row.budget.u48)
+intVal(row.budget.u49)+intVal(row.budget.u50)+intVal(row.budget.u51)
+intVal(row.budget.u52)+intVal(row.budget.u53)+intVal(row.budget.u1)
+intVal(row.budget.u2)+intVal(row.budget.u3)+intVal(row.budget.u4)
+intVal(row.budget.u5)+intVal(row.budget.u6)+intVal(row.budget.u7)
+intVal(row.budget.u8)+intVal(row.budget.u9)+intVal(row.budget.u10)
+intVal(row.budget.u11)+intVal(row.budget.u12)+intVal(row.budget.u13)
+intVal(row.budget.u14)+intVal(row.budget.u15)+intVal(row.budget.u16)
+intVal(row.budget.u17)+intVal(row.budget.u18)+intVal(row.budget.u19)
+intVal(row.budget.u20)+intVal(row.budget.u21)+intVal(row.budget.u22)
+intVal(row.budget.u23)+intVal(row.budget.u24)+intVal(row.budget.u25)
+intVal(row.budget.u26)+intVal(row.budget.u27)));
var n = num.toFixed(0);//reducerer num til n med 0 decimaler
return n
}
},
{ data: "budget.faktor"},
{ data: "budget.lektioner"},
(...)
Now in PHP:
)//lukker join
->fields(//fields åbner igen
Field::inst( 'budget.timer' ),//beregnet post....................................This is the one my render function should use.
Field::inst( 'budget.faktor' )->setFormatter( Format::ifEmpty( null ) ),
Field::inst( 'budget.lektioner' )->setFormatter( Format::ifEmpty( null ) ),
(....)
If anyone can lighten up my saturday, it will be most welcome.
Claus
This question has an accepted answers - jump to answer
Answers
The fields you define in the Editor config are what will be sent to the server when editing a row.
What problem are you trying to solve?
Kevin
Hi Kevin
The result of the render function is shown correctly on my screen, but it isn't saved in my MySQL database. All other posts are.
When you say Editor config what do you mean precisely? My understanding, which is not much, is that I use fields for designing what should be on the pop up editing. Should I have these computed post also, they must be not editable? Please explane it to me. I Would like to have a better understanding.
best regards
Claus
"Rendered" data is for display purposes only. It is not returned to the database.
Editor config is where your Editor object is configured - in PHP in your case - and includes for example your Field::inst() definitions.
To gain a better understanding I suggest you spend some time with the documentation.
The
fields
you define in the Javascript Editor config are the only fields Editor is concerned with.Do you really want to save computed values to the DB? Typically this isn't the case as the values used for the computation can change.
Kevin
Hi Kevin
Got confused because i changed the aritmetics between my columns, so it seemed as though some of the redered functions had found their way back to the database. So I've learned it the hard way.
Good old PHP did the trick. PHP computes the numbers and update the numbers in the database. Then DataTable's excellent filter functions can be used on the computed values. All is good.
Best regards.
Claus
Happens to all of us Glad you got it worked out.
Kevin