Ejemplo n.º 1
0
        public string GetSortUrl()
        {
            IList <SortDescriptor> orderBy    = new List <SortDescriptor>(Grid.DataSource.OrderBy);
            SortDescriptor         descriptor = orderBy.SingleOrDefault(c => c.Member.IsCaseInsensitiveEqual(Member));

            ListSortDirection?oldDirection = null;

            if (descriptor != null)
            {
                oldDirection = descriptor.SortDirection;

                ListSortDirection?newDirection = oldDirection.Next();

                if (newDirection == null)
                {
                    if (!Grid.Sortable.AllowUnsort)
                    {
                        newDirection = ListSortDirection.Ascending;
                    }
                    else
                    {
                        orderBy.Remove(descriptor);
                    }
                }

                if (newDirection != null)
                {
                    if (Grid.Sortable.SortMode == GridSortMode.SingleColumn)
                    {
                        orderBy.Clear();
                        orderBy.Add(new SortDescriptor {
                            SortDirection = newDirection.Value, Member = descriptor.Member
                        });
                    }
                    else
                    {
                        orderBy[orderBy.IndexOf(descriptor)] = new SortDescriptor {
                            SortDirection = newDirection.Value, Member = descriptor.Member
                        };
                    }
                }
            }
            else
            {
                if (Grid.Sortable.SortMode == GridSortMode.SingleColumn)
                {
                    orderBy.Clear();
                }

                orderBy.Add(new SortDescriptor {
                    Member = Member, SortDirection = ListSortDirection.Ascending
                });
            }

            return(Grid.UrlBuilder.SelectUrl(GridUrlParameters.Sort, GridDescriptorSerializer.Serialize(orderBy)));
        }
Ejemplo n.º 2
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            DataSourceRequest request = new DataSourceRequest();

            string sort, group, filter, aggregates;
            int    currentPage;
            int    pageSize;

            if (TryGetValue(bindingContext, GridUrlParameters.Sort, out sort))
            {
                request.Sorts = GridDescriptorSerializer.Deserialize <SortDescriptor>(sort);
            }

            if (TryGetValue(bindingContext, GridUrlParameters.Page, out currentPage))
            {
                request.Page = currentPage;
            }

            if (TryGetValue(bindingContext, GridUrlParameters.PageSize, out pageSize))
            {
                request.PageSize = pageSize;
            }

            if (TryGetValue(bindingContext, GridUrlParameters.Filter, out filter))
            {
                request.Filters = FilterDescriptorFactory.Create(filter);
            }

            if (TryGetValue(bindingContext, GridUrlParameters.Group, out group))
            {
                request.Groups = GridDescriptorSerializer.Deserialize <GroupDescriptor>(group);
            }

            if (TryGetValue(bindingContext, GridUrlParameters.Aggregates, out aggregates))
            {
                request.Aggregates = GridDescriptorSerializer.Deserialize <AggregateDescriptor>(aggregates);
            }

            return(request);
        }