Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dynamic creation of search predicates using provider expressions #21

Merged
merged 2 commits into from
Jul 10, 2020

Conversation

Namoshek
Copy link
Owner

This PR introduces three new properties on the DataTablesColumn class:

  • SearchPredicateProvider for SearchPredicate
  • ColumnSearchPredicateProvider for ColumnSearchPredicate
  • GlobalSearchPredicateProvider for GlobalSearchPredicate

Each of them can be used to create the respective search predicate dynamically using the search term as input. This is for example useful when receiving search input which needs to be transformed (e.g. tokenized, split, normalized, ...) before it can be used within the search predicate.

An example, as written in the README, which splits the search input to perform numeric range search, would be:

ColumnSearchPredicateProvider = (s) =>
{
    var minMax = s.Split("-delim-", System.StringSplitOptions.RemoveEmptyEntries);
    if (minMax.Length >= 2)
    {
        var min = long.Parse(minMax[0]);
        var max = long.Parse(minMax[1]);

        return (p, s) => p.Id >= min && p.Id <= max;
    }

    return (p, s) => false;
}

Namoshek added 2 commits July 10, 2020 18:48
The advantage of search predicate providers over search predicates is that the search value may be manipulated and baked into the search predicate more easily.
@Namoshek Namoshek merged commit 071ac3e into master Jul 10, 2020
@Namoshek Namoshek deleted the feature-search-predicate-provider branch July 10, 2020 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant