Developer forum

Forum » CMS - Standard features » Item Publisher Paging Sorting Filtering gripe

Item Publisher Paging Sorting Filtering gripe

Kevin O'Driscoll
Reply

Hi. Using Item Publisher to handle Item types as is standard, its what the module is for. Initial Paging is out the box and works fine.
Now our client wants some filtering and sorting added to the mix. And so we have a problem, since I can find no documentation how to implement this without causing a rewrite with custom code or using Query Publishing that requires a lot more expertise for the clients' content managers. Im aware of ?orderby=Business_Category&direction=asc for sorting from a forum post found by accident.

In the much loved Query Publisher I can parameterize filters on the url - do ?FilterBy=Chairs&SortBy=CreatedDate and the whole data set can be filtered, sorted, returned and paged, however in ItemPublisher, if Page size is set say 10 only the first 10 items are available to the filter, so it looks like I have to capure all the dataset via the api and implement custom paging and sorting:
Page size = 10

@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@{
    string filterTerm = string.Empty;
    IEnumerable<LoopItem> ItemList = GetLoop("ItemPublisher:Items.List");  // The First X Page size eg 10 of say 22 Items = the first of 3 pages. The Template now needs to use ItemList.

    if (!string.IsNullOrEmpty(System.Web.HttpContext.Current.Request["FilterBy"]))
    {
        filterTerm = System.Web.HttpContext.Current.Request["FilterBy"].Trim().ToLower();
        ItemList = ItemList.Where(o => o.GetString("ItemPublisher:Item.Business_Category").Equals(filterTerm)).ToList();

        //Test
        foreach(var s in ItemList)
        {
            if(s.GetString("ItemPublisher:Item.Business_Category") == "chairs")
            {
                // the first 15 items are all "tables", so no "chairs" are returned, there are 4 on the second page, but not available to the filter
            }
        }

    }

So if all 22 records are returned with GetLoop("ItemPublisher:Items.List"); and you could do (maybe in your API, where you can adjust GetInteger("ItemPublisher:Items.Paging.CurrentPage") and possibly GetInteger("ItemPublisher:Items.Paging.TotalPages") to reset the paging)
ItemList = ItemList.Where(o => o.GetString("ItemPublisher:Item.Business_Category").Equals(filterTerm)).ToList().Take(GetInteger("ItemPublisher:Items.Count"));

Is there any documentation to handle parameterized (url) filtering for Item Publisher and to adjust "ItemPublisher:Items.Paging.CurrentPage" and "ItemPublisher:Items.Paging.TotalPages" values?

Or do you have something like [Dynamicweb.Extensibility.Notifications.Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.ProductList.BeforePaging)]
Args.Products.Clear();                // clear original collection
Args.Products.AddRange(collection, false);    // pass the ordered collection to original collection, no duplicates

for ItemPublisher?

Kev

 


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Kevin

I think the answer is to be found here: https://doc.dynamicweb.com/documentation-9/content/apps/item-publisher

Check out the querystring parameter section.

BR Nicolai

Votes for this answer: 1
 
Kevin O'Driscoll
Reply

Lookin good Nicolai thanks...
works really well.

 

You must be logged in to post in the forum