I'm using Views and the Data module to show a database in a way that's easy for our visitors to browse.

The database has some tables that contain both zero and null values. That data is output via the numeric field handler in Views. If I leave "Hide if empty" unchecked, the null values are converted to zero in the output. This doesn't happen for when I create a content type with numeric fields - Views outputs blanks when those fields weren't completed even if "Hide if empty" was unchecked. I think that's what most people would expect.

I'm not adopting the solution of using the "Hide if empty" checkbox because the Data module also apparently passes a zero as a string, which causes the zero values to also be hidden. This might be fixed via typecasting in the Data module, but that doesn't solve the problem for any other modules that might also pass null.

So, I added code in my views_handler_field_numeric class's render function to always return '' if the value is null. I think that would be safe behavior to add to Views.

Members fund testing for the Drupal project. Drupal Association Learn more


pbirk created an issue. See original summary.

pbirk’s picture

Status: Active » Needs review
811 bytes

Patch attached

Status: Needs review » Needs work

The last submitted patch, 2: 2756649-views-numeric-null-handling.patch, failed testing.

pbirk’s picture

pbirk’s picture

Status: Needs work » Needs review
villav74’s picture

Had the same issue. Null should be empty not 0

attheshow’s picture

Status: Needs review » Reviewed & tested by the community

Patch #4 is working well for us too. Marking as RTBC.