This is a migrated thread and some comments may be shown as answers.

[Solved] Apply initial FilterDescriptor

4 Answers 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vinicius
Top achievements
Rank 1
Vinicius asked on 16 Nov 2011, 04:01 PM
Is there any way to apply initial FilterDescriptor?

here is what I'm trying to do:

public static GridBuilder<T> ApplyCommand<T>(this GridBuilder<T> grid, GridCommand command)
        where T : class
{
    if (command == null)
        return grid;

    if (command.SortDescriptors.Count > 0 && command.SortDescriptors[0].SortDirection == ListSortDirection.Ascending)
    {
        grid.Sortable(x => x.OrderBy(y => y.Add(command.SortDescriptors[0].Member)));
    }

    if (command.Page > 0)
    {
        grid.Pageable(x => x.PageTo(command.Page));
    }

    foreach (IFilterDescriptor item in command.FilterDescriptors)
    {
        // TODO initialize grid filtering
    }

    return grid;
}

4 Answers, 1 is accepted

Sort by
0
Vinicius
Top achievements
Rank 1
answered on 17 Nov 2011, 02:11 AM
Here are some improvements that I've made, but I still don't know how to apply the FilterDescriptor.

private static GridBuilder<T> ApplyCommand<T>(this GridBuilder<T> grid, GridCommand command)
        where T : class
{
    if (command == null)
        return grid;

    foreach (SortDescriptor sort in command.SortDescriptors)
    {
        if (sort.SortDirection == ListSortDirection.Ascending)
        {
            grid.Sortable(x => x.OrderBy(y => y.Add(sort.Member)));
        }
        else
        {
            grid.Sortable(x => x.OrderBy(y => y.Add(sort.Member).Descending()));
        }
    }

    List<FilterDescriptor> descriptors = new List<FilterDescriptor>();
    foreach (IFilterDescriptor item in command.FilterDescriptors)
    {
        descriptors.AddFilterDescriptor(item);
    }

    foreach (FilterDescriptor filter in descriptors)
    {
//TODO
    }

    if (command.Page > 0)
    {
        grid.Pageable(x => x.PageTo(command.Page));
    }

    return grid;
}
0
Vinicius
Top achievements
Rank 1
answered on 17 Nov 2011, 12:52 PM
I wrote a prototype. It is creating the expression and adding it to the grid filter, but the grid is not getting filtered. Does anyone knows why?

            List<FilterDescriptor> descriptors = new List<FilterDescriptor>();
            foreach (IFilterDescriptor item in command.FilterDescriptors)
            {
                descriptors.AddFilterDescriptor(item);
            }

            foreach (FilterDescriptor filter in descriptors)
            {
                if (filter.Operator == FilterOperator.Contains)
                {
                    Expression<Func<T, string>> f = (param) => param.GetPropertyValue(filter.Member) as string;
                    grid.Filterable(x => x.Filters(y => y.Add(f).Contains(filter.Value as string)));
                }
            }
0
Vinicius
Top achievements
Rank 1
answered on 17 Nov 2011, 07:31 PM
Here is the solution:

ParameterExpression p = Expression.Parameter(typeof(T));
var exp = Expression.Lambda<Func<T, string>>(Expression.Property(p, filter.Member), p);
grid.Filterable(x => x.Filters(y => y.Add(exp).Contains(filter.Value.ToString())));
0
Vijay
Top achievements
Rank 1
answered on 01 Jun 2013, 11:53 AM
can you please provide me a sample how did you apply initial FilterDescriptor to Telerik MVC Grid?

Let me tell you, what am I trying for.

I want to save grid columns's positions , column's size , grid's page size , filter by, sort by in database as profile and when user change profile and click on 'Load' button. The grid would take data from the database and set the grid.

Any help would be appreciated!!!

Thanks,
Vijay Panchal
Tags
Grid
Asked by
Vinicius
Top achievements
Rank 1
Answers by
Vinicius
Top achievements
Rank 1
Vijay
Top achievements
Rank 1
Share this question
or