Jump to content


Trying to implement the library for interdependent select lists


  • Please log in to reply
5 replies to this topic

#1 MarkusD

MarkusD

    Member

  • Members
  • PipPip
  • 15 posts

Posted 13 December 2012 - 03:48 PM

Hello,

I am trying to do just as it is written on the library, and I have an identical case, countries, states and cities and another table, so it should be straightforward, yet .. I am not coming on :wacko:

I have the 3 tables:

countries,

regions

towns



then I have another table called attributes which has, as foreign keys, the primary keys of each of these 3 tables, id_country, id_region, id_town

Then the names of the dropdowns are:

countries, for countries

regions, for regions

towns for cities

And also the tables for countries states and cites are interrelated the same way that it is shown in the library.

I have then the following code:

  $crud->set_relation('id_country', 'country', 'name_country'); 
  $crud->set_relation('id_region', 'regions', 'name_region');  
  $crud->set_relation('id_town', 'towns', 'name_town'); 
 
 
  $this->load->library('gc_dependent_select');
 
  
 
  $fields = array(
 
  // first field:
    'countries' => array( // first dropdown name
	  'table_name' => 'countries', // table of country
	  'title' => 'name_country', // country title
	  'relate' => null // the first dropdown hasn't a relation
    ),
 
    // second field
    'regions' => array( // second dropdown name
	  'table_name' => 'regions', // table of state
	  'title' => 'name_region', // state title
	  'id_field' => 'id_region', // table of state: primary key
	  'relate' => 'id_country', // table of state: id_pais es la foreign key de paises
	  'data-placeholder' => 'select state' //dropdown's data-placeholder:
   
    ),
   
   
    // third field. same settings
    'towns' => array(
	  'table_name' => 'towns',
	  'order_by'=>"name_town DESC",  // string. It's an optional parameter.
	  'title' => 'id: {id_town} / city : {name_town}',  // now you can use this format )))
	  'id_field' => 'id_town',
	  'relate' => 'id_region',
	  'data-placeholder' => 'select city'
    )
    );
 
 
 
  $config = array(
    'main_table' => 'atributes',
    'main_table_primary' => 'id_atribut',
    #"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', 'atributos_Copy'/'atributs_code'
    "url" =>base_url() . '__atributos_Copia__' .'/' .'__atributos_codigo__'. '/',
  );
 
 
  $categories = new gc_dependent_select($crud, $fields, $config);
 

  //$output = $categories->render();
 
  // the second method:
  $js = $categories->get_js();
 
  $output->output.= $js;
 

I am not sure if I have interpreted the sample correctly, but what happens is that when I click on the pencil for example to update the data, it takes 3 minutes to open the panel and the select lists are not interconnected, if I move one, the other doesnt notice, also the text editor is gone, there is no formatting headers etc, so the page is very much screwed, I dont know if I have to replace the "main_table" and "table_name" by the actual name of MY tables, but I did that and made no difference.

#2 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 13 December 2012 - 09:21 PM

Can you draw a scheme of your case?(tables structure)

#3 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 13 December 2012 - 09:29 PM

as I see you have controller name 'atributos_Copia', haven't you?

#4 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts
  • LocationMinsk

Posted 13 December 2012 - 09:33 PM

In your case : "url" =>base_url() . 'atributos_Copia' .'/' .'atributos_codigo'. '/',
In my example __CLASS__ - is class name.
You can read more info about this syntax here : http://php.net/manua....predefined.php

#5 MarkusD

MarkusD

    Member

  • Members
  • PipPip
  • 15 posts

Posted 14 December 2012 - 09:17 AM

Can you draw a scheme of your case?(tables structure)



#6 MarkusD

MarkusD

    Member

  • Members
  • PipPip
  • 15 posts

Posted 14 December 2012 - 09:29 AM

.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users