Multiselect with null or empty value

QuestionsMultiselect with null or empty value
Hafiz asked 5 years ago

Hello,

Is there any way to have a selection of null value on multiselect? Or customize the multiselect option using custom array value like the selectbox?

6 Answers
Abu Ghufran Staff answered 5 years ago

Please explain further what you mean by multiselect. Is it multiselect filter OR select2 multiselect tags?

Also send screenshot of your requirement.

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

Hello,

Multiselect here I meant the multiselect filter.

Screenshot : https://imgur.com/KCSzm5t

As you can see at my screenshot.. there is some record have data and some of them is empty/null. But at the filter there’s no option to select the null one. This multiselect filter value is generated by using mysql statement and mysql will ignore the null value. So I’ve been thinking is there any way to customize the multiselect filter, just to make an option to select the null value one.

Abu Ghufran Staff answered 5 years ago

If your field is numeric id and empty value is 0, then you can simply set:

$col["stype"] = "select-multiple";
$col["searchoptions"]["value"] = "0:-Empty-;".$str;

If your field is string and empty value is “”, then set:

$col["stype"] = "select-multiple";
$col["searchoptions"]["value"] = ":-Empty-;".$str;

If you are looking for null value, it will need some changes in library. Let me know if not resolved.

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

Hello,

It is still not resolve on my side.

I’ve checked my database just now and the value is null.

Kindly advice me if you need to change anything from my side.

Thanks.

Abu Ghufran Staff answered 5 years ago

Hello,

I found a simple solution for null filtering.

In multiselect-filter settings, add an empty setting:

// multi-select in search filter
$col["stype"] = "select-multiple";
$col["searchoptions"]["value"] = ":-Empty-;".$str;

And in column definition, use dbname property and use IFNULL to make it “”.

$col = array();
$col["title"] = "Client";
$col["name"] = "client_id";
$col["dbname"] = "ifnull(invheader.client_id,'')";

So now if you search “” (empty option) it will filter null value.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Abu Ghufran Staff replied 2 years ago

If using Oracle, use NVL(…) instead of ifnull(…)

Hafiz answered 5 years ago

Thank you very much.

It helps me a lot 🙂

Your Answer

6 + 5 =

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?