Magento – Magento 1.9.2 – how to set checkbox in admin grid checked by default

checkboxgridmagento-1.9

Is there any way to make all checkboxes checked in particular column in admin grid.

I want checkboxes checked by default in "skip" column.
Here is a code for this column:

protected function _prepareColumns()
{
    parent::_prepareColumns();

    $this->addColumn('skip', array(
        'header'     => Mage::helper('importexport')->__('Skip'),
        'type'       => 'checkbox',
        'name'       => 'skip',
        'field_name' => Mage_ImportExport_Model_Export::FILTER_ELEMENT_SKIP . '[]',
        'filter'     => false,
        'sortable'   => false,
        'align'      => 'center',
        'index'      => 'attribute_id'
    ));

   //other columns here

    if ($this->hasOperation()) {
        $operation = $this->getOperation();
        $skipAttr = $operation->getSkipAttr();
        if ($skipAttr) {
            $this->getColumn('skip')
                ->setData('values', $skipAttr);
        }
        $filter = $operation->getExportFilter();
        if ($filter) {
            $this->getColumn('filter')
                ->setData('values', $filter);
        }
    }

    return $this;
}

Best Answer

Try This

$this->addColumn('skip', array(
        'header'     => Mage::helper('importexport')->__('Skip'),
        'type'       => 'checkbox',
        'name'       => 'skip',
        'field_name' => Mage_ImportExport_Model_Export::FILTER_ELEMENT_SKIP . '[]',
        'filter'     => false,
        'sortable'   => false,
        'align'      => 'center',
        'index'      => 'attribute_id',
        'values'      => array(1,2) // add your values here
));

just add key 'values' => array(1,2) // your values

If you want default checked value for all you need to pass all value in array or make new Grid Column Renderer