How can i render formatted field directly in server script
How can i render formatted field directly in server script
I have added a formatter for a field which is working perfectly fine(OL.dos). But when i am trying to format all my rows together the field "Ol.dos" return raw value i..e 1or 2. Is there a way to get the formatted value.
Thanks in advance.
Field::inst('OL.dos')
->getFormatter(function ($val, $data, $opts) {
if ($val === 1) {
return "Manual";
} else if ($val === 2) {
return "Auto";
}
}),
Field::inst('OL.comment', 'comment')
->getFormatter(function ($val, $data, $field) {
$details = [
['key' => 'U1.username', 'label' => 'Operator'],
['key' => 'OM.Mode', 'label' => 'Mode'],
['key' => 'OL.dos', 'label' => 'Door Operations Switch'],
['key' => 'Y4.yesNo', 'label' => 'Are you Properly Berthed?'],
['key' => 'OL.qfmID', 'label' => 'QFM #'],
['key' => 'U4.username', 'label' => 'Other Operators']
];
$comment = $val; // Starting with the original comment value
$commentReturn = '';
foreach ($details as $detail) {
if (isset ($data[$detail['key']]) && !empty ($data[$detail['key']])) {
$value = $data[$detail['key']];
$label = $detail['label'];
$commentReturn .= '<br><div class="data-detail col">[' . $label . ': ' . $value . ']</div>';
}
}
$commentReturn = $comment . '<br><div class="row">' . $commentReturn . '</div>';
return '<div class="comment-details">' . $commentReturn . '</div>';
}),
Answers
I'm not sure what you mean by formatting all of the rows together? What you have looks like
OL.dos
should beManual
orAuto
when it hits the client-side. Is that not happening?Allan
Yes, in my cllient side it is giving me 1 or 2 instead of manual or auto .Below is a picture attached.
Can you give me a link to the page so I can take a bit more of a look please? The full PHP being used for that controller would be useful to.
Thanks,
Allan
Sure, here is the link and the code(I have removed extra piece of code: "https://stagingc.assettrack.cx/operations/DailyLog.php"
Looks like it needs a login. You can PM it to me by clicking my forum user name and then "Send message".
Allan