⚠ 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

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



victor

victor
  • profile picture
  • Member

Posted 18 December 2012 - 10:07 AM

sorry, show "url". I think you have the same problem wich had MarkusD. you can find solution on this page

kenshicu

kenshicu
  • profile picture
  • Member

Posted 18 December 2012 - 14:47 PM

Hi, I had to modify my tables relations to work your library, as I can make it work with set_relation_n_n relationships?
before ([background=rgb(255, 255, 255)]that's how I had to put it to work are the relationships set_relation_n_n[/background])
[img]http://s12.postimage.org/dfpgiz6jx/trabajadores_before.jpg[/img]
after ?
[img]http://s13.postimage.org/sa96mdy53/trabajadores_after.jpg[/img]
regards

victor

victor
  • profile picture
  • Member

Posted 18 December 2012 - 19:33 PM

Why do you don't like the first method?
Do you don't like consejo_popular field on the page?

victor

victor
  • profile picture
  • Member

Posted 18 December 2012 - 19:56 PM

deleted

kenshicu

kenshicu
  • profile picture
  • Member

Posted 18 December 2012 - 22:46 PM

because the database is not normalized, and id_provincia, id_municipio fields are repeated, and would in the controller of table Trabajador, build relationships set_relation_n_n and not the 3 set_relation that I have.

[background=rgb(255, 255, 255)]in short, is to see if the library can work with relationships set_relation_n_n [/background]
[background=rgb(255, 255, 255)]greetings and thanks for replying[/background]

victor

victor
  • profile picture
  • Member

Posted 19 December 2012 - 10:53 AM

The library doesn't supports your structure.

kenshicu

kenshicu
  • profile picture
  • Member

Posted 19 December 2012 - 14:06 PM

ok, thanks anyway

tlc033

tlc033
  • profile picture
  • Member

Posted 26 December 2012 - 10:38 AM

Hi. Can i get this library to work with a structure like this:
[b] [size=4]Storing Hierarchical Data in a Database[/size][/b]

[img]http://s13.postimage.org/m6k9gfbzb/sitepoint_tree.gif[/img] [img]http://sitepointstatic.com/graphics/table01.gif[/img]
THX.

dblanco

dblanco
  • profile picture
  • Member

Posted 27 December 2012 - 21:54 PM

Victor: As would be a standard view?

I'm not clear that these method return.
$js = $categories->get_js();

And because they are concatenated:

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

I'll be testing the library to post comments.

Thanks

dblanco

dblanco
  • profile picture
  • Member

Posted 27 December 2012 - 23:04 PM

I have a question about the methods called to configure like this:

$config = array(
'main_table' => 'comercios',
'main_table_primary' => 'id_comercio',
"url" => base_url() . '/admin/'.__CLASS__ . '/' . __FUNCTION__ . '/',
'ajax_loader' => base_url().PATH_IMG.'/admin/ajax-loader.gif', // path to ajax image.
);

When selecting a value in the first select, then attempts to call:
http://localhost//admin/Comercios/grilla/get_items/id_subcategoria/2

The method get_items, what should be returned? An example? thanks

dblanco

dblanco
  • profile picture
  • Member

Posted 28 December 2012 - 00:32 AM

Ignore my last message, just missing add index.php:

"url" => base_url (). 'index.php/admin /'. __class__. '/'. __FUNCTION__. '/',

Very useful the library. Thanks

victor

victor
  • profile picture
  • Member

Posted 28 December 2012 - 13:27 PM

[quote name='dblanco' timestamp='1356645278' post='4909']
Victor: As would be a standard view?

I'm not clear that these method return.
$js = $categories->get_js();

And because they are concatenated:

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

I'll be testing the library to post comments.

Thanks
[/quote]
This method return Javascript

davidoster

davidoster
  • profile picture
  • Member

Posted 03 January 2013 - 12:02 PM

Hello everybody! Happy New year to all of us and I hope we all have a happy coding year!
Victor, I was trying to use a callback_column and I might have found a drawback of your library.
I used in a grid view(using datatables) that has dependent fields, a callback column but on a field that is [b]not related[/b] at all with dependent dropdowns,

e.g.


$this->grocery_crud->columns('customers_id','activities_id','groups_id','date','description','date_inserted');
$this->grocery_crud->callback_column('customers_id',array($this,'_callback_attend_edit_url'));
$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' => 'Επιλογή Γκρούπ Δρaστηριοτήτων'
)
);


As you can see, I try to put a callback on customers_id which isn't one of the two fields that I am using for dependent dropdowns(activities_id,groups_id).
Try it, I am afraid we cannot use at all a callback column anywhere else when your library is used!

Just for the sake of testing I tried the exact same code on a view that doesn't use the dependent dropdowns library and is working perfectly!
Any ideas?

victor

victor
  • profile picture
  • Member

Posted 03 January 2013 - 12:12 PM

send me a private message with your controller and the database dump

davidoster

davidoster
  • profile picture
  • Member

Posted 03 January 2013 - 12:14 PM

OK

victor

victor
  • profile picture
  • Member

Posted 03 January 2013 - 13:01 PM

As I see we can't use the callback_column when we use the set_relation for these columns.
in your case :
$this->grocery_crud->set_relation('customers_id','customers','{lname} {fname}'); 

and
 $this->grocery_crud->callback_column('customers_id',array($this,'_callback_attend_edit_url'));

davidoster

davidoster
  • profile picture
  • Member

Posted 03 January 2013 - 13:13 PM

Possibly a bug or something that the core developer hasn't mentioned on the documentation!
It had nothing to do with your library after all!
Thank you very much for your help!

davidoster

davidoster
  • profile picture
  • Member

Posted 04 January 2013 - 03:53 AM

[quote name='David Oster' timestamp='1357218790' post='4960']
Possibly a bug or something that the core developer hasn't mentioned on the documentation!
It had nothing to do with your library after all!
Thank you very much for your help!
[/quote]
[quote name='victor' timestamp='1357218102' post='4959']
As I see we can't use the callback_column when we use the set_relation for these columns.
in your case :
$this->grocery_crud->set_relation('customers_id','customers','{lname} {fname}'); 

and
 $this->grocery_crud->callback_column('customers_id',array($this,'_callback_attend_edit_url'));

[/quote]

Shame on me!!! I didn't search for similar issues before posting an issue!
Solution for the problem mentioned before is here: /topic/254-set-relation-breaks-processing-of-field-with-same-name-returned/#entry982

mirr0r

mirr0r
  • profile picture
  • Member

Posted 07 January 2013 - 12:21 PM

hi,
I test your library and I m not able to work.

my controller is copy&past from your first post, just changed this string:


"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', path to method



in


"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/'


and deleted optional:


'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"


So this is:


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() . __CLASS__ . '/' . __FUNCTION__ . '/'

);
$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);

}


table in database is your table "dd_goods", "dd_country", "dd_state" and "dd_city" with sample data.

[sharedmedia=core:attachments:420]
[sharedmedia=core:attachments:421]
[sharedmedia=core:attachments:422]

[sharedmedia=core:attachments:424]


List with relation works ok:

[sharedmedia=core:attachments:425]

but I m not able to add record with dependent dropdown, first choice is ok but I can't choose second list:

[sharedmedia=core:attachments:426]

Can u help me?

Thanks

Michele

davidoster

davidoster
  • profile picture
  • Member

Posted 07 January 2013 - 12:33 PM

mirror, make sure your url is the right one. For example if you have index.php on the address bar then you need to include it also at the "url" like this,


$config = array(
'main_table' => '[color=#008800][size=2][background=rgb(248, 248, 248)]dd_goods[/background][/size][/color]',
'main_table_primary' => '[color=#008800][size=2][background=rgb(248, 248, 248)]goods_id[/background][/size][/color]',
'url' => base_url() . 'index.php/' . strtolower(__CLASS__) . '/' . strtolower(__FUNCTION__) . '/',
'ajax_loader' => base_url() . 'style/images/'. 'ajax-loader.gif'
);

strlower() might not needed in your case!
[quote name='mirr0r' timestamp='1357561272' post='5008']
hi,
I test your library and I m not able to work.

my controller is copy&past from your first post, just changed this string:


"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/', path to method



in


"url" => base_url() . __CLASS__ . '/' . __FUNCTION__ . '/'


and deleted optional:


'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"


So this is:


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() . __CLASS__ . '/' . __FUNCTION__ . '/'

);
$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);

}


table in database is your table "dd_goods", "dd_country", "dd_state" and "dd_city" with sample data.








List with relation works ok:



but I m not able to add record with dependent dropdown, first choice is ok but I can't choose second list:



Can u help me?

Thanks

Michele
[/quote]