From 0416ba4d6d5c51d7fe4581d429c30c18f0fb5ad1 Mon Sep 17 00:00:00 2001 From: ALMMa Date: Wed, 19 Mar 2014 23:13:17 -0300 Subject: [PATCH] Improved sample code. Improved sample code. Added request to submit issues on the project. --- README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 86f0472..5bf2d93 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ public JsonResult MyActionResult([ModelBinder(typeof(DataTablesBinder)] IDataTab return Json(new DataTablesResponse(requestModel.Draw, paged, myFilteredData.Count(), myOriginalDataSet.Count())); } ``` -

What about ordering?

+

What about filtering/ordering?

It's a no brainer too.

@@ -45,17 +45,22 @@ public JsonResult MyActionResult([ModelBinder(typeof(DataTablesBinder)] IDataTab Filter/sort info from each column is, well, included on each column.

- To help you out, get only the columns which were ordered on client-side with IDataTablesRequest.GetSortedColumns(). - Than, iterate through then and use Column.SortDirection to sort your dataset. + To help you out, there are two methods on ColumnCollection to help you out:
+ IDataTablesRequest.Columns.GetSortedColumns() will return an ordered enumeration of sorted columns.
+ IDataTablesRequest.Columns.GetFilteredColumns() will return an enumeration of columns which were actually filtered on client-side.

Sample:

```C# +// Apply filter to your dataset based only on the columns that actually have a search value. var filteredColumns = requestParameters.Columns.GetFilteredColumns(); foreach(var column in filteredColumns) Filter(column.Data, column.Search.Value, column.Search.IsRegexValue); + +// Set your dataset on the same order as requested from client-side either directly on your SQL code or easily +// into any type or enumeration. var sortedColumns = requestParameters.Columns.GetSortedColumns(); var isSorted = false; foreach(var column in sortedColumns) @@ -63,4 +68,9 @@ foreach(var column in sortedColumns) if (!isSorted) { Sort(column.Data, column.SortDirection); isSorted = true; } else { SortAgain(column.Data, column.SortDirection); } } -``` \ No newline at end of file +``` + +

Any issues?

+

+ If you do find any issues, please, submit then and I'll fix it ASAP. +

\ No newline at end of file