Filter blanks from dropdown?

Using your Sharepoint Lookup example, I was trying to filter out blank values in a dropdown (a lookup to a calculated column, native SharePoint forms automatically exclude blanks). Client is the column name, but this didn’t work:

function filterDT(){
        dt.filter = "<IsNotNull><FieldRef Name='Client' /></IsNotNull>";
    }

Also, I couldn’t find any documentation on Sort. Is it not possible to sort a dropdown by the values?

Hi!

As far as I understand, you want to exclude the blank values from a dropdown field and sort the values inside a dropdown, am I right?

You can use a lookup filter for this case:

Use 'ne' (not equal) in the filter query to exclude empty elements.

A code will look like this:

fd.spRendered(function() {
   fd.field('LookupFieldInternalName').filter = "FilterFieldName ne null";
   fd.field('LookupFieldInternalName').orderBy = "OrderFieldName";
   fd.field('LookupFieldInternalName').widget.dataSource.read();	
});

Make sure to add the fields that you want to use for filtering and ordering as an Extra fields in Lookup properties, if it’s not the field that Lookup displays by default.

Thank You! That helped me find the problem – my filter was on a calculated lookup column, Sharepoint wasn’t happy about that. Console showed the error: “The field ‘Client’ of type ‘Calculated’ cannot be used in the query filter expression.” I added the extra lookup fields and recreated that calculated column using filters, works fine now.

How is that blank aspect implemented? Where does the javascript go? How is it called?

@Kurtnelle

The code added in Javascript Editor. It is called on the form load as it included in the spRendered event handler.

image

Please have a look at Cascading Lookups and Manager articles to get more information.

Ok, I understand that.

Now I’m getting an error that fd is undefined.

@Kurtnelle,

Could you please provide the code you are using and the screenshot of the error from the console for me to be able to troubleshoot the issue.

Thank you!

The javascript is:

fd.spRendered(function() {
fd.field('LookupFieldInternalName').filter = "SourcePlant ne ''";
fd.field('LookupFieldInternalName').orderBy = "SourcePlant";
fd.field('LookupFieldInternalName').widget.dataSource.read();
});

@Kurtnelle,

Please replace LookupFieldInternalName in the code below with your field’s internal name.

Also, in below example filtering and ordering made by Title field. Replace Title with your filed’s internal name.

And please add the field that you want to use for filtering and ordering in Extra Fields under Lookup field Settings.
image

fd.spRendered(function() {
fd.field('LookupFieldInternalName').filter = "Title ne null";
fd.field('LookupFieldInternalName').orderBy = "Title";
fd.field('LookupFieldInternalName').widget.dataSource.read();	
});

Hi there,

I have a drop down list as the following:

.

I am also trying to filter out the null values. But I don't really understand the code as listed below:

fd.spRendered(function() {
fd.field('LookupFieldInternalName').filter = "Title ne null";
fd.field('LookupFieldInternalName').orderBy = "Title";
fd.field('LookupFieldInternalName').widget.dataSource.read();
});

is the LookupFieldInternalName same as the Name of the dropdown list? and what should i put in the "Extra Fields" field. Please refer to the below image on details of my dropdown list.

Thank you,

@jyou,

You need to replace LookupFieldInternalName with the internal name of the field.
image