[updated 24/11/2012] Dependent dropdown (library)
Posted 27 January 2013 - 06:57 AM
Posted 27 January 2013 - 20:04 PM
$this->load->library('gc_dependent_select');
$fields = array(
'activities_id' => array(
'table_name' => 'activities',
'title' => '{year} {description}',
'order_by'=> 'year DESC',
'relate' => null),
'groups_id' => array(
'table_name' => 'groups',
'title' => '{day} {hour} {description}',
'id_field' => 'id',
'relate' => 'activities_id',
'data-placeholder' => 'Επιλογή ΓκÏοÏÏ€ ΔÏaστηÏιοτήτων'
)
);
$config = array(
'main_table' => 'attendance',
'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);
Basically I am trying to set the order_by of field 'activities_id' like this 'order_by'=> 'year DESC'.
Is this possible to do it somehow?
Posted 27 January 2013 - 20:11 PM
Posted 27 January 2013 - 20:29 PM
Posted 27 January 2013 - 20:30 PM
Posted 04 February 2013 - 12:39 PM
I tried integrating you library , but its not working for me .This is my code, please tell me what i am doing wrong ?
function employees_management() { $crud = new grocery_CRUD(); $crud->set_table('employee'); $crud->set_relation('_DepartmentID','Department','Department'); $crud->set_relation('_JobTitleID','JobTitle','JobTitle'); $this->load->library('gc_dependent_select'); // settings $fields = array( // first field: 'Department' => array( // first dropdown name 'table_name' => 'Department', // table of department 'title' => 'Department', // department title 'relate' => null // the first dropdown hasn't a relation ), // second field 'JobTitle' => array( // second dropdown name 'table_name' => 'JobTitle', // table of JobTitle 'title' => 'JobTitle', // state job title 'id_field' => '__JobTitleID', // table of state: primary key 'relate' => '_DepartmentID', // table of job title: 'data-placeholder' => 'select job title' //dropdown's data-placeholder: ) ); $config = array( 'main_table' => 'Employee', 'main_table_primary' => '__EmployeeID', 'url' => base_url().'index.php/'.__CLASS__.'/'.__METHOD__.'/' , 'ajax_loader' => base_url('images/ajax-loader.gif') // path to ajax-loader image. ); $categories = new gc_dependent_select($crud, $fields, $config); // first method: $output = $categories->render(); // the second method: //$js = $categories->get_js(); $output = $crud->render(); $output->output.= $js; $this->_example_output($output); }
Posted 04 February 2013 - 12:51 PM
And what error do you get when you test it
Posted 04 February 2013 - 20:07 PM
vaibhav, did you solved your problem?
Posted 06 February 2013 - 16:31 PM
Hi victor,
Your library is great! I only write to say thank you for your work!
Thanks!!
Posted 13 February 2013 - 07:51 AM
My code is not working please help me. dependent model drop down is not displaying.I also attach databse table schema.
$crud = new grocery_CRUD();
$crud->set_table('item');
$crud->set_relation('brand_id', 'brands', 'name');
$crud->set_relation('model_id', 'models', 'name');
$this->load->library('gc_dependent_select');
// settings
$fields = array(
// first field:
'brand_id' => array( // first dropdown name
'table_name' => 'brands', // table of country
'title' => 'name', // country title
'relate' => null // the first dropdown hasn't a relation
),
// second field
'model_id' => array( // second dropdown name
'table_name' => 'models', // table of state
'title' => 'name', // state title
'id_field' => 'model_id', // table of state: primary key
'relate' => 'brand_id ', // table of state:
'data-placeholder' => 'select model' //dropdown's data-placeholder:
)
);
$config = array(
'main_table' =>'item',
'main_table_primary' => 'item_id',
'url'=>base_url().'index.php/'.__CLASS__.'/'.__METHOD__.'/'
//'ajax_loader' => base_url() . 'ajax-loader.gif' // path to ajax-loader image. It's an optional parameter
//'segment_name' =>'Your_segment_name' // It's an optional parameter. by default "get_items"
);
$categories = new gc_dependent_select($crud, $fields, $config);
// first method:
//$output = $categories->render();
// the second method:
$js = $categories->get_js();
$output = $crud->render();
$output->output.= $js;
$this->_example_output($output);
[attachment=466:brand.png]
Posted 13 February 2013 - 10:42 AM
Posted 13 February 2013 - 10:46 AM
I solve it myself.
Posted 13 February 2013 - 11:17 AM
I want to count models name with a particular brand. I am using this
$fields = array(
// first field:
'brand_id' => array( // first dropdown name
'table_name' => 'brands', // table of country
'title' => 'name', // country title
'relate' => null // the first dropdown hasn't a relation
),
// second field
'model_id' => array( // second dropdown name
'table_name' => 'models', // table of state
'title' => 'name', // state title
'id_field' => 'model_id', // table of state: primary key
'relate' => 'brand_id ', // table of state:
'data-placeholder' => 'select model' //dropdown's data-placeholder:
)
);
Posted 19 February 2013 - 07:29 AM
hai victor, i think its very usefull for my ci web.. but, i dont know how i integrate with grocerycrud in codeignitor..can u help me ?
Posted 19 February 2013 - 08:55 AM
Posted 27 February 2013 - 15:20 PM
Was looking for it. Thanks.
Posted 27 February 2013 - 18:34 PM
victor I am using for only 2 drop downs and it works but i get this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: property
Filename: libraries/gc_dependent_select.php
Line Number: 103
This library really rocks and helped me out a lot...thank you!
Posted 27 February 2013 - 18:38 PM
here is my code:
// ROOMS public function rooms() { //$lag = $this->db->select('rate_plans')->get_where('property', array('properties' => 'id'))->row(); $crud = new grocery_CRUD(); $crud->set_subject('Room'); $crud->set_table('rooms'); $crud->display_as('name','Room / Unit Name') ->display_as('room_desc','Description') ->display_as('number','Room / Unit Number') ->display_as('add_desc','Additional Details Window') ->display_as('bgcolor','Background Color') ->display_as('txtcolor','Text Color') ->display_as('alt_rate_plan','Alternate Rate Plan') ->display_as('slideshow','Show Additional Photos in Slideshow') ->display_as('max_occu','Max. Occupancy') ->display_as('type','Room Type'); $crud->columns('room_status', 'name', 'number', 'property','rate_plan', 'type','max_occu'); $crud->set_relation('property','properties','title'); $crud->set_relation('rate_plan','rate_plans','rate_name'); //$crud->set_relation('alt_rate_plan','rate_plans','rate_name'); $this->load->library('gc_dependent_select'); // create relational drop downs for property specific rate plans $fields = array( // first field: What Property is it? 'property' => array( // first dropdown name 'table_name' => 'properties', // table of property 'title' => 'title', // property title 'relate' => null // the first dropdown hasn't a relation ), // second field: Rate plan name gets populated based on field 1 selection 'rate_plan' => array( // second dropdown name 'table_name' => 'rate_plans', // table of rate plan 'title' => 'rate_name', // rate name column 'id_field' => 'id', // table rate_plans: primary key 'relate' => 'property', // table of state: 'data-placeholder' => 'Select Rate Plan' //dropdown's data-placeholder: ) ); $config = array( 'main_table' => 'properties', 'main_table_primary' => 'id', "url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', ); $categories = new gc_dependent_select($crud, $fields, $config); $js = $categories->get_js(); $crud->set_relation('type','room_types','type'); $crud->set_field_upload('photo','assets/uploads/files'); $crud->callback_add_field('room_status',array($this,'add_field_room_status')); $crud->callback_add_field('slideshow',array($this,'add_field_slideshow')); $crud->callback_add_field('room_desc',array($this,'add_field_room_desc')); $crud->callback_add_field('add_desc',array($this,'add_field_room_desc')); $crud->callback_edit_field('room_status',array($this,'edit_field_room_status')); $crud->callback_edit_field('room_desc',array($this,'edit_field_room_desc')); $crud->callback_edit_field('add_desc',array($this,'edit_field_room_desc')); $crud->callback_edit_field('slideshow',array($this,'edit_field_slideshow')); $output = $crud->render(); $output->output.= $js; $this->_rooms_output($output); } function add_field_room_status() { return 'Online (Show Internally) <input name="room_status" type="radio" value="Online" checked /> Offline (Hide Internally) <input name="room_status" type="radio" value="Offline" />'; } function add_field_slideshow() { return 'Yes <input name="status" type="radio" value="Yes" /> No <input name="status" type="radio" value="No" checked />'; } function edit_field_slideshow() { return 'Yes <input name="status" type="radio" value="Yes" /> No <input name="status" type="radio" value="No" checked />'; } function edit_field_room_status($value, $primary_key) { return 'Online (Show Internally) <input name="room_status" type="radio" value="Online" checked/> Offline (Hide Internally) <input name="room_status" type="radio" value="Offline" />'; } function add_field_room_desc() { return '<textarea name="room_desc" value="" ></textarea>'; } function edit_field_room_desc($value, $primary_key) { return '<textarea name="room_desc" value="'.$value.'" >' .$value. '</textarea>'; } function _rooms_output($output = null) { $this->load->view('properties.php',$output); } // END ROOMS
Posted 27 February 2013 - 19:34 PM
What version of the library did you download?
Posted 27 February 2013 - 19:39 PM
victor thank you for quick response. This library has saved me so much time...it is great!
version says in file v.1.2.0