This is a migrated thread and some comments may be shown as answers.
Force a filter numeric filter on string column
3 Answers 17 Views
This is a migrated thread and some comments may be shown as answers.
Romero
Top achievements
Rank 1
Romero asked on 13 Apr 2020, 07:56 PM

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);
    }
}
...

3 Answers, 1 is accepted

Sort by
0
Romero
Top achievements
Rank 1
answered on 13 Apr 2020, 08:02 PM
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));
0
Romero
Top achievements
Rank 1
answered on 14 Apr 2020, 06:56 PM
I fixed this problem by using a ClientTemplate in the original decimal column
0
Ianko
Telerik team
answered on 15 Apr 2020, 10:08 AM

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.
Tags
Grid
Asked by
Romero
Top achievements
Rank 1
Answers by
Romero
Top achievements
Rank 1
Ianko
Telerik team
Share this question
or