1

I have the code that hides empty fields in a list and it works great, the problem is it also hides the edit field and icon which I would like to keep, what would I need to change in the code to stop it from being hidden

enter image description here

<script type="text/javascript">
  $(function() {
$.each($('td.ms-stylebody'), function() {
if (!$(this).text().replace(/\xA0/,' ').trim()) {
$(this).closest('tr').hide();
 }
});
 });
</script>

EDIT: So I have found a problem, when I group by a column my code does not work, any ideas how to fix both issues?

Here is my password list where I would like to hide fields that do no have a value because the other columns belong to a different content type

I found this article which works when not grouped, I need it to work when grouped

http://www.surfpointtech.com/2014/05/20/cleaner-list-view-boxed-style-using-jquery/

enter image description here

  • why do you need to hide empty fields? In your case the column title doesn't match the column value anymore – Gwny Feb 5 '16 at 9:30
  • Thanks for the reply, how do I fix the the two problems? – Matt Saunders Feb 6 '16 at 21:24
  • for that I need to understand what you are trying to achieve by hiding the empty columns? why not leave them there? – Gwny Feb 8 '16 at 8:14
  • I have a password list with content types that have different columns associated with each content type, I al using the Allitems view with all the content type columns visible, I am then grouping the view by Content type. When I enter say a website password the other columns are shown in the group (see image above) I need to hide fields that do not have an values so then the view makes more sense – Matt Saunders Feb 8 '16 at 23:04
  • have you tried using jslink for that? – Gwny Feb 9 '16 at 15:24
1

You can attach a jslink file (js) to your listview webpart. Here is an example for a similar problem like yours : https://code.msdn.microsoft.com/office/Client-side-rendering-code-2625e5e3

It changes how your webpart is rendered and you can change this for every column.

0

You can use this popular jQuery library SPUtility https://sputility.codeplex.com/

with this code example you can hide a specific field

SPUtility.GetSPField('% Complete').Hide();

This approach gives you a greater degree of control compared to the CSS selectors method which hides all fields of that class

see also: Hide/Show field on list form based on value from another field

  • Thanks Damien, this is great, in your example you are specifying which field to hide, is it possible to use SPUtility to hide fields that have no value entered. – Matt Saunders Feb 11 '16 at 3:23
  • hi Matt yes - you put the name of the field eg Bank Name and it will be hidden. BTW the other link on SharePoint shows a much more detailed code example which will show or hide a field based on the value of a selected field – Damien Feb 11 '16 at 8:30

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.