I know how to select some rows from a grid as indicated here: http://agiletoolkit.org/blog/how-to-select-elements-in-a-grid/
But I want to do the opposite, I want to have a grid, with selectable column, where I want to have checked the rows with certain ids from database, and then be able to unselect some or select a new one.
Is there a "prefered" method to do that in Agile Toolkit?
i'll make this short just to answer the question.
to preselect checkboxes on Grid Basic or MVC Grid, you just need to fill-in the values in the accompanying Form's selected
Form_Field, example:
class page_gridcheckboxestest extends Page {
function init() {
parent::init();
$g = $this->add('MVCGrid');
$g->setModel('Employees');
$f = $this->add('Form');
$f->addField('hidden','selected');
$preselect = array(1,2,3,4,5); // array of preselected ids
$f->getElement('selected')->set(json_encode($preselect));
$g->addSelectable($f->getElement('selected'));
}
}
the array of preselected ids has to be in JSON format for this to work.