Multiple select dropdown in add/edit pop up?

QuestionsMultiple select dropdown in add/edit pop up?
Rankaj asked 9 years ago

Dear Abu,

I have query regarding multiple select drop down in add/edit pop up. Actually i have one master grid showing all the news articles, in case of add new article i add article data like(article title,description,date,brand dropdown etc.) earlier i was adding single brand for one article but now i have to add multiple brands for single article. Can u please suggest me how it is feasible? Now in add/edit pop up i will have to select multiple brands from dropdown.

Note: Please take care of edit record popup for that multiple selected drop down(brand_id)

Table Structure is below:-
—————————
Table name = news_article_brands
Columns = id, brand_id, article_id

6 Answers
Abu Ghufran answered 9 years ago

Hello,

For multi-selection of dropdown, you can have select2 with multiple option. Refer demos/integration/dropdown-select2.php

// to enable multiselect option
$col["editoptions"]["multiple"] = "multiple";

It will result in following:
http://easycaptures.com/fs/uploaded/801/5587551854.png

Now it will post comma separated values to server.
On backend, you need to use on_update event handler and write your manual code to insert into your one-many relation table.

Refer demos/editing/custom-events.php

Rankaj answered 9 years ago

Hi,

In case of "add record" its working fine but in "edit" its not working fine. Also not showing last selected records in edit mode.

Can u please help in that case.

Table Structure is below:-
—————————
Table name = news_article_brands
Columns = id, brand_id, article_id

Database entries are like below

[id] [brand_id] [article_id]
1 10 100
2 11 100
3 12 100

Rankaj answered 9 years ago

Also have one question which of below structure is good to store multiple data(add/edit/delete) in database for select2 dropdown

Structure-1:-
————–
Database entries are like below

[id] [brand_id] [article_id]
1 10,11,12 100

Structure-2:-
————–
Database entries are like below

[id] [brand_id] [article_id]
1 10 100
2 11 100
3 12 100

Abu Ghufran answered 9 years ago

For edit, you need to select brand_id using group_concat function.
This will return brand_id comma separated and it will be loaded in multi select by phpgrid.

Rankaj answered 9 years ago

On main grid the comma separated values are coming now. But in edit popup case the previous selected values not showing. please help

Abu Ghufran answered 9 years ago

It's my mistake.

The correct syntax for multi select dropdown is:
$col["editoptions"]["multiple"] = true;

Previously i told $col["editoptions"]["multiple"] = "multiple"; which is incorrect.

Your Answer

1 + 17 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?