예제 #1
0
        private void CalculateAggregates()
        {
            if (aggregatesAreCalculated || bindingContext.EnableCustomBinding)
            {
                return;
            }

            if (bindingContext.DataSource == null)
            {
                aggregatesAreCalculated = true;
                return;
            }

            if (Aggregates.Any())
            {
                var dataSource = GetCustomDataSource(bindingContext.DataSource).AsQueryable();

                var source = dataSource;
                if (FilterDescriptors.Any())
                {
                    source = dataSource.Where(FilterDescriptors);
                }
                aggregatesResults       = source.Aggregate(Aggregates);
                aggregatesAreCalculated = true;
            }
        }
        public double GetCount()
        {
            if (!Aggregates.Any(agg => agg.Type == AggregatorType.COUNT))
            {
                throw new ApplicationException("Cannot get Count for Group");
            }

            return(Aggregates.FirstOrDefault(agg => agg.Type == AggregatorType.COUNT).Value);
        }
예제 #3
0
        private void EnsureDataSourceIsProcessed()
        {
            if (dataSourceIsProcessed)
            {
                return;
            }

            if (bindingContext.DataSource == null)
            {
                dataSourceIsProcessed = true;
                return;
            }

            if (!bindingContext.EnableCustomBinding)
            {
                GridModel model;

                if (GroupDescriptors.Any() && Aggregates.Any())
                {
                    GroupDescriptors.Each(g => g.AggregateFunctions.AddRange(Aggregates));
                }

                var dataTableEnumerable = bindingContext.DataSource as GridDataTableWrapper;
                if (dataTableEnumerable != null)
                {
                    model = dataTableEnumerable.ToGridModel(CurrentPage, PageSize, SortDescriptors, FilterDescriptors, GroupDescriptors);
                }
                else
                {
                    var dataSource = bindingContext.DataSource.AsQueryable();
                    model = dataSource.ToGridModel(CurrentPage, PageSize, SortDescriptors, FilterDescriptors, GroupDescriptors);
                }

                totalCount          = model.Total;
                processedDataSource = model.Data.AsGenericEnumerable();
            }
            else
            {
                processedDataSource = GetCustomDataSource(bindingContext.DataSource);
                totalCount          = bindingContext.Total;
            }

            dataSourceIsProcessed = true;
        }
예제 #4
0
        private GridRenderingData CreateRenderingData()
        {
            var renderingData = new GridRenderingData
            {
                TableHtmlAttributes = TableHtmlAttributes,
                DataKeyStore        = DataKeyStore,
                HtmlHelper          = new GridHtmlHelper <T>(ViewContext, DataKeyStore),
                UrlBuilder          = UrlBuilder,
                DataSource          = DataProcessor.ProcessedDataSource,
                Columns             = VisibleColumns.Cast <IGridColumn>(),
                GroupMembers        = DataProcessor.GroupDescriptors.Select(g => g.Member),
                Mode                   = CurrentItemMode,
                EditMode               = Editing.Mode,
                HasDetailView          = HasDetailView,
                Colspan                = Colspan - Columns.Count(column => column.Hidden),
                DetailViewTemplate     = MapDetailViewTemplate(HasDetailView ? DetailView.Template : null),
                NoRecordsTemplate      = FormatNoRecordsTemplate(),
                Localization           = Localization,
                ScrollingHeight        = Scrolling.Height,
                EditFormHtmlAttributes = Editing.FormHtmlAttributes,
                ShowFooter             = Footer && VisibleColumns.Any(c => c.FooterTemplate.HasValue() || c.ClientFooterTemplate.HasValue()),
                AggregateResults       = DataProcessor.AggregatesResults,
                Aggregates             = Aggregates.SelectMany(aggregate => aggregate.Aggregates),
                GroupsCount            = DataProcessor.GroupDescriptors.Count,
                ShowGroupFooter        = Aggregates.Any() && VisibleColumns.OfType <IGridBoundColumn>().Any(c => c.GroupFooterTemplate.HasValue()),
                PopUpContainer         = new HtmlFragment(),
#if MVC2 || MVC3
                CreateNewDataItem  = () => Editing.DefaultDataItem(),
                InsertRowPosition  = Editing.InsertRowPosition,
                EditTemplateName   = Editing.TemplateName,
                AdditionalViewData = Editing.AdditionalViewData,
                FormId             = ViewContext.FormContext.FormId,
#endif
                Callback = RowActionCallback
            };

            if (RowTemplate.HasValue())
            {
                renderingData.RowTemplate = (dataItem, container) => RowTemplate.Apply((T)dataItem, container);
            }

            return(renderingData);
        }
예제 #5
0
 private void MergeAggregateTypes(DataSourceRequest request)
 {
     if (Aggregates.Any())
     {
         foreach (var requestAggregate in request.Aggregates)
         {
             var match = Aggregates.SingleOrDefault(agg => agg.Member.Equals(requestAggregate.Member, StringComparison.InvariantCultureIgnoreCase));
             if (match != null)
             {
                 requestAggregate.Aggregates.Each(function =>
                 {
                     var innerFunction = match.Aggregates.SingleOrDefault(matchFunction => matchFunction.AggregateMethodName == function.AggregateMethodName);
                     if (innerFunction != null && innerFunction.MemberType != null)
                     {
                         function.MemberType = innerFunction.MemberType;
                     }
                 });
             }
         }
     }
 }
예제 #6
0
        protected override void Serialize(IDictionary <string, object> json)
        {
            if (Transport.Read.Url == null)
            {
                // If Url is not set assume the current url (used in server binding)
                Transport.Read.Url = "";
            }

            var transport = Transport.ToJson();

            if (transport.Keys.Any())
            {
                json["transport"] = transport;
            }

            if (PageSize > 0)
            {
                json["pageSize"] = PageSize;
                json["page"]     = Page;
                json["total"]    = Total;
            }

            if (ServerPaging)
            {
                json["serverPaging"] = ServerPaging;
            }

            if (ServerSorting)
            {
                json["serverSorting"] = ServerSorting;
            }

            if (ServerFiltering)
            {
                json["serverFiltering"] = ServerFiltering;
            }

            if (ServerGrouping)
            {
                json["serverGrouping"] = ServerGrouping;
            }

            if (ServerAggregates)
            {
                json["serverAggregates"] = ServerAggregates;
            }

            if (Type != null)
            {
                json["type"] = "aspnetmvc-" + Type.ToString().ToLower();
            }

            if (OrderBy.Any())
            {
                json["sort"] = OrderBy.ToJson();
            }

            if (Groups.Any())
            {
                json["group"] = Groups.ToJson();
            }

            if (Aggregates.Any())
            {
                json["aggregate"] = Aggregates.SelectMany(agg => agg.Aggregates.ToJson());
            }

            if (Filters.Any() || ServerFiltering)
            {
                json["filter"] = Filters.OfType <FilterDescriptorBase>().ToJson();
            }

            if (Events.Keys.Any())
            {
                json.Merge(Events);
            }

            json["schema"] = Schema.ToJson();

            if (Batch)
            {
                json["batch"] = Batch;
            }

            if (AutoSync)
            {
                json["autoSync"] = AutoSync;
            }

            if (IsClientOperationMode && RawData != null)
            {
                json["data"] = new Dictionary <string, object>()
                {
                    { Schema.Data, SerializeDataSource(RawData) },
                    { Schema.Total, Total }
                };
            }
            else if (Type == DataSourceType.Ajax && !IsClientOperationMode && Data != null)
            {
                json["data"] = new Dictionary <string, object>()
                {
                    { Schema.Data, SerializeDataSource(Data) },
                    { Schema.Total, Total }
                };
            }
        }
예제 #7
0
        public void Process(DataSourceRequest request, bool processData)
        {
            RawData = Data;

            if (request.Sorts == null)
            {
                request.Sorts = OrderBy;
            }
            else if (request.Sorts.Any())
            {
                OrderBy.Clear();
                OrderBy.AddRange(request.Sorts);
            }
            else
            {
                OrderBy.Clear();
            }

            if (request.PageSize == 0)
            {
                request.PageSize = PageSize;
            }

            PageSize = request.PageSize;

            if (request.Groups == null)
            {
                request.Groups = Groups;
            }
            else if (request.Groups.Any())
            {
                Groups.Clear();
                Groups.AddRange(request.Groups);
            }
            else
            {
                Groups.Clear();
            }

            if (request.Filters == null)
            {
                request.Filters = Filters;
            }
            else if (request.Filters.Any())
            {
                Filters.Clear();
                Filters.AddRange(request.Filters);
            }
            else
            {
                Filters.Clear();
            }

            if (!request.Aggregates.Any())
            {
                request.Aggregates = Aggregates;
            }
            else if (request.Aggregates.Any())
            {
                MergeAggregateTypes(request);

                Aggregates.Clear();
                Aggregates.AddRange(request.Aggregates);
            }
            else
            {
                Aggregates.Clear();
            }

            if (Groups.Any() && Aggregates.Any() && Data == null)
            {
                Groups.Each(g => g.AggregateFunctions.AddRange(Aggregates.SelectMany(a => a.Aggregates)));
            }

            if (Data != null)
            {
                if (processData)
                {
                    var result = Data.AsQueryable().ToDataSourceResult(request);

                    Data = result.Data;

                    Total = result.Total;

                    AggregateResults = result.AggregateResults;
                }
                else
                {
                    var wrapper = Data as IGridCustomGroupingWrapper;
                    if (wrapper != null)
                    {
                        RawData = Data = wrapper.GroupedEnumerable.AsGenericEnumerable();
                    }
                }
            }

            Page = request.Page;

            if (Total == 0 || PageSize == 0)
            {
                TotalPages = 1;
            }
            else
            {
                TotalPages = (Total + PageSize - 1) / PageSize;
            }
        }
예제 #8
0
 private GridAggregateResult CalculateAggregates(IEnumerable <AggregateResult> aggregateResults)
 {
     return(new GridAggregateResult(aggregateResults.Where(r => Aggregates.Any(f => f.FunctionName == r.FunctionName))));
 }
예제 #9
0
        protected override void Serialize(IDictionary <string, object> json)
        {
            if (Transport.Read.Url == null)
            {
                // If Url is not set assume the current url (used in server binding)
                Transport.Read.Url = "";
            }

            var transport = Transport.ToJson();

            if (transport.Keys.Any())
            {
                json["transport"] = transport;
            }

            if (PageSize > 0)
            {
                json["pageSize"] = PageSize;
                json["page"]     = Page;
                json["total"]    = Total;
            }

            if (ServerPaging)
            {
                json["serverPaging"] = ServerPaging;
            }

            if (ServerSorting)
            {
                json["serverSorting"] = ServerSorting;
            }

            if (ServerFiltering)
            {
                json["serverFiltering"] = ServerFiltering;
            }

            if (ServerGrouping)
            {
                json["serverGrouping"] = ServerGrouping;
            }

            if (ServerAggregates)
            {
                json["serverAggregates"] = ServerAggregates;
            }
            if (Events.Keys.Any())
            {
                SerializeDataSourceEvents(Events, json);
            }
            if (Type != null)
            {
                json["type"] = "aspnetmvc-" + Type.ToString().ToLower();
            }

            if (OrderBy.Any())
            {
                json["sort"] = OrderBy.ToJson();
            }

            if (Groups.Any())
            {
                json["group"] = Groups.ToJson();
            }

            if (Aggregates.Any())
            {
                var aggObjectList = new List <IDictionary <string, object> >();
                foreach (var item in Aggregates)
                {
                    var jsonDic = item.ToJson();
                    aggObjectList.Add(jsonDic);
                }
                json["aggregate"] = aggObjectList;// Aggregates.SelectMany(agg => agg.Aggregates.ToJson());
            }

            if (Filters.Any() || ServerFiltering)
            {
                json["filter"] = Filters.OfType <FilterDescriptorBase>().ToJson();
            }

            if (Filter != null && ServerFiltering)
            {
                //var f = Filter.Trim(new char[] { '\\', '"' });
                var filter = (Filter as FilterItem);
                if (filter != null)
                {
                    json["filter"] = filter.ToJson();
                }
                else
                {
                    var compFilter = (Filter as CompositeFilterItem);
                    json["filter"] = compFilter.ToJson();
                }
            }


            if (Schema.Model != null)
            {
                json["schema"] = Schema.ToJson();
            }


            json["batch"] = Batch;


            if (IsClientOperationMode && RawData != null)
            {
                json["data"] = new Dictionary <string, object>()
                {
                    { Schema.Data, SerializeDataSource(RawData) },
                    { Schema.Total, Total }
                };
            }
            else if (Type == DataSourceType.Ajax && !IsClientOperationMode && Data != null)
            {
                json["data"] = new Dictionary <string, object>()
                {
                    //{ Schema.Data,  SerializeDataSource(Data) },
                    { Schema.Total, Total }
                };
                //json["type"] = "aspnetmvc-ajax";
            }
        }
예제 #10
0
        protected override void Serialize(IDictionary <string, object> json)
        {
            if (Transport.Read.Url == null & Type != DataSourceType.Custom)
            {
                // If Url is not set assume the current url (used in server binding)
                Transport.Read.Url = "";
            }

            if (Type != null)
            {
                if (Type == DataSourceType.Ajax || Type == DataSourceType.Server)
                {
                    json["type"] = "aspnetmvc-" + Type.ToString().ToLower();
                }
                else if (Type == DataSourceType.Custom)
                {
                    if (!string.IsNullOrEmpty(CustomType))
                    {
                        json["type"] = CustomType;
                    }
                }
                else
                {
                    json["type"] = Type.ToString().ToLower();

                    if (Type == DataSourceType.WebApi && Schema.Model.Id != null)
                    {
                        Transport.IdField = Schema.Model.Id.Name;
                    }
                }
            }

            if (CustomTransport != null)
            {
                json["transport"] = CustomTransport;
            }
            else
            {
                var transport = Transport.ToJson();

                if (transport.Keys.Any())
                {
                    json["transport"] = transport;
                }
            }

            if (PageSize > 0)
            {
                json["pageSize"] = PageSize;
                json["page"]     = Page;
                json["total"]    = Total;
            }

            if (ServerPaging)
            {
                json["serverPaging"] = ServerPaging;
            }

            if (ServerSorting)
            {
                json["serverSorting"] = ServerSorting;
            }

            if (ServerFiltering)
            {
                json["serverFiltering"] = ServerFiltering;
            }

            if (ServerGrouping)
            {
                json["serverGrouping"] = ServerGrouping;
            }

            if (ServerAggregates)
            {
                json["serverAggregates"] = ServerAggregates;
            }

            if (OrderBy.Any())
            {
                json["sort"] = OrderBy.ToJson();
            }

            if (Groups.Any())
            {
                json["group"] = Groups.ToJson();
            }

            if (Aggregates.Any())
            {
                json["aggregate"] = Aggregates.SelectMany(agg => agg.Aggregates.ToJson());
            }

            if (Filters.Any() || ServerFiltering)
            {
                json["filter"] = Filters.OfType <FilterDescriptorBase>().ToJson();
            }

            if (Events.Keys.Any())
            {
                json.Merge(Events);
            }

            var schema = Schema.ToJson();

            if (schema.Keys.Any())
            {
                json["schema"] = schema;
            }

            if (Batch)
            {
                json["batch"] = Batch;
            }

            if (AutoSync)
            {
                json["autoSync"] = AutoSync;
            }

            if (IsClientOperationMode && Type == DataSourceType.Custom && CustomType != "aspnetmvc-ajax")
            {
                RawData = Data;
            }

            if (IsClientOperationMode && RawData != null)
            {
                SerializeData(json, RawData);
            }
            else if (IsClientBinding && !IsClientOperationMode && Data != null)
            {
                SerializeData(json, Data);
            }
        }