Skip to content

Commit

Permalink
Added DataTableExclude attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mcintyre321 committed Sep 23, 2014
1 parent b814e52 commit c54d55f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs
Expand Up @@ -87,6 +87,9 @@ public class UserView

public Numbers Number { get; set; }

[DataTablesExclude]
public string ThisColumnIsExcluded { get { return "asdf"; } }


}

Expand Down
13 changes: 13 additions & 0 deletions Mvc.JQuery.Datatables/DataTablesExcludeAttribute.cs
@@ -0,0 +1,13 @@
using System;

namespace Mvc.JQuery.Datatables
{
/// <summary>
/// Prevent a public property from being included as a column in a DataTable row model
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public class DataTablesExcludeAttribute : Attribute
{

}
}
1 change: 1 addition & 0 deletions Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj
Expand Up @@ -78,6 +78,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataTablesExcludeAttribute.cs" />
<Compile Include="DataTablesFiltering.cs" />
<Compile Include="DataTablesFilterAttribute.cs" />
<Compile Include="LengthMenuVm.cs" />
Expand Down
1 change: 1 addition & 0 deletions Mvc.JQuery.Datatables/Reflection/DataTablesTypeInfo.cs
Expand Up @@ -15,6 +15,7 @@ internal static DataTablesPropertyInfo[] Properties(Type type)
return propertiesCache.GetOrAdd(type, t =>
{
var infos = from pi in t.GetProperties()
where pi.GetCustomAttribute<DataTablesExcludeAttribute>() == null
let attributes = (pi.GetCustomAttributes()).OfType<DataTablesAttributeBase>().ToArray()
orderby attributes.OfType<DataTablesAttribute>().Select(a => a.Order as int?).SingleOrDefault() ?? int.MaxValue
select new DataTablesPropertyInfo(pi, attributes);
Expand Down

0 comments on commit c54d55f

Please sign in to comment.