Skip to content

Commit c54d55f

Browse files
committed
Added DataTableExclude attribute
1 parent b814e52 commit c54d55f

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public class UserView
8787

8888
public Numbers Number { get; set; }
8989

90+
[DataTablesExclude]
91+
public string ThisColumnIsExcluded { get { return "asdf"; } }
92+
9093

9194
}
9295

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace Mvc.JQuery.Datatables
4+
{
5+
/// <summary>
6+
/// Prevent a public property from being included as a column in a DataTable row model
7+
/// </summary>
8+
[AttributeUsage(AttributeTargets.Property)]
9+
public class DataTablesExcludeAttribute : Attribute
10+
{
11+
12+
}
13+
}

Mvc.JQuery.Datatables/Mvc.JQuery.Datatables.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<Reference Include="System.Xml" />
7979
</ItemGroup>
8080
<ItemGroup>
81+
<Compile Include="DataTablesExcludeAttribute.cs" />
8182
<Compile Include="DataTablesFiltering.cs" />
8283
<Compile Include="DataTablesFilterAttribute.cs" />
8384
<Compile Include="LengthMenuVm.cs" />

Mvc.JQuery.Datatables/Reflection/DataTablesTypeInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal static DataTablesPropertyInfo[] Properties(Type type)
1515
return propertiesCache.GetOrAdd(type, t =>
1616
{
1717
var infos = from pi in t.GetProperties()
18+
where pi.GetCustomAttribute<DataTablesExcludeAttribute>() == null
1819
let attributes = (pi.GetCustomAttributes()).OfType<DataTablesAttributeBase>().ToArray()
1920
orderby attributes.OfType<DataTablesAttribute>().Select(a => a.Order as int?).SingleOrDefault() ?? int.MaxValue
2021
select new DataTablesPropertyInfo(pi, attributes);

0 commit comments

Comments
 (0)