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

Commit

Permalink
Improved sample code.
Browse files Browse the repository at this point in the history
Improved sample code.

Added request to submit issues on the project.
  • Loading branch information
ALMMa committed Mar 20, 2014
1 parent 2848fa2 commit 0416ba4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,40 @@ public JsonResult MyActionResult([ModelBinder(typeof(DataTablesBinder)] IDataTab
return Json(new DataTablesResponse(requestModel.Draw, paged, myFilteredData.Count(), myOriginalDataSet.Count()));
}
```
<h3>What about ordering?</h3>
<h3>What about filtering/ordering?</h3>
<p>
It's a no brainer too.
</p>
<p>
Filter/sort info from each column is, well, included on each column.
</p>
<p>
To help you out, get only the columns which were ordered on client-side with <code>IDataTablesRequest.GetSortedColumns()</code>.
Than, iterate through then and use <code>Column.SortDirection</code> to sort your dataset.
To help you out, there are two methods on <code>ColumnCollection</code> to help you out:<br />
<code>IDataTablesRequest.Columns.GetSortedColumns()</code> will return an ordered enumeration of sorted columns.<br />
<code>IDataTablesRequest.Columns.GetFilteredColumns()</code> will return an enumeration of columns which were actually filtered on client-side.
</p>
<p>
Sample:
</p>
```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)
{
if (!isSorted) { Sort(column.Data, column.SortDirection); isSorted = true; }
else { SortAgain(column.Data, column.SortDirection); }
}
```
```

<h3>Any issues?</h3>
<p>
If you do find any issues, please, submit then and I'll fix it ASAP.
</p>

0 comments on commit 0416ba4

Please sign in to comment.