PDA

View Full Version : [CLOSED] How to : show the DisplayName attribute in column header?



macroe
Dec 31, 2013, 7:45 AM
hello, i write a gridpanel in the razor view, and use Html.X().ColumnFor to display column.

Column name displayed is not DisplayNameAttribute, but the Property name.

How do I make it show DisplayName attribute in column header?

Thank you.

Daniil
Dec 31, 2013, 11:58 AM
Hi @macroe,

I am not sure we should treat the DisplayName attribute as a Column's header text.

Please use the Column attribute.

[Ext.Net.MVC.Column(Text = "Header Text")]

macroe
Dec 31, 2013, 12:41 PM
Hi @macroe,

I am not sure we should treat the DisplayName attribute as a Column's header text.

Please use the Column attribute.

[Ext.Net.MVC.Column(Text = "Header Text")]

Thanks, but how can I localize the header text?

Baidaly
Dec 31, 2013, 2:53 PM
Hello!


Thanks, but how can I localize the header text?

If you mean localization using ResourceProvider, I'm afraid it is not possible right now.

However, you can extend attributes to add this functionality. You can find examples in the Internet like this one: http://carrarini.blogspot.ca/2010/08/localize-aspnet-mvc-2-dataannotations.html.

macroe
Jan 01, 2014, 3:32 AM
Hello!



If you mean localization using ResourceProvider, I'm afraid it is not possible right now.

However, you can extend attributes to add this functionality. You can find examples in the Internet like this one: http://carrarini.blogspot.ca/2010/08/localize-aspnet-mvc-2-dataannotations.html.


Sorry, I'm not very good at English.

But ,I have a BitResourceDisplayNameAttribute to localize displayname, it works fine in Html.X().TextField ,Html.X().Combobox() and so on, but not works in Column.


And, happy new year~



public class BitResourceDisplayNameAttribute : System.ComponentModel.DisplayNameAttribute, IModelAttribute
{
private string _resourceValue = string.Empty;
//private bool _resourceValueRetrived;

public BitResourceDisplayNameAttribute(string resourceKey)
: base(resourceKey)
{
ResourceKey = resourceKey;
}

public string ResourceKey { get; set; }

public override string DisplayName
{
get
{
//do not cache resources because it causes issues when you have multiple languages
//if (!_resourceValueRetrived)
//{
var langId = EngineContext.Current.Resolve<IWorkContext>().WorkingLanguage.Id;
_resourceValue = EngineContext.Current
.Resolve<ILocalizationService>()
.GetResource(ResourceKey, langId, true, ResourceKey);
// _resourceValueRetrived = true;
//}
return _resourceValue;
}
}

public string Name
{
get { return "BitResourceDisplayName"; }
}
}

Vladimir
Jan 04, 2014, 5:15 AM
We meant that you should extend Ext.Net.MVC.ColumnAttribute for Text localization

macroe
Jan 04, 2014, 10:13 AM
We meant that you should extend Ext.Net.MVC.ColumnAttribute for Text localization

oh, i get it ,thank you!

and, i changed the source code Ext.Net\MVC\Ext\Grid\GridPanel.cs , 163 row to


//column.Text = Regex.Replace(propertyMetadata.PropertyName, "([a-z])([A-Z])", "$1 $2");
if (!string.IsNullOrEmpty(propertyMetadata.DisplayNam e))
{
column.Text = propertyMetadata.DisplayName;
}
else
{
column.Text = Regex.Replace(propertyMetadata.PropertyName, "([a-z])([A-Z])", "$1 $2");
}

it work fine!

Daniil
Jan 10, 2014, 11:13 AM
A nice tweak! It has been committed to SVN in the revision #5601. It will go to the v2.5 release.

Daniil
Mar 31, 2014, 11:51 PM
Needs similar changes in other classes:
http://forums.ext.net/showthread.php?30791