Looking to create a conditional formatter/row action with jQuery Bootgrid. For example, if a certain value in the PHP data is set, then the formatter is shown, otherwise not. I can't find any documentation or previous stackoverflow questions that address this.
EDIT:
My current way of doing this in my controller is like this:
$actions = array(
'override' => array(
'icon' => 'flare red',
'link' => '/edit',
'perm' => 'Edit',
'title' => '...',
'condition_and' => array(
'status' => array(
'column' => 'status !=',
'value' => 'Suspended'
),
'registered' => array(
'column' => 'reg ==',
'value' => 'Yes'
)
),
'disabled_icon' => 'flare grey',
'disabled_title' => '...'
)
);
In the function that I then generate the grid, I interpret these settings when I loop through the data. The only part that is still hacky in my opinion is where I loop through the data using PHP, and then build up a JS string to match the condition:
if (!empty($vv['condition_and']))
{
$check_cond = '+(';
foreach ($vv['condition_and'] as $conk => $conv)
{
$check_cond .= '(row.' . $conv['column'] . ' ' . $conv['operator'] . ' "' . $conv['value'] . '") && ';
}
$check_cond = rtrim($check_cond, ' && ');
$out .= '"\
"' . $check_cond . ' ? "\
<a style=\"margin-right: 8px\" href=\"' . base_url() . $vv['link'] . '/" + row.id + "\"><i title=\"' . $vv['title'] . '\" class=\"zmdi zmdi-hc-lg zmdi-' . $vv['icon'] . '\"></i></a>" : "\
<i style=\"margin-right: 8px;\" title=\"' . $vv['disabled_title'] . '\" class=\"zmdi zmdi-hc-lg zmdi-' . $vv['disabled_icon'] . '\"></i>")+"\
" + ';
}
But if there is no clear way to do this better, I will just stick with that for now.