I love grocery crud but drop downs are driving me crazy.
From the documentation I understand that I need to use set_relation.
I have reference table called Sub district consisting of
SUB_DISTRICT_ID
SUB_DISTRICT_NAME
ACTIVE
Then I have another table called data status consisting of
DATA_DISPLAY_ID
DATA_DISPLAYNAME
This table basiscally holds 2 rows
Active
Inactive
in the data_displayname column.
When users are adding subdistricts I need them to mark whether it is active or inactive by selecting the correct status from a dropdown
code:
$this->grocery_crud->callback_edit_field('active',array($this,'_call_back_dstatus'));
$this->grocery_crud->callback_add_field('active',array($this,'_call_back_dstatus'));
$this->grocery_crud->display_as('active','Data Status');
$this->grocery_crud->set_relation('active','data_display','data_displayname');
function _call_back_dstatus()
{
$data = $this->getYou('data_display','data_display_id, data_displayname',''); // iam using session here
$hasil ='<select name="active">';
foreach($data as $x)
{
$hasil .='<option value="'.$x->data_display_id.'">'.$x->data_displayname.'</option>';
}
return $hasil.'</select>';
}
function getYou($tabel,$field = '*', $cond ='')
{
$this->db->select($field);
$this->db->from($tabel);
if(!empty($cond)) $this->db->where($cond);
return $this->db->get()->result();
}
Nothing shows up not even the Display as text.
I know the code is being called, if I change a function name etc, it fails.
Any ideas about what I am doing wrong?
Drop downs
Started by Riyaad Salasa, 06 August 2012 - 10:39 AM
- Single Page
Posted 06 August 2012 - 10:39 AM