MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

How do I filter by a Category  (Mono Support )

Viewed 20007 time(s), 8 post(s) 10/12/2011 3:27:17 AMby yousaid

Related topics

yousaid

yousaid

10/12/2011 3:27:17 AM

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

This content has not been rated yet. 
206 Reputation 36 Total posts
imarusic

imarusic

10/12/2011 8:50:40 AM
Hi,

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

Regards
This content has not been rated yet. 
3016 Reputation 428 Total posts
khorvat

khorvat

10/12/2011 9:35:38 AM
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
This content has not been rated yet. 
15993 Reputation 2214 Total posts
yousaid

yousaid

10/12/2011 12:18:59 PM

Greetings,
@Imarrusic:I am using the News Module

@Khorvat
I will prefer to do it Programatically, so Please show me how.
cheers,
yousaid
This content has not been rated yet. 
206 Reputation 36 Total posts
khorvat

khorvat

10/12/2011 8:16:42 PM
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
This content has not been rated yet. 
15993 Reputation 2214 Total posts
khorvat

khorvat

10/13/2011 8:52:37 AM
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
This content has not been rated yet. 
15993 Reputation 2214 Total posts
yousaid

yousaid

10/14/2011 5:19:15 AM
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
This content has not been rated yet. 
206 Reputation 36 Total posts
khorvat

khorvat

10/14/2011 8:23:04 AM
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
This content has not been rated yet. 
15993 Reputation 2214 Total posts