⚠ 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 forum is read-only and soon will be archived. ⚠


[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

#101 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

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

#102 kenshicu

kenshicu

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts

Posted 18 December 2012 - 02: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 (that's how I had to put it to work are the relationships set_relation_n_n)
Posted Image
after ?
Posted Image
regards

#103 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 18 December 2012 - 07:33 PM

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

#104 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 18 December 2012 - 07:56 PM

deleted

#105 kenshicu

kenshicu

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts

Posted 18 December 2012 - 10: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.

in short, is to see if the library can work with relationships set_relation_n_n
greetings and thanks for replying

#106 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 19 December 2012 - 10:53 AM

The library doesn't supports your structure.

#107 kenshicu

kenshicu

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts

Posted 19 December 2012 - 02:06 PM

ok, thanks anyway

#108 tlc033

tlc033

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts

Posted 26 December 2012 - 10:38 AM

Hi. Can i get this library to work with a structure like this:
Storing Hierarchical Data in a Database

Posted Image Posted Image
THX.

#109 dblanco

dblanco

    Member

  • Members
  • PipPip
  • 22 posts

Posted 27 December 2012 - 09: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

#110 dblanco

dblanco

    Member

  • Members
  • PipPip
  • 22 posts

Posted 27 December 2012 - 11: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//ad..._subcategoria/2

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

#111 dblanco

dblanco

    Member

  • Members
  • PipPip
  • 22 posts

Posted 28 December 2012 - 12:32 AM

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

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

Very useful the library. Thanks

#112 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 28 December 2012 - 01:27 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

This method return Javascript

#113 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts

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 not related 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?

#114 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 03 January 2013 - 12:12 PM

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

#115 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts

Posted 03 January 2013 - 12:14 PM

OK

#116 victor

victor

    grocery CRUD Hero

  • Advanced Member
  • PipPipPip
  • 967 posts

Posted 03 January 2013 - 01: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'));


#117 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts

Posted 03 January 2013 - 01: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!

#118 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts

Posted 04 January 2013 - 03:53 AM

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!

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


Shame on me!!! I didn't search for similar issues before posting an issue!
Solution for the problem mentioned before is here: http://www.grocerycr...urned/#entry982

#119 mirr0r

mirr0r

    Newbie

  • Members
  • Pip
  • 5 posts

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.

dd_goods.jpg
dd_country.jpg
dd_state.jpg

dd_city.jpg


List with relation works ok:

list.jpg

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

dropdown_error.jpg

Can u help me?

Thanks

Michele

Attached Thumbnails

  • dd_goods.jpg
  • dd_country.jpg
  • dd_state.jpg
  • dd_city.jpg
  • list.jpg
  • dropdown_error.jpg


#120 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts

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' => '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'
);

strlower() might not needed in your case!

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


Edited by David Oster, 07 January 2013 - 12:41 PM.






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