Jump to content


[updated 24/11/2012] Dependent dropdown (library)

Dependent dropdown categories ajax dropdown Categories and sub-categories

  • Please log in to reply
347 replies to this topic

#301 Sebastián

Sebastián

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 21 July 2015 - 02:40 PM

Hi! This is just URL to function where you are using this dependent dropdown library, no more!

Sorry buy I don't undestand.
If every time I chose an item for the first dropdown, it try to load the 'url'=>base_url().'index.php/'.__CLASS__.'/'.__METHOD__.'/'

getting the values for the second dropdown, BUT what's the code for that METHOD?
just an html output like <option value="1">Same value</option> or what?

 



#302 Cindy Lorena

Cindy Lorena

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 10 August 2015 - 08:34 PM

hello as I can do because I only load dependent lists the first table.



#303 Cindy Lorena

Cindy Lorena

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 11 August 2015 - 04:15 PM

for difficult cases use KaBaDaBrA's code.
Maybe in the next version I'll try make this functionality.

hello victor could make an example of crud grocery master detail



#304 geekygirl

geekygirl

    Member

  • Members
  • PipPip
  • 15 posts

Posted 22 September 2015 - 09:37 PM

Is this plugin compatible with GC 1.5.2 and does it still work?



#305 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 25 September 2015 - 12:16 PM

Is this plugin compatible with GC 1.5.2 and does it still work?

I did not check that.



#306 Prince Hector

Prince Hector

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 18 November 2015 - 05:33 AM

I have a product Table , there is category and sub category field. So I want to change sub categiries depends on category . So I write the code below

 

$fields = array(
                'Sub_Categry' => array(
                'table_name' => 'sub_category',
                'title' => 'Sub Category',
                'id_field' => 'sub_cat_id',
                'relate' => 'category_id',
                'data-placeholder' => 'select Sub category'

                )
            );

 

$config = array(
                'main_table' => 'category',
                'main_table_primary' => 'category_id',
                "url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/',
                'ajax_loader' => base_url() . 'ajax-loader.gif',
                'segment_name' =>'Your_segment_name'
            );

 

$categories2 = new gc_dependent_select($crud, $fields, $config);
            $js2 = $categories2->get_js();

            $output = $crud->render();
            $output->output.= $js2;

            $this->_example_output($output);

 

 

But it didnt work. Where did I wrong ? Can any one help me plzzz ??

Attached Thumbnails

  • rrrr.PNG


#307 Prince Hector

Prince Hector

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 18 November 2015 - 05:35 AM

I have a product Table , there is category and sub category field. So I want to change sub categiries depends on category . So I write the code below

 

$fields = array(
                'Sub_Categry' => array(
                'table_name' => 'sub_category',
                'title' => 'Sub Category',
                'id_field' => 'sub_cat_id',
                'relate' => 'category_id',
                'data-placeholder' => 'select Sub category'

                )
            );

 

$config = array(
                'main_table' => 'category',
                'main_table_primary' => 'category_id',
                "url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/',
                'ajax_loader' => base_url() . 'ajax-loader.gif',
                'segment_name' =>'Your_segment_name'
            );

 

$categories2 = new gc_dependent_select($crud, $fields, $config);
            $js2 = $categories2->get_js();

            $output = $crud->render();
            $output->output.= $js2;

            $this->_example_output($output);

 

 

But it didnt work. Where did I wrong ? Can any one help me plzzz ??



#308 ljegou

ljegou

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 20 February 2016 - 03:39 PM

Too bad this useful library doesn't work with current GC version :-(



#309 Mohamed Abukhatwa

Mohamed Abukhatwa

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 03 March 2016 - 11:37 PM

Thank you for the Library but mr.grocery CRUD Hero wouldn't work when i tested it. once i select the country dropdown the state and the city dropdown never show up.

P.S i used ot



#310 mohdzaid

mohdzaid

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 28 April 2016 - 09:15 PM

Hi Victor, whats your recommendation if I need to filter few records for the first dropdown. I have an existing table with over 10K records.

 

 

Table structure.

 

Vendor Master:

Id, name, type (enum), blah1, blah2, blah3

 

The third field "type" has 4 different values (Cement Supplier, Bricks Supplier, another type1, another type2)

 

for some reason I need to show the records type = Cement Supplier in the first dropdown.

 

Is there any workaround / approach to achieve this.

 

 

 

Thanks,

Mohammad



#311 pramin100

pramin100

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 12 May 2016 - 06:17 AM

Dear Victor,

 

Thank for wonder work. But in my case, it is working in localhost but when i upload in live server it is not working. Please help.

 

Pramin

 



#312 Neeraj Singh

Neeraj Singh

    Newbie

  • Members
  • Pip
  • 4 posts
  • LocationMumbai

Posted 31 May 2016 - 08:42 PM

Hi Victor,

 

 

Thanks for this useful library. But, the Dependent Drop-down not working with latest GC 'assets'. I have tried this with old version 'assets' and new version 'assets'. I am using latest GC models (Grocery_crud_model.php: 1.5.4) and library (Grocery_CRUD.php: 1.5.4) in both (CI latest CodeIgniter 3.0.6).

 

Here is result:

 

GC 1.5.4 and latest 'assets' has working ajax and getting data properly but not populating drop-down. The select box still lock after getting ajax data.

Error_First.png

 

GC 1.5.4 and old 'assets' has working ajax and getting data properly and populating in drop-down, working fine

 

Working_Fine.png

 

 

Will you plz help me to fix this problem, I am stuck in a project. Your help would be much appreciated Victor :)

 

Download Code for test: https://drive.google...dDlCRGhNMjZuY00

 

-Best

Neeraj Singh



#313 Php Power Arts

Php Power Arts

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 04 June 2016 - 06:04 PM

you are genius , thanks for this great lib :) , better to making it on github and add more simple examples 



#314 Php Power Arts

Php Power Arts

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 05 June 2016 - 11:58 AM

 

Please help , its not work for me this is my code , i just find the second dropdown menu disabled and not changed any idea ?

 


function index()
    {
        $this->load->library('grocery_CRUD');
        if (!$this->ion_auth->logged_in()) {
            // redirect them to the login page
            redirect('user/login', 'refresh');
        } else {


            $crud = new Grocery_CRUD();
            $crud->set_table('venues');
            $crud->set_subject(' ');
            $crud->unset_delete();
            //$crud->unset_jquery();
            $crud->unset_bootstrap();
            $crud->unset_export();
            $crud->unset_print();
            $crud->unset_read();
            $crud->unset_list();
            $crud->unset_back_to_list();
            $crud->unset_fields('v_started_date', 'v_end_date', 'v_active', 'user_id', 'v_event_counter');
            $crud->unset_edit_fields('v_started_date', 'v_end_date', 'v_active', 'user_id', 'v_event_counter', 'v_accept_agreement');
            $crud->display_as('v_name', __('Venue Name'))
                ->display_as('region_id', __('Region'))
                ->display_as('location_id', __('Location'))
                ->display_as('v_logo', __('Venue Logo'))
                ->display_as('v_address_1', __('Address 1'))
                ->display_as('v_address_2', __('Address 2'))
                ->display_as('v_city', __('City'))
                ->display_as('v_phone_number', __('Phone Number'))
                ->display_as('v_accept_agreement', '');

            // fields type
            $crud->set_field_upload('v_logo', 'assets/uploads/files');
            $crud->set_relation('region_id', 'regions', 'country');
            $crud->set_relation('location_id', 'locations', 'location');

            // dependent dropDown menu
            $this->load->library('gc_dependent_select');

            $fields = array(
                            // first field:
                            'region_id' => array( // first dropdown name //
                             'title' => 'country', //
                             'relate' => null // the first dropdown hasn't a relation
                            ),
                            // second field
                            'location_id' => array( // first dropdown name
                                'table_name' => 'locations',
                                'title' => 'location',
                                'id_field' => 'location_id',
                                'relate' => 'region_id',
                                'data-placeholder' => 'Select Location'
                            ));

            $config = array(
                'main_table' => 'regions',
                'main_table_primary' => 'region_id',
                "url" => base_url() .__CLASS__ . '/' . __FUNCTION__ . '/',
                'ajax_loader' => '',
                '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:


            // callback function
            $crud->callback_add_field('v_accept_agreement', array($this, 'add_field_v_accept_agreement'));
            $crud->callback_after_insert(array($this, 'insert_start_date_after_insert'));

            // validation fields
            $crud->required_fields('v_name', 'v_accept_agreement');
            $crud->set_rules('v_accept_agreement', '', 'callback_required_field_v_accept_agreement_msg');

            // elements change text
            $crud->set_lang_string('form_save', __('Subscribe Now'));
            $crud->set_lang_string('insert_success_message',
                ' Your data has been successfully stored into the database.
                <br/>
                 Please wait while you are redirecting to the list page.
                 <script type="text/javascript">
                  window.location = "' . site_url() . '";
                 </script>'
            );

            $js = $categories->get_js();
            $output = $crud->render();
            $output->output .= $js;
            $this->load->vars($output);
            $this->layout->render_page('venue/index');

        }
    }


#315 Php Power Arts

Php Power Arts

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 07 June 2016 - 07:13 AM

Hi Victor,

 

 

Thanks for this useful library. But, the Dependent Drop-down not working with latest GC 'assets'. I have tried this with old version 'assets' and new version 'assets'. I am using latest GC models (Grocery_crud_model.php: 1.5.4) and library (Grocery_CRUD.php: 1.5.4) in both (CI latest CodeIgniter 3.0.6).

 

Here is result:

 

GC 1.5.4 and latest 'assets' has working ajax and getting data properly but not populating drop-down. The select box still lock after getting ajax data.

Error_First.png

 

GC 1.5.4 and old 'assets' has working ajax and getting data properly and populating in drop-down, working fine

 

Working_Fine.png

 

 

Will you plz help me to fix this problem, I am stuck in a project. Your help would be much appreciated Victor :)

 

Download Code for test: https://drive.google...dDlCRGhNMjZuY00

 

-Best

Neeraj Singh

i have the same issue like Neeraj



#316 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 10 June 2016 - 07:24 AM

Hello! The problems are because of the library has been done a few years ago. This weekend I will try to update the library to current GC version.



#317 michael

michael

    Newbie

  • Members
  • Pip
  • 1 posts
  • LocationZurich, Switzerland

Posted 10 June 2016 - 08:46 AM

Hello! The problems are because of the library has been done a few years ago. This weekend I will try to update the library to current GC version.

 

Dear Victor, nice to read that you take time for an update. I would be very happy if this great library would work with the current GC version. Thank you very much for your efforts.



#318 Luca Chiaravalloti

Luca Chiaravalloti

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 22 June 2016 - 01:59 PM

I found the solution. It's very simple, it's only need to replace the string "liszt" with "chosen" into the library.

May be that the new version of Chosen library doesn't support anymore the liszt event.

I have attached the corrected Library.

Attached Files



#319 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 29 June 2016 - 04:55 PM

I found the solution. It's very simple, it's only need to replace the string "liszt" with "chosen" into the library.

May be that the new version of Chosen library doesn't support anymore the liszt event.

I have attached the corrected Library.

Yes. I've fixed that and made refactoring a bit. You can download the fresh version at the first page of the topic



#320 Koia

Koia

    Member

  • Members
  • PipPip
  • 10 posts

Posted 19 July 2016 - 07:36 AM

Can someone help me with getting the Dependent dropdown library working with the "Goods" test code as in
http://www.grocerycr...opdown-library/.

I use Codeigniter 3 with HMVC from https://github.com/jlamim/ci3-hmvc, grocery-crud-1.5.4, Gc_dependent_select 1.5 and I have $config['index_page'] = 'index.php';

The drop down selection works only for Country but nothing happens when i click on state and city.

When I click on edit in a grocery crud http://.....hudev1/i...hem/goods/goods I get following error.

 

Error Number: 1054

Unknown column 'post_code' in 'where clause'

SELECT * FROM `dd_city` WHERE `state_ids` = '1' AND post_code>'167' ORDER BY `state_title` DESC

Filename: modules/grocery_crud/libraries/Gc_dependent_select.php

Line Number: 147


Similar problem was reported in
http://www.grocerycr...-library/page-6
response #120. I implemented proposed changes as in #121 but the problem remains.

Thanks in advance, Ingmar

My code and database is as follows:

    public function goods() {

        $crud = new grocery_CRUD();
        $crud->set_table('dd_goods');
        $crud->set_relation('goods_country', 'dd_country', 'country_title');
        $crud->set_relation('goods_state', 'dd_state', 'state_title');
        $crud->set_relation('goods_city', 'dd_city', 'city_title');

        $this->load->library('gc_dependent_select');
// settings

        $fields = array(
// first field:
            'goods_country' => array(// first dropdown name
                'table_name' => 'dd_country', // table of country
                'title' => 'country_title', // country title
                'relate' => null // the first dropdown hasn't a relation
            ),
// second field
            'goods_state' => array(// second dropdown name
                'table_name' => 'dd_state', // table of state
                'title' => 'state_title', // state title
                'id_field' => 'state_id', // table of state: primary key
                'relate' => 'country_ids', // table of state:
                'data-placeholder' => 'select state' //dropdown's data-placeholder:
            ),
// third field. same settings
            'goods_city' => array(
                'table_name' => 'dd_city',
                'where' => "post_code>'167'", // string. It's an optional parameter.
                'order_by' => "state_title DESC", // string. It's an optional parameter.
                'title' => 'id: {city_id} / city : {city_title}', // now you can use this format )))
                'id_field' => 'city_id',
                'relate' => 'state_ids',
                'data-placeholder' => 'select city'
            )
        );

        $config = array(
        'main_table' => 'dd_goods',
        'main_table_primary' => 'goods_id',
        'url' => base_url() . 'index.php/' . strtolower(__CLASS__) . '/' . strtolower(__FUNCTION__) . '/',
        'ajax_loader' => base_url() . 'style/images/'. 'ajax-loader.gif',
        '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);
    }
   

}
/*

CREATE TABLE IF NOT EXISTS `dd_country` (
  `country_id` int(15) NOT NULL,
  `country_title` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`country_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `dd_state` (
  `state_id` int(15) NOT NULL,
  `state_title` varchar(255) DEFAULT NULL,
  `country_ids` int(15) NOT NULL,
  PRIMARY KEY (`state_id`),
  KEY `country_ids` (`country_ids`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `dd_city` (
  `city_id` int(15) NOT NULL,
  `city_title` varchar(255) DEFAULT NULL,
  `state_ids` int(15) NOT NULL,
  PRIMARY KEY (`city_id`),
  KEY `state_ids` (`state_ids`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `dd_goods` (
  `goods_id` int(11) NOT NULL,
  `goods_name` varchar(255) DEFAULT NULL,
  `goods_country` int(11) NOT NULL,
  `goods_state` int(11) NOT NULL,
  `goods_city` int(11) NOT NULL,
  PRIMARY KEY (`goods_id`),
  KEY `goods_country` (`goods_country`),
  KEY `goods_state` (`goods_state`),
  KEY `goods_city` (`goods_city`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 */

 







Also tagged with one or more of these keywords: Dependent dropdown, categories, ajax, dropdown, Categories and sub-categories

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users