Sometimes we need to set filter in Sharepoint list view on the hidden field. As hidden fields are not shown in UI we can’t set such filters from the browser, but we can set them programmatically. E.g. suppose that we have field “IsPrivate” which is hidden so end users are not able to change value of this field and we want to show only non-private list items in the list view. List view filter will look like this in this case:
1: <Where>
2: <Eq>
3: <FieldRef Name="IsPrivate" />
4: <Value Type="Boolean">false</Value>
5: </Eq>
6: </Where>
Now if we will try to modify this list view in UI we will see that its filter section looks like there is no filter at all:
And which is more interesting is that when we will click Save button there – filter on hidden field will remain. I.e. if we will add sorting from UI ViewQuery property will look like this:
1: <OrderBy>
2: <FieldRef Name="Title" />
3: </OrderBy>
4: <Where>
5: <Eq>
6: <FieldRef Name="IsPrivate" />
7: <Value Type="Boolean">false</Value>
8: </Eq>
9: </Where>
even though Filter was shown empty in UI. Be aware of this tricky moment to not be confused in situations when filter uses hidden fields.
No comments:
Post a Comment