How to create QueryItems?
I currently have a requirement where I need to dynamically create several NewsView controls that each take in a category argument, and only display news items from that category.
I've got it working fine, but it's really messy. I had to set the NewsView's AdditionalFilter property with my own QueryData and QueryItems... the contents of which I don't fully understand but have just adapted from the output of NewsViews which I've created via the built in designer.
Is there a proper way to create QueryData via some utility class? I see a QueryBuilder namespace but am not yet sure what it's for or how to use it
Hello Hahn,
Actually you can use FilterExpression of the ContentView based control
sample
NewsView v =
new
NewsView();
var filter =
"Category.Contains(\"A9F2C13A-9472-4BF6-AB3D-19B2EF05B043\") AND Visible = true AND Status = Live AND PublicationDate <= DateTime.UtcNow AND (ExpirationDate = NULL OR ExpirationDate > DateTime.UtcNow)"
;
v.MasterViewDefinition.FilterExpression = filter;
Controls.Add(v);
works great. thank you for the response and for making the filter complete, as I would not have thought to include live status and expiration date into the filter.
Is there syntax for filtering by custom fields?
Hi Basem,
Here is a sample that shows filtering by custom fields
Visible = true AND Status = Live
AND Tags.Contains((95BFB3D9-10EE-491f-BB95-5B43423404D5))
AND CustomField.Contains((83F51312-C941-43a1-BC5E-605A2BC288D5))
There were errors in the previous versions that should be fixed in the latest build.
Regards,
Ivan Dimitrov
the Telerik team
Hi Ivan,
I have a custom widget and I want to dynamically add a NewsView with a filter by using the code snippet you showed before:
NewsView v =
new
NewsView();
var filter =
"Category.Contains(\"A9F2C13A-9472-4BF6-AB3D-19B2EF05B043\") AND Visible = true AND Status = Live AND PublicationDate <= DateTime.UtcNow AND (ExpirationDate = NULL OR ExpirationDate > DateTime.UtcNow)"
;
v.MasterViewDefinition.FilterExpression = filter;
Controls.Add(v);
Hi Hahn,
I'm also trying to achieve this. Would it be possible for you to post some of your code here that has this working? Are you using a custom widget?
Thanks,
Peter
Hello Peter,
I tried the same at my end and the source was correctly filtered. I used Page_Load of a user control.
Best wishes,
Ivan Dimitrov
the Telerik team