Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion DataTablesParser/DatatablesParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ public class DataTablesParser<T> where T : class
* string: sEcho - Information for DataTables to use for rendering
*/

private const string INDIVIDUAL_DATA_KEY_PREFIX = "mDataProp_";
private const string INDIVIDUAL_SEARCH_KEY_PREFIX = "sSearch_";
private const string INDIVIDUAL_SEARCHABLE_KEY_PREFIX = "bSearchable_";
private const string INDIVIDUAL_SORT_KEY_PREFIX = "iSortCol_";
private const string INDIVIDUAL_SORT_DIRECTION_KEY_PREFIX = "sSortDir_";
private const string DISPLAY_START = "iDisplayStart";
Expand Down Expand Up @@ -315,9 +317,32 @@ private Expression<Func<T, bool>> ApplyGenericSearch

List<MethodCallExpression> searchProps = new List<MethodCallExpression>();

var dataNumbers = new Dictionary<int, string>();

foreach (string key in _httpRequest.Params.AllKeys.Where(x => x.StartsWith(INDIVIDUAL_DATA_KEY_PREFIX)))
{
// parse the property number
var property = -1;

var propertyString = key.Replace(INDIVIDUAL_DATA_KEY_PREFIX, string.Empty);

if ((!int.TryParse(propertyString, out property))
|| property >= _properties.Length || string.IsNullOrEmpty(key))
break; // ignore if the option is invalid

dataNumbers.Add(property, _httpRequest[key]);
}

foreach (var prop in _properties)
{
if(!prop.CanWrite){ continue; }
var searchable = INDIVIDUAL_SEARCHABLE_KEY_PREFIX
+ dataNumbers.Where(d => d.Value == prop.Name).Select(d => d.Key).FirstOrDefault();

bool isSearchable;

bool.TryParse(_httpRequest[searchable], out isSearchable);

if (!prop.CanWrite || !isSearchable) { continue; }

Expression stringProp = null;

Expand Down