Mono Support How do I filter by a Category 

Viewed 37021 time(s), 8 post(s), 10/12/2011 3:27:17 AM - by yousaid
10/12/2011 3:27:17 AM
206 Reputation 36 Total posts


The website I am building is a News and Sports Website. So I want Sports to be a separate menu item and appears on the navigation menu. So I added a page named Sports and set it to show on the navigation. All this works fine. I have created a Category called Sports. Now what I want is this:When a visitor clicks the Sports menu Item on the Navigation menu, it filters ONLY items in Sports category, just like it does for News and Blogs.
Where is the Filter Property set or how do I archieve this?
cheers,
Yousaid

1
10/12/2011 8:50:40 AM
3016 Reputation 428 Total posts

Hi,

Which modules are you using on the Sports page(blog, news or both)?

Regards

2
10/12/2011 9:35:38 AM
15993 Reputation 2214 Total posts

Hi,

as I understand you are adding manually the "Sports" link to the menu in the MonoX administration ? If so you will need to add a category filter also manually by adding the query parameter newscatid e.g. http://localhost/MonoX/MonoX/Pages/News.aspx?newscatid=4c630ec2-4c00-45c5-aa2c-9f6700e506f1. Note that you need to hard-code the category id in the URL, I know that this isn't a best solution but if you are doing everything manually this is the only way.

If you want to programatically add the category id to this menu item URL let us know so we can show you how.

Regards

3
10/12/2011 12:18:59 PM
206 Reputation 36 Total posts


Greetings,
@Imarrusic:I am using the News Module

@Khorvat
I will prefer to do it Programatically, so Please show me how.
cheers,
yousaid

4
10/12/2011 8:16:42 PM
15993 Reputation 2214 Total posts

Hi,

you need to inherit from the MonoSoftware.MonoX.ModuleGallery.MonoXMenuSimple and override the OnPreRender. In the OnPreRender you should use repeater.DataSource to extract the data of type HierarchyDataCollection<HierarchyData<NavigationMenuItem>>. Now when you have the whole hierarchy, search for your page and set the Url property of the NavigationMenuItem instance to something similar to this:

Guid catId = MonoSoftware.MonoX.Repositories.NewsRepository.GetInstance().GetCategoryId("YourCategoryName");
NavigationMenuItemInstance.Url = NavigationMenuItemInstance.Url.Append(UrlParams.NewsCategoryId, catId)

I hope that I have point you in the right direction, if you need anything else let us know.

Regards

5
10/13/2011 8:52:37 AM
15993 Reputation 2214 Total posts

Hi,

I have just spoke to Vlatko and he suggested one more way to accomplish this, by using the NavigationMenuRendered event that you can attach to on the control or page where you have placed the MonoXMenuSimple module. It will iterate through the hierarchy for you, you just need to watch for the item you need to modify and perform the same operation that I have described above.

Regards

6
10/14/2011 5:19:15 AM
206 Reputation 36 Total posts

Greetings,
Unfortunately, I am unable to get this to work following your guide. Can you please post a sample or show a tutorial on how to accomplish this?. I am of the opinion that filtering by category is an integral part of any application.
This I believe is a great way to extend MonoX without the source code.
With the code available, this is fairly easy to implement, but without the source code, a tutorial or clear guidance in the form of a working sample will be very helpful.

cheers,
yousaid

7
10/14/2011 8:23:04 AM
15993 Reputation 2214 Total posts

Hi,

basically MonoX menus are used for MonoX page navigation and more general purposes. Therefore "other" modules aren't integrated in it. To get exactly the scenario you want you need to use NewsMenu module (it will show only the news categories) which will filter news article by selected category. 

As for the above implementation everything can be done without the MonoX source code and unfortunately we can't cover every MonoX customization aspect with tutorial and full source code samples. That's why we are trying to provide you with a good support and guidance.  

Let me try to summarize why you need to do to get this working:
1. Inherit from the MonoSoftware.MonoX.ModuleGallery.MonoXMenuSimple
2.Override the OnInit and use this code to attach to event mentioned by Vlatko

base.NavigationMenuRendered += new EventHandler<NavigationEventArgs>(MonoXMenuSimple_NavigationMenuRendered);
3. Add the following code to the NavigationMenuRender
void MonoXMenuSimple_NavigationMenuRendered(object sender, NavigationEventArgs e)
{
    if (e.NavigationMenuItem.Url.EndsWith("YouCustomUrl"))
    {
        Guid catId = MonoSoftware.MonoX.Repositories.NewsRepository.GetInstance().GetCategoryId("YourCategoryName");
        e.NavigationMenuItem.Url = e.NavigationMenuItem.Url.Append(UrlParams.NewsCategoryId, catId);
    }
}

4. Done forget to change the Inherits attribute in the MonoXMenuSimple mark-up file to point to your implementation.

Let us know if you need anything else.

Regards

8
This is a demo site for MonoX. Please visit Mono Software for more info.