[updated 24/11/2012] Dependent dropdown (library)
Posted 26 November 2012 - 09:26 AM
My controler is like this:
function programs_management()
{
$crud = new grocery_CRUD();
$crud->set_table('programs');
$crud->set_subject('program');
$crud->columns('program_id','country_id','channel_id','program_name','description','start_time','end_time','type_categ','type_id','logo_program');
$crud->display_as('country_id','Country')
->display_as('channel_id','Channel')
->display_as('program_name','Name program')
->display_as('logo_program','Base image/video')
->display_as('type_categ','Type category')
->display_as('type_id','Type program');
$crud->unset_columns('description');
$crud->fields('country_id','channel_id','program_name','logo_program','description','start_time','end_time','type_categ','type_id','status');
$crud->change_field_type('type_id', 'enum', array('Live','Reluare','Deleted'));
$crud->required_fields('country_id','channel_id','program_name','start_time','end_time','type_categ');
$crud->set_relation('country_id','countries','country_name');
$crud->set_relation('channel_id','channels','channel_name');
$crud->set_relation('type_categ','type_categ','type_categ');
$crud->set_field_upload('logo_program','assets/uploads/files');
$crud->add_action('Add images', base_url().'img/admin/icons/add_photo.png', '','ui-icon-image',array($this,'add_image_program'));
// settings
$config_view = array(
'table_name'=>'programs',
'related_table'=>'channels',
'sort_field'=>'channel_id',
'categories_primary_key'=>'channel_id',
'related_title_field'=>'channel_name',
'first_url' => base_url().__CLASS__.'/'.__FUNCTION__,
'segment_name' => 'channel',
'style' => 'height:24px; width: 200px;',
'text'=>array('all_rows'=>' All channels ')
);
$fields = array(
// first field:
'country_id' => array( // first dropdown name
'table_name' => 'countries', // table of country
'title' => 'country_name', // country title
'relate' => null // the first dropdown hasn't a relation
),
// second field
'channel_id' => array( // second dropdown name
'table_name' => 'channels', // table of channels
'title' => 'channel_name', // channel name
'id_field' => 'channel_id', // table of channels: primary key
'relate' => 'country_id', // table of country:
'data-placeholder' => 'select channel' //dropdown's data-placeholder:
)
);
$config = array(
'main_table' => 'programs',
'main_table_primary' => 'program_id',
"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/',
'ajax_loader' => base_url() . 'img/ajax-loader.gif' // path to ajax-loader image. It's an optional parameter
);
$categories_view = new grocery_crud_categories($crud,$config_view);
$dropdown = $categories_view->get_dropdown();
$categories = new gc_dependent_select(&$crud, $fields, $config);
// first method:
$output = $categories->render();
$output->output = $dropdown . $output->output;
// the second method:
//$js = $categories->get_js();
//$output = $crud->render();
//$output->output.= $js;
//$output = $crud->render();
$this->_admin_output($output);
}
For add:
[img]http://s9.postimage.org/q3oxdc73j/image.png[/img]
For edit:
[img]http://s11.postimage.org/7qntvsqc3/image.png[/img]
I declare this in function __construct()
$this->load->library('grocery_crud_categories');
$this->load->library('gc_dependent_select');
Posted 26 November 2012 - 09:59 AM
Posted 28 November 2012 - 21:56 PM
should be part of grocery crud, by default, very useful.
Posted 28 November 2012 - 23:27 PM
But this version of my library works perfectly for GC 1.3.3. I'll update the library when will be realized a stable version of the GC 1.4.
Posted 04 December 2012 - 19:08 PM
congratulations!
Posted 04 December 2012 - 19:10 PM
Posted 05 December 2012 - 13:17 PM
Posted 06 December 2012 - 10:27 AM
I have a situation where the very last select, which depends from the previous, needs to be multiselect and not a simple select.
On the documentation in order to make a multiselect you need to specify an array with the values that holds, but since this is done via the library, this cannot be done via php.
So we need somehow to change the last select to a multiselect, if it is not already, and load the correct values.
I can get the correct values from my model and output them as a json response.
Any ideas?
Thank you.
Posted 06 December 2012 - 10:49 AM
can you draw a scheme?
Posted 06 December 2012 - 11:03 AM
$this->load->library('gc_dependent_select');
$fields = array(
'activities_id' => array(
'table_name' => 'activities',
'title' => '{year} {description}',
'relate' => null),
'groups_id' => array(
'table_name' => 'groups',
'title' => '{day} {hour} {description}',
'id_field' => 'id',
'relate' => 'activities_id',
'data-placeholder' => 'some greek text '
)
);
$config = array(
'main_table' => 'payments',
'main_table_primary' => 'id',
'url' => base_url() . 'index.php/' . strtolower(__CLASS__) . '/' . strtolower(__FUNCTION__) . '/',
'ajax_loader' => base_url() . 'style/images/'. 'ajax-loader.gif'
);
$categories = new gc_dependent_select(&$this->grocery_crud, $fields, $config);
$js = $categories->get_js();
$output = $this->grocery_crud->render($data);
$output->output .= $js;
$this->_main_output($output);
Posted 06 December 2012 - 11:58 AM
Posted 06 December 2012 - 13:22 PM
Thank you for your help!
Posted 11 December 2012 - 00:42 AM
Posted 11 December 2012 - 07:24 AM
Posted 13 December 2012 - 10:15 AM
can you help me please ?
Posted 13 December 2012 - 11:00 AM
Posted 13 December 2012 - 11:06 AM
"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', 'myController . '/' . method_that_takes_me_to_the_administration_panel'
'myController . '/' .
[quote name='MarkusD' timestamp='1355396445' post='4695']
Hello,
I am in the process of implementing the library, and I think I have done alright until the end where I am not sure how I should write the path because I am not familiar with this syntax of __CLASS__ AND __FUNCTION__
as you describe it here:
"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', path to method
I have done this:
"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', 'myController'/'method_that_takes_me_to_the_administration_panel'
but I must be doing something really wrong because I get an error that says:
Message: Division by zero
Filename: controllers/my_controller.php
and I get 3 repeated times the display of my data to edit, add, delete, and if I click on the pencil or on add it is a mess, so definitively I am not writing the url right or I dont know ..
[/quote]
Posted 13 December 2012 - 19:53 PM
code runs fine in save process, but an error in the editing process,
can you help me please ?
[/quote]
When did you download the latest version of grocery crud?
May be it your problem /topic/1087-updated-24112012-dependent-dropdown-library/page__st__60#entry4441
Posted 13 December 2012 - 20:56 PM
[quote name='David Oster' timestamp='1354791799' post='4608']
I already use the gc_dependent_library like this. Will it work if I make use of the set_relation_n_n? I don't think so to be honest!
$this->load->library('gc_dependent_select');
$fields = array(
'activities_id' => array(
'table_name' => 'activities',
'title' => '{year} {description}',
'relate' => null),
'groups_id' => array(
'table_name' => 'groups',
'title' => '{day} {hour} {description}',
'id_field' => 'id',
'relate' => 'activities_id',
'data-placeholder' => 'some greek text '
)
);
$config = array(
'main_table' => 'payments',
'main_table_primary' => 'id',
'url' => base_url() . 'index.php/' . strtolower(__CLASS__) . '/' . strtolower(__FUNCTION__) . '/',
'ajax_loader' => base_url() . 'style/images/'. 'ajax-loader.gif'
);
$categories = new gc_dependent_select(&$this->grocery_crud, $fields, $config);
$js = $categories->get_js();
$output = $this->grocery_crud->render($data);
$output->output .= $js;
$this->_main_output($output);
[/quote]
Posted 13 December 2012 - 21:01 PM
David Oster, thanks for help . Is problem solved?
[/quote]
You welcome! No I haven't, not yet at least! It is a low priority problem!