Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Custom sort country drop down list View modes: 
User avatar
Member
Member
spectro-jarlen - 11/16/2011 9:56:38 AM
   
Custom sort country drop down list
Is there a way to custom sort the country drop down list so that Canada and USA appeared before all other countries? I want to keep the option open to show all countries, but most of our customers come from Canada and USA, so it would be easier for users to find the country at the top of the list. I checked the country list in SiteManager -> Development -> Countries, but there isn't any sorting mechanism outside of name.

thanks,
Jarlen

User avatar
Member
Member
nicolas.juteau-nexun - 11/16/2011 11:01:48 AM
   
RE:Custom sort country drop down list
Hi Jarlen,

The only way I found to do what you want is by sorting the countries by its 'CountryLastModified' column. It is not visible in the SiteManager but definetly there.

What you have to do is just edit the countries (in cmsdesk/sitemanager) you want to appear on top of the list so their CountryLastModified date will be updated. (In your case, edit Canada and USA)

Then, you will have to modify the CountrySelector webpart (/CMSFormControls/CountrySelector.ascx file)

On line 7, there is the code:

<cms:UniSelector ID="uniSelectorCountry" runat="server" DisplayNameFormat="{%CountryDisplayName%}"
ObjectType="cms.country" ResourcePrefix="countryselector" AllowAll="false" AllowEmpty="false" />


replace this with:

<cms:UniSelector ID="uniSelectorCountry" runat="server" DisplayNameFormat="{%CountryDisplayName%}"
ObjectType="cms.country" ResourcePrefix="countryselector" AllowAll="false" AllowEmpty="false" OrderBy="CountryLastModified DESC" />


This tells the UniSelector control to sort the countries by their last modified date from the newest date to the oldest.

The only caveat I see with this solution is that the other countries (other than Canada and USA) will not be sorted alphabetically if their CountryLastModified column differs.

You could fix this by achieving something like (Transact SQL):

UPDATE CMS_Country SET CountryLastModified = '2008-03-13 00:00:00' WHERE (CountryName <> 'Canada' AND CountryName <> 'USA')


That way, hence all other countries have the same CountryLastModified date except Canada and USA, the alphabetical order will be respected.

For your information: I would suggest not doing this if you do not have a minimum of knowledge in programming ;) Strante behavior can occur if you do not do this correctly.

Maybe someone at Kentico knows a better way to do this for the average user? :)

I will follow this post if you have further questions.

Cheers !

User avatar
Member
Member
nicolas.juteau-nexun - 11/17/2011 8:18:44 AM
   
RE:Custom sort country drop down list
I have found some way better than mentionned previously, but needs more tweaking from your side. Just tell me if previous solution does not do the trick and i'll explain it.

User avatar
Member
Member
spectro-jarlen - 11/19/2011 10:30:18 AM
   
RE:Custom sort country drop down list
Hey Nicolas,

Thanks for the reply. I hadn't checked my post and meanwhile was working on my own solution. I just saw your response now (thank you for that) and it sounds like my solution is similar to what you're suggesting and as well may be what you thought of as a better trick.

Here is my solution:

1. Alter the country table, adding a new column which I can use to sort, default value for all rows = 100, that way if I need to add more countries at the top of the list, I can add up to 100 before the full list appears:

ALTER TABLE dbo.CMS_Country ADD CountryOrderBy int NOT NULL DEFAULT(100)
GO


2. Next, I update the country table rows for Canada and USA, so that Canada = 1 and USA = 2 for the CountryOrderBy column:

UPDATE dbo.CMS_Country SET CountryOrderBy = 1 WHERE CountryID = 309;
GO
UPDATE dbo.CMS_Country SET CountryOrderBy = 2 WHERE CountryID = 271;
GO


3. And finally, similar to your suggestion, I added the OrderBy parameter to the Country tag in ~\CMSFormControls\CountrySelector.ascx with values: OrderBy="CountryOrderBy ASC, CountryName ASC" - this will sort at first by my new column, and then sort all country names alphabetically.

<cms:UniSelector ID="uniSelectorCountry" runat="server" DisplayNameFormat="{%CountryDisplayName%}"
ObjectType="cms.country" OrderBy="CountryOrderBy ASC, CountryName ASC" ResourcePrefix="countryselector" AllowAll="false" AllowEmpty="false" />


It works like a charm. :)

User avatar
Member
Member
nicolas.juteau-nexun - 11/19/2011 2:55:30 PM
   
RE:Custom sort country drop down list
Hello Jarlen,

I'm glad you found a solution! Indeed, yours is pretty similar to mine. I tried to put forth a solution simplest as possible, I did not know you had great knowledge :o

Let me tell you the solution I mentionned in my second post, just in case: it is very good and could be used in other contexts.

First, in the table CMS_Class in SQL, the row WHERE ClassName = 'cms.country', set the column ShowAsSystemTable to True. It will allow you to edit as you want the country class in Site Manager -> Development -> System tables.

Add your custom field there. For example: ShowOnTop (Boolean). Check Show in editing form.

That way, you will be able to edit at anytime the countries you want to appear on top of list directly inside kentico cms in Site Manager -> Development -> Countries :D

Not to mention you will have to update the CountrySelector control the property OrderBy to: ShowOnTop DESC, CountryDisplayName ASC. But I think you already know that! Just for others :)

That way it will show countries you want on top of list and respect the alphebetical order.

Isn't that great? Thank you Kentico for such great customization possibilities.

I hope this solution will help you in the future for other little problems like this one :)

Nicolas

User avatar
Member
Member
kentico_michal - 11/21/2011 3:44:17 AM
   
RE:Custom sort country drop down list
Hello guys,

Thank you very much for your thoughts and great solution. I am pretty sure it will be helpful for other users.

Best regards,
Michal Legen

User avatar
Member
Member
spectro-jarlen - 11/21/2011 2:51:09 PM
   
RE:Custom sort country drop down list
Hey Nicolas,

Wow - didn't know about that feature. Thanks for sharing this. Typically I prefer to avoid modifying the database directly, but sometimes it is necessary to perform a custom solution. This will be useful for future things I may come across for sure.

thanks again,
Jarlen

User avatar
Member
Member
eagleag - 8/16/2012 6:34:49 AM
   
RE:Custom sort country drop down list
I've followed these steps:

First, in the table CMS_Class in SQL, the row WHERE ClassName = 'cms.country', set the column ShowAsSystemTable to True. It will allow you to edit as you want the country class in Site Manager -> Development -> System tables.

Add your custom field there. For example: ShowOnTop (Boolean). Check Show in editing form.

That way, you will be able to edit at anytime the countries you want to appear on top of list directly inside kentico cms in Site Manager -> Development -> Countries :D


but when I go to edit COUNTRY I dont see new field.
only when I try create NEW COUNTRY do I see new field.

Any idea how to solve this?

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 8/20/2012 3:04:33 AM
   
RE:Custom sort country drop down list
Hello,


we were writing e-mails about this issue, so only for other visitors:

The edit form is hard-coded so if you want to add your custom field, edit:

<web site folder>\CMSModules\Countries\Pages\Development\Country\Tab_General.aspx

and add the custom field there and ensure saving.

Please note that upgrade or hotfix can re-write your changes since this customization is not supported by default.


Best regards,
Helena Grulichova