2

What I'm trying to do is this:

enter image description here

But failing at it. The codes I've tried using are:

<td class="nowrap center">
    <div class="btn-group">
        <?php echo JHtml::_('jgrid.published', $row->state, $i, 'records.', true, 'cb'); ?>
        <?php echo JHtml::_('jgrid.published', ((int) $row->state === 2 ? 1 : 2), $i, 'records.', true, true, 'cb'); ?>
        <?php echo JHtml::_('jgrid.published', ((int) $row->state === -2 ? 1 : -2), $i, 'records.', true, true, 'cb'); ?>
    </div>
</td>

and also an attempt at:

<td class="nowrap center">
    <div class="btn-group">
        <?php echo JHtml::_('jgrid.published', $row->state, $i, 'records.', true, 'cb'); ?>
        <?php echo JHtml::_('jgrid.state', JHtml::_('grid.publishedOptions'), ((int) $row->state === 2 ? 1 : 2), $i, 'records.', true, true, 'cb'); ?>
        <?php echo JHtml::_('jgrid.state', JHtml::_('grid.publishedOptions'), ((int) $row->state === -2 ? 1 : -2), $i, 'records.', true, true, 'cb'); ?>
    </div>
</td>

1 Answer 1

2

Had to look into this again and I seem to have found a solution.

Just like the publish button rendered using jgrid.published in the example below:

<?php echo JHtml::_('jgrid.published', $row->state, $i, 'myitems.', true, 'cb', $row->publish_up, $row->publish_down); ?>

Use the more general purpose jgrid.action render instead, which is defined in the joomla library as:

public static function action($i, $task, $prefix = '', $text = '', $active_title = '', $inactive_title = '', $tip = false, $active_class = '',
    $inactive_class = '', $enabled = true, $translate = true, $checkbox = 'cb')

Although unlike jgrid.published, this renderer creates buttons with a singular fixed task. It isn't state-aware, i.e. it cannot automatically assign a task based on the current state. But one could always mimic that behaviour by using an if-else code-wrapper to control which buttons to show.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.