Issue with adding values via formatter to editor dropdown
Issue with adding values via formatter to editor dropdown
ziv@kpmbro.com
Posts: 73Questions: 28Answers: 4
Hi
I wanted to set a string next to each dropdown value in my table, so i used the getFormatter function.
for example instead of:
"1"
i draw
"1 :: TRUE"
same with
"0"
i draw
"0 :: FALSE"
The problem is that when i want to update that it doesn't work because the value is "1 :: TRUE" instead of "1" so the editor cant handle it(of course).
What is the best way to add string to a value ?
Thanks
This discussion has been closed.
Answers
I would suggest using a client-side renderer so you aren't modifying the raw data, but just the display output.
Allan
Hi Allan.
Right now i am sending something like this js array to the columns section:
[
{
"data":"offers_main_table.title"
},
{
"data":"offers_main_table.network_campaign_id"
}
]
I try this
[
{
"data":"offers_main_table.title"
},
{
"data":"offers_main_table.network_campaign_id",
"render":"test"
}
]
and it doesnt work.
How can i do something like:
from the columns js array(the json above)?
thanks
Ok i got it , I wrote it hard coded
[
{
"data":"offers_main_table.network_campaign_id"
},
{
"data":"offers_main_table.advertiser_id",
render: function ( data, type, row ) {
return data +'xxxx ';
}
]
but how can i do it dynamically ,can i do it with some kind of loop with conditions ?
I don't understand what you mean by dynamically I'm afraid. Do you mean you want conditions in the renderer? If so, then sure, you can have whatever conditions you want in the renderer.
Allan
Hi Allan
<?php
$columns_js_array = array();
foreach ($table_params['fields_array'] as $key => $value) {
$columns_js_array[]= array("data"=> $value['field']);
}
like:
<td>1 :: TRUE</td> (i added a pic above), this still confuse the editor update because i only want to pass the "1".
i saw this example online
https://datatables.net/examples/api/form.html
thanks
You would need to find some way of being able to define a Javascript rendering function from your PHP loop. Possibly just have the functions named in Javascript and have your PHP output the function names (i.e. the PHP would also need to know the Javascript function names).
Yup - you need to do the rendering client-side as I said above. If you embed the rendered value into the data, then editor won't be able to read the correct value.
Allan