⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Grocery Crud dependent dropdown



rim
  • profile picture
  • Member

Posted 21 November 2019 - 07:03 AM

 
I am not able to implement dependent drop down in grocery crud.
 
$this->load->library('gc_dependent_select');

 

public function index()
{
// echo GroceryCrud::VERSION;die;
$crud = generate_crud('');
$crud->set_table('routes');
$crud->display_as('category_id','Category'); 
$crud->display_as('subcategory_id','Subcategory'); 
$crud->set_rules('category_id', 'Category','required');  
$crud->set_relation('category_id','categories','{category}');
$crud->set_relation('subcategory_id','subcategories','{subcategory}');
/////////////////////////////////////////////
$fields = array(
// first field:
'category_id' => array( // first dropdown name
'table_name' => 'categories', // table of country
'title' => 'category', // country title
'relate' => null // the first dropdown hasn't a relation
),
// second field
'subcategory_id' => array( // second dropdown name
'table_name' => 'subcategories', // table of state
'title' => 'subcategory', // state title
'id_field' => 'id', // table of state: primary key
'relate' => 'category_id', // table of state:
'data-placeholder' => 'Select Subcategory' //dropdown's data-placeholder:
),
);
 
$config = array(
'main_table' => 'routes',
'main_table_primary' => 'id',
"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/',
);
$categories = new gc_dependent_select($crud, $fields, $config);
$js = $categories->get_js();
$output = $crud->render();
$output->output.= $js;
$this->_example_output($output);
/////////////////////////////////////////////
// $this->mTitle = "Routes";
// $this->mViewFile = '_partial/crud';
// $this->mViewData['crud_data'] = $crud->render();
}