Using drupal 7 I have imported an excel spreadsheet into a database and mapped about 20 fields into a Custom Content Type. Not every field contains data in every record. I've created a couple of Views - one based on the Glossary that gives me a searchable form for the entries, and a separate Block view, which gives me the ability to hide empty fields and show random nodes.

However, when I click on a record to view the full node, the display shows all the fields, including the empty ones. If I edit the node, and then save it, when viewed the empty fields are hidden.

Is there a simple way to hide those empty fields all the time in full node view. Can I do it from within Views(3)? I'm not a programmer so not sure that I could edit a page template if that is what is required.

  • Interesting. How are you importing the excel documents? – Citricguy Aug 21 '12 at 9:11
  • Excel file was saved out as a CSV file and imported using the Feeds module – Stuart Aug 21 '12 at 9:34
  • There are many ways to solve this problem here drupal.org/node/2027583.<br> Also problem was fixed in latest dev build. – iamdroid Aug 29 '13 at 14:19

If, when you edit the node, it displays correctly, this makes me think that the import may have added whitespace into the fields? Is that possible? I would recommend using Migrate for importing data. Even from files.

Either way, Views will not work for a node view ie, node/nid. You could use Views to create a landing/index page and hide empty fields pretty easily.

Rather than change the display, I would be more concerned with the quality of data in the fields (ie, whitespace) and would look at using something like VBO for cleaning the data. Are there many nodes? You could even just write a simple SQL update statement, something like;

UPDATE {field_data_field_blah} SET $value_col = NULL WHERE $value_col = '';

Note, pseudo query. :)

  • There are 21,500 nodes. There aren't any white spaces shown in the CSV files used for import, so if they are in the database they've been created in the Feeds import. – Stuart Aug 21 '12 at 11:11
  • 1
    Which is likely. When you open and edit the node and then save it, Drupal is likely trimming whitespace and/or making empty strings (such as '') NULL. So, we can either update those fields in the DB or VBO, or we can alter their output, which is the easier, but less correct method. – Christian Aug 21 '12 at 12:21
  • I'll have a look tonight at updating the DB fields with that SQL command. It's all a new area to me, but I'm a quick learner :) – Stuart Aug 21 '12 at 13:20
  • Sorry for not getting back to you - had to stop work on it as I had a mountain of other things to do! Have had a quick look at the DB but can't get it to work on the SQL query - getting syntax error, which is not really surprising, as I don't know much about SQL queries! At the moment I've got this: UPDATE 'field_data_field_last_name' SET 'field_last_name_value'= NULL, WHERE 'field_last_name_value'= " "; I'm not too bothered about fixing it, as long story short, someone else has been working on the same end-solution elsewhere, so my project will probably end up being scrapped. Stuart – Stuart Aug 29 '12 at 20:02
  • This is pretty late now but for others looking here, delete the null rows from the field tables. I have had this problem with the migrate module too. The field tables end up with rows where the value is null, but there should just be no row for that field for that entity. – rooby May 19 '13 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.