2

I am trying to add class attribute in the checkboxes.

https://docs.joomla.org/API15:JHTMLGrid/id

I read the documentation but no luck today :(

Please check the image (Thats just an example) enter image description here

So my question is, can we add class attribute in JHtml::_('grid.id', $i, $item->id); ??

Is there any way to do this without hacking core

Thanks in advance.

1 Answer 1

4

First of all, this documentation is very old. Latest is here.

You can't just add class to that. You would have to create your own JHtml* class and override it there. Following is just example, you can rename class and file names if you prefer.

components/your_component/html/mygrid.php

abstract class JHtmlMygrid
{
    public static function id($rowNum, $recId, $class = null, $checkedOut = false, $name = 'cid', $stub = 'cb')
    {
        return $checkedOut ? '' : '<input type="checkbox" id="' . $stub . $rowNum . '"'.(is_string($class) ? ' class="'.$class.'"' : '').' name="' . $name . '[]" value="' . $recId
            . '" onclick="Joomla.isChecked(this.checked);" />';
    }
}

Then in your view template, for example myview/tmpl/default.php, add your class to JHtml include paths.

JHtml::addIncludePath(JPATH_COMPONENT.'/html');

Note: you could add this code to your component main file, then you will be able to use it in every view without repeating this line.

And finaly call it in your template file.

JHtml::_('mygrid.id', $i, $item->id, 'class-name');

Then Joomla! will automatically call your JHtmlMygrid class method id.

1
  • 1
    It worked!!! :) I have learnt something new today. Thank you @Rene
    – Joomler
    Mar 10, 2016 at 4:59

Your Answer

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

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