diff --git a/Mvc.JQuery.Datatables.Example/App_GlobalResources/UserViewResource.Designer.cs b/Mvc.JQuery.Datatables.Example/App_GlobalResources/UserViewResource.Designer.cs new file mode 100644 index 0000000..e3b6bf6 --- /dev/null +++ b/Mvc.JQuery.Datatables.Example/App_GlobalResources/UserViewResource.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.17929 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option or rebuild the Visual Studio project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Web.Application.StronglyTypedResourceProxyBuilder", "11.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class UserViewResource { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal UserViewResource() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Resources.UserViewResource", global::System.Reflection.Assembly.Load("App_GlobalResources")); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Full name from resource file. + /// + internal static string Name { + get { + return ResourceManager.GetString("Name", resourceCulture); + } + } + } +} diff --git a/Mvc.JQuery.Datatables.Example/App_GlobalResources/UserViewResource.resx b/Mvc.JQuery.Datatables.Example/App_GlobalResources/UserViewResource.resx new file mode 100644 index 0000000..52fcae7 --- /dev/null +++ b/Mvc.JQuery.Datatables.Example/App_GlobalResources/UserViewResource.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Full name from resource file + + \ No newline at end of file diff --git a/Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs b/Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs index 54730fd..97a1bc7 100644 --- a/Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs +++ b/Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs @@ -4,8 +4,9 @@ using System.Globalization; using System.Linq; using System.Web; -using System.Web.Mvc; - +using System.Web.Mvc; +using Resources; + namespace Mvc.JQuery.Datatables.Example.Controllers { public class HomeController : Controller @@ -52,13 +53,13 @@ public DataTablesResult GetUsers(DataTablesParam dataTableParam) public class UserView { - [DataTables(DisplayName = "Full Name", MRenderFunction = "test")] + [DataTables(DisplayName = "Name", DisplayNameResourceType = typeof(UserViewResource), MRenderFunction = "test")] public string Name { get; set; } [DataTables(SortDirection = SortDirection.Ascending, Order = 0)] public int Id { get; set; } - [DataTables(Searchable = false)] + [DataTables(DisplayName = "E-Mail", Searchable = false)] public string Email { get; set; } [DataTables( Sortable = false)] diff --git a/Mvc.JQuery.Datatables.Example/Mvc.JQuery.Datatables.Example.csproj b/Mvc.JQuery.Datatables.Example/Mvc.JQuery.Datatables.Example.csproj index f4a762a..50e1c6f 100644 --- a/Mvc.JQuery.Datatables.Example/Mvc.JQuery.Datatables.Example.csproj +++ b/Mvc.JQuery.Datatables.Example/Mvc.JQuery.Datatables.Example.csproj @@ -1,654 +1,665 @@ - - - - - Debug - AnyCPU - - - 2.0 - {476D3266-8699-4E89-A528-646C1235EEB1} - {E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} - Library - Properties - Mvc.JQuery.Datatables.Example - Mvc.JQuery.Datatables.Example - v4.0 - false - false - - - - - 4.0 - - - - - ..\ - true - - - true - full - false - bin\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\ - TRACE - prompt - 4 - - - - ..\packages\EmbeddedResourceVirtualPathProvider.1.2.5\lib\net40\EmbeddedResourceVirtualPathProvider.dll - - - True - ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Global.asax - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Web.config - - - Web.config - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {389ADE94-7C32-4885-812E-68A2A74C82D8} - Mvc.JQuery.Datatables - - - - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - + + + + + Debug + AnyCPU + + + 2.0 + {476D3266-8699-4E89-A528-646C1235EEB1} + {E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + Mvc.JQuery.Datatables.Example + Mvc.JQuery.Datatables.Example + v4.0 + false + false + + + + + 4.0 + + + + + ..\ + true + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + ..\packages\EmbeddedResourceVirtualPathProvider.1.2.5\lib\net40\EmbeddedResourceVirtualPathProvider.dll + + + True + ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + True + UserViewResource.resx + + + + + + Global.asax + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Web.config + + + Web.config + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {389ADE94-7C32-4885-812E-68A2A74C82D8} + Mvc.JQuery.Datatables + + + + + GlobalResourceProxyGenerator + UserViewResource.Designer.cs + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + - - - - - - - - False - True - 53281 - / - - - False - False - - - False - - - - - + --> + + + + + + + + False + True + 53281 + / + + + False + False + + + False + + + + + \ No newline at end of file diff --git a/Mvc.JQuery.Datatables/DataTablesHelper.cs b/Mvc.JQuery.Datatables/DataTablesHelper.cs index 05123f7..17a1851 100644 --- a/Mvc.JQuery.Datatables/DataTablesHelper.cs +++ b/Mvc.JQuery.Datatables/DataTablesHelper.cs @@ -60,7 +60,7 @@ public static ColDef[] ColDefs() columnList.Add(new ColDef(pi.Item1.PropertyType) { Name = pi.Item1.Name, - DisplayName = pi.Item2.DisplayName ?? pi.Item1.Name, + DisplayName = pi.Item2.ToDisplayName() ?? pi.Item1.Name, Sortable = pi.Item2.Sortable, Visible = pi.Item2.Visible, Searchable = pi.Item2.Searchable, diff --git a/Mvc.JQuery.Datatables/DataTablesTypeInfo.cs b/Mvc.JQuery.Datatables/DataTablesTypeInfo.cs index a101d77..7653b17 100644 --- a/Mvc.JQuery.Datatables/DataTablesTypeInfo.cs +++ b/Mvc.JQuery.Datatables/DataTablesTypeInfo.cs @@ -5,7 +5,18 @@ using System.Reflection; namespace Mvc.JQuery.Datatables -{ +{ + public static class DataTablesTypeInfoHelper + { + public static string ToDisplayName(this DataTablesAttribute attribute) + { + if (string.IsNullOrEmpty(attribute.DisplayName) || attribute.DisplayNameResourceType == null) + return attribute.DisplayName; + var value = ResourceHelper.GetResourceLookup(attribute.DisplayNameResourceType, attribute.DisplayName); + return value; + } + } + public static class DataTablesTypeInfo { public static DataTablesPropertyInfo[] Properties { get; private set; } @@ -28,7 +39,9 @@ public static Dictionary ToDictionary(T row) } return dictionary; } - } + } + + public class DataTablesPropertyInfo { @@ -56,7 +69,8 @@ public DataTablesAttribute() public bool Searchable { get; set; } public bool Sortable { get; set; } public int Order { get; set; } - public string DisplayName { get; set; } + public string DisplayName { get; set; } + public Type DisplayNameResourceType { get; set; } public SortDirection SortDirection { get; set; } public string MRenderFunction { get; set; } diff --git a/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj b/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj index 0ab2651..b1e7b3b 100644 --- a/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj +++ b/Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj @@ -1,214 +1,215 @@ - - - - Debug - AnyCPU - 8.0.30703 - 2.0 - {389ADE94-7C32-4885-812E-68A2A74C82D8} - Library - Properties - Mvc.JQuery.Datatables - Mvc.JQuery.Datatables - v4.0 - 512 - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - ..\packages\Newtonsoft.Json.5.0.8\lib\net40\Newtonsoft.Json.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Views\Shared\DataTable.cshtml - - - - - - - - - - - Content\DataTables\media\css\jquery.dataTables.css - - - Content\DataTables\media\css\jquery.dataTables_themeroller.css - - - - - Content\DataTables\extras\TableTools\media\css\TableTools.css - - - Content\DataTables\extras\TableTools\media\css\TableTools_JUI.css - - - - - Content\DataTables\extras\TableTools\media\images\background.png - - - Content\DataTables\extras\TableTools\media\images\collection.png - - - Content\DataTables\extras\TableTools\media\images\collection_hover.png - - - Content\DataTables\extras\TableTools\media\images\copy.png - - - Content\DataTables\extras\TableTools\media\images\copy_hover.png - - - Content\DataTables\extras\TableTools\media\images\csv.png - - - Content\DataTables\extras\TableTools\media\images\csv_hover.png - - - Content\DataTables\extras\TableTools\media\images\pdf.png - - - Content\DataTables\extras\TableTools\media\images\pdf_hover.png - - - Content\DataTables\extras\TableTools\media\images\print.png - - - Content\DataTables\extras\TableTools\media\images\print_hover.png - - - Content\DataTables\extras\TableTools\media\images\xls.png - - - Content\DataTables\extras\TableTools\media\images\xls_hover.png - - - - - Content\DataTables\extras\TableTools\media\js\TableTools.js - - - Content\DataTables\extras\TableTools\media\js\TableTools.min.js - - - Content\DataTables\extras\TableTools\media\js\ZeroClipboard.js - - - - - Content\DataTables\media\js\jquery.dataTables.js - - - Content\DataTables\media\js\jquery.dataTables.min.js - - - - - Content\jquery.dataTables.columnFilter.js - - - - - Content\DataTables\media\images\back_disabled.png - - - Content\DataTables\media\images\back_enabled.png - - - Content\DataTables\media\images\back_enabled_hover.png - - - Content\DataTables\media\images\forward_disabled.png - - - Content\DataTables\media\images\forward_enabled.png - - - Content\DataTables\media\images\forward_enabled_hover.png - - - Content\DataTables\media\images\sort_asc.png - - - Content\DataTables\media\images\sort_asc_disabled.png - - - Content\DataTables\media\images\sort_both.png - - - Content\DataTables\media\images\sort_desc.png - - - Content\DataTables\media\images\sort_desc_disabled.png - - - - - Content\DataTables\extras\TableTools\media\swf\copy_csv_xls.swf - - - Content\DataTables\extras\TableTools\media\swf\copy_csv_xls_pdf.swf - - - - + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {389ADE94-7C32-4885-812E-68A2A74C82D8} + Library + Properties + Mvc.JQuery.Datatables + Mvc.JQuery.Datatables + v4.0 + 512 + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + ..\packages\Newtonsoft.Json.5.0.8\lib\net40\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Views\Shared\DataTable.cshtml + + + + + + + + + + + Content\DataTables\media\css\jquery.dataTables.css + + + Content\DataTables\media\css\jquery.dataTables_themeroller.css + + + + + Content\DataTables\extras\TableTools\media\css\TableTools.css + + + Content\DataTables\extras\TableTools\media\css\TableTools_JUI.css + + + + + Content\DataTables\extras\TableTools\media\images\background.png + + + Content\DataTables\extras\TableTools\media\images\collection.png + + + Content\DataTables\extras\TableTools\media\images\collection_hover.png + + + Content\DataTables\extras\TableTools\media\images\copy.png + + + Content\DataTables\extras\TableTools\media\images\copy_hover.png + + + Content\DataTables\extras\TableTools\media\images\csv.png + + + Content\DataTables\extras\TableTools\media\images\csv_hover.png + + + Content\DataTables\extras\TableTools\media\images\pdf.png + + + Content\DataTables\extras\TableTools\media\images\pdf_hover.png + + + Content\DataTables\extras\TableTools\media\images\print.png + + + Content\DataTables\extras\TableTools\media\images\print_hover.png + + + Content\DataTables\extras\TableTools\media\images\xls.png + + + Content\DataTables\extras\TableTools\media\images\xls_hover.png + + + + + Content\DataTables\extras\TableTools\media\js\TableTools.js + + + Content\DataTables\extras\TableTools\media\js\TableTools.min.js + + + Content\DataTables\extras\TableTools\media\js\ZeroClipboard.js + + + + + Content\DataTables\media\js\jquery.dataTables.js + + + Content\DataTables\media\js\jquery.dataTables.min.js + + + + + Content\jquery.dataTables.columnFilter.js + + + + + Content\DataTables\media\images\back_disabled.png + + + Content\DataTables\media\images\back_enabled.png + + + Content\DataTables\media\images\back_enabled_hover.png + + + Content\DataTables\media\images\forward_disabled.png + + + Content\DataTables\media\images\forward_enabled.png + + + Content\DataTables\media\images\forward_enabled_hover.png + + + Content\DataTables\media\images\sort_asc.png + + + Content\DataTables\media\images\sort_asc_disabled.png + + + Content\DataTables\media\images\sort_both.png + + + Content\DataTables\media\images\sort_desc.png + + + Content\DataTables\media\images\sort_desc_disabled.png + + + + + Content\DataTables\extras\TableTools\media\swf\copy_csv_xls.swf + + + Content\DataTables\extras\TableTools\media\swf\copy_csv_xls_pdf.swf + + + + + --> \ No newline at end of file diff --git a/Mvc.JQuery.Datatables/ResourceHelper.cs b/Mvc.JQuery.Datatables/ResourceHelper.cs new file mode 100644 index 0000000..46c5982 --- /dev/null +++ b/Mvc.JQuery.Datatables/ResourceHelper.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace Mvc.JQuery.Datatables +{ + public class ResourceHelper + { + public static T GetResourceLookup(Type resourceType, string resourceName) + { + if ((resourceType != null) && (resourceName != null)) + { + PropertyInfo property = resourceType.GetProperty(resourceName, BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic); + if (property == null) + { + return default(T); + } + + return (T)property.GetValue(null, null); + } + return default(T); + } + } +}