Skip to content

Commit 1c19ffb

Browse files
committed
Merge pull request #6 from mistanorbo/master
Adding support for bSearchable parameter.
2 parents 35f3b49 + 7f54fe0 commit 1c19ffb

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

DataTablesParser/DatatablesParser.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public class DataTablesParser<T> where T : class
3434
* string: sEcho - Information for DataTables to use for rendering
3535
*/
3636

37+
private const string INDIVIDUAL_DATA_KEY_PREFIX = "mDataProp_";
3738
private const string INDIVIDUAL_SEARCH_KEY_PREFIX = "sSearch_";
39+
private const string INDIVIDUAL_SEARCHABLE_KEY_PREFIX = "bSearchable_";
3840
private const string INDIVIDUAL_SORT_KEY_PREFIX = "iSortCol_";
3941
private const string INDIVIDUAL_SORT_DIRECTION_KEY_PREFIX = "sSortDir_";
4042
private const string DISPLAY_START = "iDisplayStart";
@@ -315,9 +317,32 @@ private Expression<Func<T, bool>> ApplyGenericSearch
315317

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

320+
var dataNumbers = new Dictionary<int, string>();
321+
322+
foreach (string key in _httpRequest.Params.AllKeys.Where(x => x.StartsWith(INDIVIDUAL_DATA_KEY_PREFIX)))
323+
{
324+
// parse the property number
325+
var property = -1;
326+
327+
var propertyString = key.Replace(INDIVIDUAL_DATA_KEY_PREFIX, string.Empty);
328+
329+
if ((!int.TryParse(propertyString, out property))
330+
|| property >= _properties.Length || string.IsNullOrEmpty(key))
331+
break; // ignore if the option is invalid
332+
333+
dataNumbers.Add(property, _httpRequest[key]);
334+
}
335+
318336
foreach (var prop in _properties)
319337
{
320-
if(!prop.CanWrite){ continue; }
338+
var searchable = INDIVIDUAL_SEARCHABLE_KEY_PREFIX
339+
+ dataNumbers.Where(d => d.Value == prop.Name).Select(d => d.Key).FirstOrDefault();
340+
341+
bool isSearchable;
342+
343+
bool.TryParse(_httpRequest[searchable], out isSearchable);
344+
345+
if (!prop.CanWrite || !isSearchable) { continue; }
321346

322347
Expression stringProp = null;
323348

0 commit comments

Comments
 (0)