@@ -37,30 +37,40 @@ public JsonResult MyActionResult([ModelBinder(typeof(DataTablesBinder)] IDataTab
3737 return Json (new DataTablesResponse (requestModel .Draw , paged , myFilteredData .Count (), myOriginalDataSet .Count ()));
3838}
3939```
40- < h3 > What about ordering ? < / h3 >
40+ < h3 > What about filtering / ordering ? < / h3 >
4141< p >
4242 It 's a no brainer too.
4343< / p >
4444< p >
4545 Filter / sort info from each column is , well , included on each column .
4646< / p >
4747< p >
48- To help you out , get only the columns which were ordered on client - side with < code > IDataTablesRequest .GetSortedColumns ()< / code > .
49- Than , iterate through then and use < code > Column .SortDirection < / code > to sort your dataset .
48+ To help you out , there are two methods on < code > ColumnCollection < / code > to help you out :< br / >
49+ < code > IDataTablesRequest .Columns .GetSortedColumns ()< / code > will return an ordered enumeration of sorted columns .< br / >
50+ < code > IDataTablesRequest .Columns .GetFilteredColumns ()< / code > will return an enumeration of columns which were actually filtered on client - side .
5051< / p >
5152< p >
5253 Sample :
5354< / p >
5455```C #
56+ // Apply filter to your dataset based only on the columns that actually have a search value.
5557var filteredColumns = requestParameters .Columns .GetFilteredColumns ();
5658foreach (var column in filteredColumns )
5759 Filter (column .Data , column .Search .Value , column .Search .IsRegexValue );
5860
61+
62+ // Set your dataset on the same order as requested from client-side either directly on your SQL code or easily
63+ // into any type or enumeration.
5964var sortedColumns = requestParameters .Columns .GetSortedColumns ();
6065var isSorted = false ;
6166foreach (var column in sortedColumns )
6267{
6368 if (! isSorted ) { Sort (column .Data , column .SortDirection ); isSorted = true ; }
6469 else { SortAgain (column .Data , column .SortDirection ); }
6570}
66- ```
71+ ```
72+
73+ < h3 > Any issues ? < / h3 >
74+ < p >
75+ If you do find any issues , please , submit then and I 'll fix it ASAP.
76+ < / p >
0 commit comments