diff --git a/appveyor.yml b/appveyor.yml index a9050d9..569e2ca 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.0.3 +version: 2.1.0 environment: nuget_token: diff --git a/samples/NooBIT.DataTables.Sample/Model/SampleData.cs b/samples/NooBIT.DataTables.Sample/Model/SampleData.cs index 9bb1a92..d88468e 100644 --- a/samples/NooBIT.DataTables.Sample/Model/SampleData.cs +++ b/samples/NooBIT.DataTables.Sample/Model/SampleData.cs @@ -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; } } } \ No newline at end of file diff --git a/src/NooBIT.DataTables/Attributes/ColumnOrderAttribute.cs b/src/NooBIT.DataTables/Attributes/ColumnOrderAttribute.cs new file mode 100644 index 0000000..4be485d --- /dev/null +++ b/src/NooBIT.DataTables/Attributes/ColumnOrderAttribute.cs @@ -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; } + } +} diff --git a/src/NooBIT.DataTables/DataTable.cs b/src/NooBIT.DataTables/DataTable.cs index 8c2341c..4e21a5d 100644 --- a/src/NooBIT.DataTables/DataTable.cs +++ b/src/NooBIT.DataTables/DataTable.cs @@ -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; @@ -159,8 +160,9 @@ private IEnumerable 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()?.Order ?? int.MaxValue) .Select(GetColumnTemplate) .ToArray();