Pager doesn't preserve filtering criteria

Posted by Community Admin on 04-Aug-2018 17:45

Pager doesn't preserve filtering criteria

All Replies

Posted by Community Admin on 14-Feb-2011 00:00

My issue is with showing a paged result-set of Blog Posts, but I'm certain this exists in other section-controls (News, Content Items, etc.).

I've set up a page for showing historical Blog Posts, allowing the actor to filter by a specific date or a specific taxonomy item (category).  Using the URL-key-prefix of 'k' the URLs are generated in the format:

http://<mysite>/blogs/myblog/archives/!k/2011/01/25

Which works with the out-of-the-box Blog controls, and correctly places a pager at the bottom of the page when the number of results to show exceeds the limit I have set (in this case, five).  However, the pager control appears to be stripping the date or taxonomy criteria from the end of the URL so that the hyperlink for browsing to the second results page is generated as:

http://<mysite>/blogs/myblog/archives/?k=2

Similarly, when filtering by taxonomy items I've set up the following link for filtering by a category, and works correctly:

http://<mysite>/blogs/myblog/archives/!k/-in-Category/Categories/regions

But the pager generates subsequent hyperlinks like the following (stripping the filter criteria):

http://<mysite>/blogs/myblog/archives/?k=2

I would assume that the pager control would preserve any filter criteria specified in the URL and generate the correct links, for example:

http://<mysite>/blogs/myblog/archives/!k/2011/01/25?k=2
and
http://<mysite>/blogs/myblog/archives/!k/-in-Category/Categories/regions?k=2

Posted by Community Admin on 15-Feb-2011 00:00

Hi Anthony,

The reason for all this happening is that all URLs generated by the widgets go through route handlers. When using route handlers, anything in the URL between two slashes is part of the route. When you want multiple filter criteria, you are essentially generating a specific route. Say if you want to filter by date AND page you could generate one of two routes:

Semantically, those two should do the same thing. Technically, however, they don't. They are interpreted by the routing engine as two different routes under two different parent routes. Hence, filtering by multiple criteria is not a suitable case for using route handling.

How can then we achieve our desired goal? By supplying values for filtering in the QueryString, rather than the URL itself. The QueryString is ignored by the routing engine and we can insert whatever name-value pairs we want. Our URLs would look like:

We could mix those parameters in any order so this will be semantically AND technically equivalent to the above:
To enable this, the only thing you have to do is set the UrlEvaluationMode property in the Advanced view of the widget to "QueryString" (rather than the default UrlPath). Once you do this, this property is applied for all widgets on the page and filtering by multiple criteria should be fine.
The tradeoff is basically between pretty URLs (route handling) and ugly, but powerful URLs (QueryString). For basic scenarios, the first would be OK, and that's why it is the default value.

All the best,
Slavo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about 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 17-Feb-2011 00:00

Hi Slavo -- I appreciate your thorough explanation of how the routing-engine can become confused by the filtering criteria, but I do have a couple of follow-up comments:

1. Why does the Pager control ignore the UrlEvalationMode property of its host control and always append the page-index as a query-string parameter?  If I specify the mode to UrlPath, then I'd expect that the page number would be part of the URL and not the query-string, ie:

http://<mysite>/blogs/myblog/archives/!k/2/

It seems like this is a bug?

2.  Why weren't pre-defined URL keys defined for date and page criteria like they were for categories?  Sitefinity 4 internally recognizes that the route /-in-Category/ specifies that all items afterward within the URL represents the category-hierarchy from which to sort the items.  If the system gets confused as how to manage the filters when the mode is UrlPath, then why not pre-define that /-for-Date/ and /-Page/ are routes from which the engine can use to parse-out these filter values?  That means we could have the semantics of the UrlPath evaluation mode but with the power of the query-string parsing, ie:

http://<mysite>/blogs/myblog/archives/!k/-for-Date/2011/01/25/-in-Category/regions/canada/-Page/2/

Thanks for your assistance.

Posted by Community Admin on 22-Feb-2011 00:00

Hello Anthony,

  1. By default, on a new page, the page number is appended to the route (see attached image). You've probably modified the settings to make it go in QueryString mode?
  2. That's a good suggestion, but would complicate URL handling a lot. The reason it has been implemented for Taxonomies (not just Categories and Tags, which are the default taxonomies), is that you can have custom taxonomies with custom names in the URL. Instead of "/-in-Category/" you could create your own taxonomy called Sports, and the Url "/-in-Sports/" would still work out of the box. 

    To see how complicated it can get, let's take the example of filtering by date. With the current implementation, you can filter by day, month or year (without a custom /-for-Date/ pattern). If we want to introduce a pattern, we can have URLs like "/-for-Date/2011/02/22", "/-for-Date/2011/02", "/-for-Date/2011". Those all have a different number of routes. How would the routing engine know how many of those routes represent the filter? What if you have "/-for-Date/2011/02/-in-Category/Widgets"? Then we could easily misinterpret "-in-Category" as the value for the day. Parsing all combinations like the above becomes non-trivial. This doesn't scale, and it also defeats the purpose of having UrlPath mode in the first place - pretty URLs. This is why for advanced (non-default) scenarios, we advise using QueryString mode.
All the best,
Slavo
the Telerik team

Posted by Community Admin on 27-Oct-2011 00:00

Is there any way to change that route "-in-Category" to something more simple? Maybe "category"?

Posted by Community Admin on 02-Nov-2011 00:00

Hello Conrad Ehinger,

Currently, the only way to change that URL string is to implement your own URL evaluator and implement your custom views, which use it. The reason we have an "-in-" is that these URLs are valid for all taxonomies, and not only categories and tags. 

Categories and tags are just instances of the Hierarchical and Flat taxonomies, but in Sitefinity users can create their own. The URLs are implemented to work with all of them, not just the built-in ones.

Greetings,
Slavo
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 12-Mar-2013 00:00

Sorry to bring up an old thread, but is it possible to filter upon multiple categories or a parent category (and pull down all children category related content) when things are hierarchical?

Thanks!
Andy

Posted by Community Admin on 17-Mar-2013 00:00

Hello,

If I understood you correct, you want to have the ability to filter categories (in the Categories Grid section, in the backend of Sitefinity). At the moment you could only sort categories in the grid view of Categories by Title, URL and est.

All the best,
Stefani Tacheva
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