@@ -37,30 +37,40 @@ public JsonResult MyActionResult([ModelBinder(typeof(DataTablesBinder)] IDataTab
37
37
return Json (new DataTablesResponse (requestModel .Draw , paged , myFilteredData .Count (), myOriginalDataSet .Count ()));
38
38
}
39
39
```
40
- < h3 > What about ordering ? < / h3 >
40
+ < h3 > What about filtering / ordering ? < / h3 >
41
41
< p >
42
42
It 's a no brainer too.
43
43
< / p >
44
44
< p >
45
45
Filter / sort info from each column is , well , included on each column .
46
46
< / p >
47
47
< 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 .
50
51
< / p >
51
52
< p >
52
53
Sample :
53
54
< / p >
54
55
```C #
56
+ // Apply filter to your dataset based only on the columns that actually have a search value.
55
57
var filteredColumns = requestParameters .Columns .GetFilteredColumns ();
56
58
foreach (var column in filteredColumns )
57
59
Filter (column .Data , column .Search .Value , column .Search .IsRegexValue );
58
60
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.
59
64
var sortedColumns = requestParameters .Columns .GetSortedColumns ();
60
65
var isSorted = false ;
61
66
foreach (var column in sortedColumns )
62
67
{
63
68
if (! isSorted ) { Sort (column .Data , column .SortDirection ); isSorted = true ; }
64
69
else { SortAgain (column .Data , column .SortDirection ); }
65
70
}
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