Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit bd2e4f0

Browse files
committed
Merge pull request #12 from phayman/master
Added a new method GetSortedColumnsExpression() to ColumnCollection, thanks to phayman.
2 parents 308fad6 + 93c3992 commit bd2e4f0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

DataTables.Mvc/ColumnCollection.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ public IEnumerable<Column> GetFilteredColumns()
7171
.Where(_column => !String.IsNullOrWhiteSpace(_column.Data) && _column.Searchable && !String.IsNullOrWhiteSpace(_column.Search.Value));
7272
}
7373
/// <summary>
74+
/// Get sorted columns on client-side already on the same order as the client requested.
75+
/// The method checks if the column is bound and if it's ordered on client-side.
76+
/// The returned expression can be used with the OrderBy(string sortExpression) extension mehod
77+
/// found here : http://extensionmethod.net/csharp/ienumerable-t/orderby-string-sortexpression
78+
/// </summary>
79+
/// <remarks>Added by phayman www.kwiboo.com</remarks>
80+
/// <returns>The ordered enumeration of sorted columns as an expression. e.g. "columnname asc, othercolumn desc"</returns>
81+
public string GetSortedColumnsExpression()
82+
{
83+
var sortExpression = new List<string>();
84+
foreach (var column in GetSortedColumns())
85+
{
86+
sortExpression.Add(column.Data + " " + (column.SortDirection == Column.OrderDirection.Descendant ? "desc" : "asc"));
87+
}
88+
89+
return String.Join(",", sortExpression.ToArray());
90+
}
91+
/// <summary>
7492
/// Returns the enumerable element as defined on IEnumerable.
7593
/// </summary>
7694
/// <returns>The enumerable elemento to iterate through data.</returns>

0 commit comments

Comments
 (0)