Multiselect-filter where data contains commas

QuestionsMultiselect-filter where data contains commas
Matthew asked 4 years ago

I have a field which I want to multiselect filter on but it’s not working.  When I select a value the grid displays “no value found”.  I can multiselect on the ID field no problems but the field that contains data with commas in it won’t work.

This is the code for the ID field which is just an autoincrementing integer.  This multiselects fine.

$col = array();
$col[“title”] = “Id”;
$col[“name”] = “id”;
$col[“hidden”] = false;
$str = $g->get_dropdown_values(“Select DISTINCT id as k, id as v from 2009stats order by id asc”);
$col[“stype”] = “select-multiple”;
$col[“searchoptions”][“value”] = $str;
$cols[] = $col;

 

This is the code for the Name field which doesn’t work.  The data is in the form “Surname, Firstname”

 

$col = array();
$col[“title”] = “Name”;
$col[“name”] = “Name”;
$col[“width”] = “100”;
$col[“fixed”] = true;
$col[“editable”] = true;
$col[“search”] = true;
$col[“frozen”] = true;
$str = $g->get_dropdown_values(“Select distinct Name as k, Name as v from 2009stats order by name asc”);
$col[“stype”] = “select-multiple”;
$col[“searchoptions”][“value”] = $str;
$cols[] = $col;

 

Any thoughts on how to get this working?

 

Thanks

4 Answers
Matthew answered 4 years ago

I’ve just done a workaround and replaced the comma with a fullstop and this works as I’d expect.  It’s not the best solution but all I can think of for now:

$col = array();
$col[“title”] = “Name”;
$col[“name”] = “Namedot”;
$col[“dbname”] = “REPLACE(Name,’,’,’.’)”;
$str = $g->get_dropdown_values(“Select distinct REPLACE(Name,’,’,’.’) as k, REPLACE(Name,’,’,’.’) as v from 2009stats order by Name asc”);
$col[“stype”] = “select-multiple”;
$col[“searchoptions”][“value”] = $str;
$cols[] = $col;

$g->select_command = “SELECT *, REPLACE(Name,’,’,’.’) as Namedot FROM 2009stats”;

Matthew answered 4 years ago

I replaced the comma , with U+00B8: Cedilla ¸

This looks almost identical and works so happy days.

Abu Ghufran Staff answered 4 years ago

Thats fine as well. I have found solution for this issue as well. If your data contains comma, you need to surround the key in single quotes using sql concat. e.g.

$str = $g->get_dropdown_values(“Select distinct concat(\”‘\”,Name,\”‘\”) as k, Name as v from 2009stats order by name asc”);

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Matthew answered 4 years ago

Thanks Abu that’s perfect

Your Answer

15 + 3 =

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 0 / 5. Vote count: 0

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?