how can I add a custom dropdown with GroceryCrud? I have the following mysql table:
CREATE TABLE IF NOT EXISTS `clients` (
`clientId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`clientName` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`cif` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`address` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
`type` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`clientId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
And the following code to show the functionality:
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('clients');
$crud->set_subject($this->lang->line('tpv_clients'));
$crud->display_as('clientName', $this->lang->line('tpv_client_name'));
$crud->display_as('cif', $this->lang->line('tpv_client_cif'));
$crud->display_as('address', $this->lang->line('tpv_client_address'));
$crud->display_as('type', $this->lang->line('tpv_client_type'));
$crud->columns('clientName','address','type');
$crud->required_fields('clientName', 'cif', 'type');
$output = $crud->render();
The field "type" should be only contain two values: "A" or "B". I need a dropdown combo with these two values. I have tried this code
$crud->field_type('type','dropdown',array('1' => 'A', '2' => 'B'));
but it doesn't work.
I think you just need this:
$crud->field_type('type','dropdown',array('A' => 'A', 'B' => 'B'));
For more about the field_type method, you can check: http://www.grocerycrud.com/documentation/options_functions/field_type