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

[Solved] Grid Pivot + Edit

1 Answer 206 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.
Aalano
Top achievements
Rank 1
Aalano asked on 08 Aug 2010, 10:18 PM
Hello, I've been attempting to do a pivot using the mvc grid and have finally succeeded, however one further issue that came up was supporting edit at the same time.  

I finally tracked down the issue to the fact that on the client side when you do an edit, it retrieves the current value for a column using the member property (on the column definition.)

This presents a bit of an issue for a pivot though because the name of the member for a pivot always evaluates to the final property/field accessor....

I was wondering if there were plans to add a method to GridBuilder<T> to facilitate overriding the clientside member column property.  (I've done a workaround for this in my current code as below

public static class ViewComponentFactoryExtensions
    {
        public static PivotGridBuilder<T> PivotGrid<T>(this ViewComponentFactory componentFactory, IEnumerable<T> dataSource)
            where T : class
        {
            return new PivotGridBuilder<T>(componentFactory.Grid(dataSource));
        }
    }
    public class PivotGridBuilder<T> : GridBuilder<T>
        where T : class
    {
        public PivotGridBuilder(Grid<T> component) : base(component)
        {
        }
        public PivotGridBuilder<T> PivotColumns(Action<PivotGridColumnFactory<T>> configurator)
        {
            configurator(new PivotGridColumnFactory<T>(Component));
            return this;
        }
    }
    public class PivotGridColumnFactory<TModel> : GridColumnFactory<TModel>
        where TModel : class
    {
        public PivotGridColumnFactory(Grid<TModel> container) : base(container)
        {
            Container = container;
        }
        private Grid<TModel> Container { get; set; }
        public GridBoundColumnBuilder<TModel> Bound<TValue>(string memberName, System.Linq.Expressions.Expression<Func<TModel,TValue>> expression)
        {
            var columnBuilder = base.Bound(expression);
            var column = Container.Columns[Container.Columns.Count - 1];
            column.Member = memberName;
            return columnBuilder;
        }
    }

1 Answer, 1 is accepted

Sort by
0
Developix
Top achievements
Rank 1
answered on 08 Feb 2011, 11:05 AM
Hi Aalano,
thanx for your post. Can you provide us more information on how you solved the pivot problem?

Which view model did you use?

Actually we are pivoting our data in a stored procedure and giving the grid an old fashion DataTable.
But we are not very happy with our solution...
Tags
Grid
Asked by
Aalano
Top achievements
Rank 1
Answers by
Developix
Top achievements
Rank 1
Share this question
or