Force a filter numeric filter on string column

4 posts, 0 answers
  1. Romero
    Romero avatar
    3 posts
    Member since:
    Apr 2020

    Posted 13 Apr 2020 Link to this post

    I have a grid where the filters are done in the server, directly in database. One of my columns is a string representation of a number, like this:

    public string NumberDisplay
    {
        get
        {
            if(Number == null)
                return "--";
            else
                return Number.Value.ToString("0.##");
        }
    }

    As this is a string, the grid will show the string filters (contains, starts with, etc). How can I force a numeric filter (greater than, less than, etc.) on a string column? This is how the filtering is done in the database (as a number, not as a string):

    case "NumberDisplay":
    {
        bool addQueryParam = true;
        string sql = null;
        switch (filter.Operator)
        {
            case GridFilterOperator.IsGreaterThan:
                sql = " and (@KendoNumber is not null and mm.Number is not null and mm.Number > @KendoNumber)";
                break;
                ...
        }
        if (addQueryParam)
        {
            queryBuilder.Where(sql);
            queryBuilder.AddParameter("KendoNumber", filterValue);
        }
    }
    ...
  2. Romero
    Romero avatar
    3 posts
    Member since:
    Apr 2020

    Posted 13 Apr 2020 in reply to Romero Link to this post

    Changinf the filter.UI will only alter the input and not the filter types
    c.Bound(b => b.NumberDisplay).Title("Number").Width(150).Filterable(filter => filter.UI(GridFilterUIRole.NumericTextBox));
  3. Romero
    Romero avatar
    3 posts
    Member since:
    Apr 2020

    Posted 14 Apr 2020 Link to this post

    I fixed this problem by using a ClientTemplate in the original decimal column
  4. Ianko
    Admin
    Ianko avatar
    1945 posts

    Posted 15 Apr 2020 Link to this post

    Hi Romero,

    The solution you have found is a valid one. I will close the ticket. 

    Regards,
    Ianko
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top