How to create QueryItems?

Posted by Community Admin on 03-Aug-2018 16:36

How to create QueryItems?

All Replies

Posted by Community Admin on 04-Apr-2011 00:00
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
Posted by Community Admin on 06-Apr-2011 00:00
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);


Regards,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 06-Apr-2011 00:00
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.  
Posted by Community Admin on 25-May-2011 00:00
Is there syntax for filtering by custom fields?
Posted by Community Admin on 25-May-2011 00:00
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
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Posted by Community Admin on 26-May-2011 00:00
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);

I tried adding it into the CreateChildControls() and the Page_Load() methods and in both cases the NewsView appears correctly but the filter doesn't work (all of the news items appear, rather than just the ones with the given category). I'm sure the filter text is correct because I was able get the it working by adding it to the FilterExpression in the Advanced settings of the NewsView widget. Can you tell where I should put the above code to have the filter work correctly? Are there any other steps I need to take to get the filter working for a dynamically created NewsView?

Thanks,
Peter
Posted by Community Admin on 26-May-2011 00:00
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
Posted by Community Admin on 26-May-2011 00:00
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
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
This thread is closed