Skip to content

Commit

Permalink
add columnorder attribute for ordering properties on tabledata
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias.haimerl committed Nov 8, 2018
1 parent cd8c1df commit 1871603
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2.0.3
version: 2.1.0

environment:
nuget_token:
Expand Down
7 changes: 6 additions & 1 deletion samples/NooBIT.DataTables.Sample/Model/SampleData.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
namespace NooBIT.DataTables.Sample.Model
using NooBIT.DataTables.Attributes;

namespace NooBIT.DataTables.Sample.Model
{
public class SampleData
{
[ColumnOrder(0)]
public int Id { get; set; }

[ColumnOrder(1)]
public string Name { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/NooBIT.DataTables/Attributes/ColumnOrderAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace NooBIT.DataTables.Attributes
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class ColumnOrderAttribute : Attribute
{
public ColumnOrderAttribute(int order)
{
Order = order;
}

public int Order { get; }
}
}
6 changes: 4 additions & 2 deletions src/NooBIT.DataTables/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using NooBIT.DataTables.Attributes;
using NooBIT.DataTables.Helpers;
using NooBIT.DataTables.Models;
using NooBIT.DataTables.Queries;
Expand Down Expand Up @@ -159,8 +160,9 @@ private IEnumerable<SortInstruction> GenerateSortInstructions(DataTableRequest r

public Column[] Columns => _columns ?? (_columns = GetColumnsInternal());

protected virtual Column[] GetColumnsInternal() => typeof(T)
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
protected virtual Column[] GetColumnsInternal() =>
typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public)
.OrderBy(x => x.GetCustomAttribute<ColumnOrderAttribute>()?.Order ?? int.MaxValue)
.Select(GetColumnTemplate)
.ToArray();

Expand Down

0 comments on commit 1871603

Please sign in to comment.