public IHtmlString Render(IGridColumn column)
        {
            if (!column.FilterEnabled)
            {
                return(MvcHtmlString.Create(string.Empty));
            }


            //determine current column filter settings
            var filterSettings = new List <ColumnFilterValue>();

            if (_settings.IsInitState && column.InitialFilterSettings != ColumnFilterValue.Null)
            {
                filterSettings.Add(column.InitialFilterSettings);
            }
            else
            {
                filterSettings.AddRange(_settings.FilteredColumns.GetByColumn(column));
            }

            bool isColumnFiltered = filterSettings.Any();

            //determine current url:
            var builder = new CustomQueryStringBuilder(_settings.Context.Request.QueryString);

            var exceptQueryParameters = new List <string>
            {
                QueryStringFilterSettings.DefaultTypeQueryParameter,
                QueryStringFilterSettings.DefaultFilterInitQueryParameter
            };
            string pagerParameterName = GetPagerQueryParameterName(column.ParentGrid.Pager);

            if (!string.IsNullOrEmpty(pagerParameterName))
            {
                exceptQueryParameters.Add(pagerParameterName);
            }

            string url = builder.GetQueryStringExcept(exceptQueryParameters);

            var gridFilterButton = new TagBuilder("span");

            gridFilterButton.AddCssClass(FilterButtonCss);
            if (isColumnFiltered)
            {
                gridFilterButton.AddCssClass(FilteredButtonCssClass);
            }
            gridFilterButton.Attributes.Add("title", Strings.FilterButtonTooltipText);

            var gridFilter  = new TagBuilder("div");
            var dataKeyList = new Dictionary <string, string>
            {
                { "data-type", column.FilterWidgetTypeName },
                { "data-name", column.Name },
                { "data-widgetdata", JsonHelper.JsonSerializer(column.FilterWidgetData) },
                { "data-filterdata", JsonHelper.JsonSerializer(filterSettings) },
                { "data-url", url }
            };

            gridFilter.InnerHtml = gridFilterButton.ToString();
            gridFilter.AddCssClass("grid-filter");
            foreach (var data in dataKeyList)
            {
                if (!string.IsNullOrWhiteSpace(data.Value))
                {
                    gridFilter.Attributes.Add(data.Key, data.Value);
                }
            }

            return(MvcHtmlString.Create(gridFilter.ToString()));
        }
Exemplo n.º 2
0
        protected override void OnParametersSet()
        {
            _filterComponents = new QueryDictionary <Type>();
            _filterComponents.Add("System.String", typeof(TextFilterComponent <T>));
            _filterComponents.Add("System.Guid", typeof(TextFilterComponent <T>));
            _filterComponents.Add("System.Int32", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.Double", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.Decimal", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.Byte", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.Single", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.Float", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.Int64", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.Int16", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.UInt64", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.UInt32", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.UInt16", typeof(NumberFilterComponent <T>));
            _filterComponents.Add("System.DateTime", typeof(DateTimeFilterComponent <T>));
            _filterComponents.Add("System.Date", typeof(DateTimeFilterComponent <T>));
            _filterComponents.Add("System.DateTimeOffset", typeof(DateTimeFilterComponent <T>));
            _filterComponents.Add("DateTimeLocal", typeof(DateTimeLocalFilterComponent <T>));
            _filterComponents.Add("System.Boolean", typeof(BooleanFilterComponent <T>));

            if (CustomFilters == null)
            {
                CustomFilters = new QueryDictionary <Type>();
            }
            if (CustomFilters.Any(r => r.Key.Equals(SelectItem.ListFilter)))
            {
                CustomFilters.Remove(SelectItem.ListFilter);
            }
            CustomFilters.Add(SelectItem.ListFilter, typeof(ListFilterComponent <T>));
            foreach (var widget in CustomFilters)
            {
                if (_filterComponents.ContainsKey(widget.Key))
                {
                    _filterComponents[widget.Key] = widget.Value;
                }
                else
                {
                    _filterComponents.Add(widget);
                }
            }

            FirstColumn = (ICGridColumn)Grid.Columns.FirstOrDefault();

            if (OnRowClickedActions != null && OnRowClickedActions.Count() > 0)
            {
                OnRowClicked = OnRowClickedActions.First();
            }

            _hasSubGrid           = Grid.SubGridKeys != null && Grid.SubGridKeys.Length > 0;
            _hasTotals            = Grid.IsSumEnabled || Grid.IsAverageEnabled || Grid.IsMaxEnabled || Grid.IsMinEnabled;
            _requiredTotalsColumn = _hasTotals &&
                                    FirstColumn != null &&
                                    (FirstColumn.IsSumEnabled || FirstColumn.IsAverageEnabled ||
                                     FirstColumn.IsMaxEnabled || FirstColumn.IsMinEnabled);

            InitSubGridVars();

            var queryBuilder          = new CustomQueryStringBuilder(Grid.Settings.SearchSettings.Query);
            var exceptQueryParameters = new List <string> {
                GridPager.DefaultPageSizeQueryParameter
            };

            _changePageSizeUrl = queryBuilder.GetQueryStringExcept(exceptQueryParameters);
            _pageSize          = Grid.Pager.ChangePageSize && Grid.Pager.QueryPageSize > 0 ? Grid.Pager.QueryPageSize : Grid.Pager.PageSize;

            _shouldRender = true;
        }
        protected override void OnParametersSet()
        {
            //determine current column filter settings
            _filterSettings = new List <ColumnFilterValue>();
            if (FilterSettings.IsInitState(Column) && Column.InitialFilterSettings != ColumnFilterValue.Null)
            {
                _filterSettings.Add(Column.InitialFilterSettings);
            }
            else
            {
                _filterSettings.AddRange(FilterSettings.FilteredColumns.GetByColumn(Column));
            }

            _isColumnFiltered = _filterSettings.Any(r => r.FilterType != GridFilterType.Condition);

            //determine current url:
            var queryBuilder = new CustomQueryStringBuilder(FilterSettings.Query);

            var exceptQueryParameters = new List <string>
            {
                QueryStringFilterSettings.DefaultTypeQueryParameter,
                QueryStringFilterSettings.DefaultClearInitFilterQueryParameter
            };
            string pagerParameterName = GetPagerQueryParameterName(((ICGrid)(Column.ParentGrid)).Pager);

            if (!string.IsNullOrEmpty(pagerParameterName))
            {
                exceptQueryParameters.Add(pagerParameterName);
            }

            _url = queryBuilder.GetQueryStringExcept(exceptQueryParameters);

            _clearInitFilter = FilterSettings.Query.Get(QueryStringFilterSettings.DefaultClearInitFilterQueryParameter);

            if (((GridColumnBase <T>)Column).Hidden)
            {
                _cssStyles = ((GridStyledColumn)Column).GetCssStylesString() + " " + ThStyle;
            }
            else
            {
                _cssStyles = ((GridStyledColumn)Column).GetCssStylesString();
            }
            _cssClass = ((GridStyledColumn)Column).GetCssClassesString() + " " + ThClass;

            if (!string.IsNullOrWhiteSpace(Column.Width))
            {
                _cssStyles = string.Concat(_cssStyles, " width:", Column.Width, ";").Trim();
            }

            List <string> cssFilterClasses = new List <string>();

            cssFilterClasses.Add(FilterButtonCss);
            if (_isColumnFiltered)
            {
                cssFilterClasses.Add(FilteredButtonCssClass);
            }
            _cssFilterClass = string.Join(" ", cssFilterClasses);

            List <string> cssSortingClass = new List <string>();

            cssSortingClass.Add("grid-header-title");

            if (Column.IsSorted)
            {
                cssSortingClass.Add("sorted");
                cssSortingClass.Add(Column.Direction == GridSortDirection.Ascending ? "sorted-asc" : "sorted-desc");
            }
            _cssSortingClass = string.Join(" ", cssSortingClass);

            FilterWidgetRender = CreateFilterWidgetComponent();
        }
        protected override void OnParametersSet()
        {
            //determine current column filter settings
            _filterSettings = new List <ColumnFilterValue>();
            if (FilterSettings.IsInitState(Column) && Column.InitialFilterSettings != ColumnFilterValue.Null)
            {
                _filterSettings.Add(Column.InitialFilterSettings);
            }
            else
            {
                _filterSettings.AddRange(FilterSettings.FilteredColumns.GetByColumn(Column));
            }

            _isColumnFiltered = _filterSettings.Any(r => r.FilterType != GridFilterType.Condition);

            //determine current url:
            var queryBuilder = new CustomQueryStringBuilder(FilterSettings.Query);

            var exceptQueryParameters = new List <string>
            {
                QueryStringFilterSettings.DefaultTypeQueryParameter,
                QueryStringFilterSettings.DefaultClearInitFilterQueryParameter
            };
            string pagerParameterName = GetPagerQueryParameterName(((ICGrid)(Column.ParentGrid)).Pager);

            if (!string.IsNullOrEmpty(pagerParameterName))
            {
                exceptQueryParameters.Add(pagerParameterName);
            }

            _url = queryBuilder.GetQueryStringExcept(exceptQueryParameters);

            _clearInitFilter = FilterSettings.Query.Get(QueryStringFilterSettings.DefaultClearInitFilterQueryParameter);

            if (Column.Hidden)
            {
                _cssStyles = ((GridStyledColumn)Column).GetCssStylesString() + " " + ThStyle;
            }
            else
            {
                _cssStyles = ((GridStyledColumn)Column).GetCssStylesString();
            }
            _cssClass = ((GridStyledColumn)Column).GetCssClassesString() + " " + ThClass;

            if (GridComponent.Grid.Direction == GridDirection.RTL)
            {
                _cssStyles = string.Concat(_cssStyles, " text-align:right;direction:rtl;").Trim();
            }

            // tables with fixed layout don't need to set up column width on the header
            if (GridComponent.Grid.TableLayout == TableLayout.Auto)
            {
                if (!string.IsNullOrWhiteSpace(Column.Width))
                {
                    _cssStyles = string.Concat(_cssStyles, " width:", Column.Width, ";").Trim();
                }
            }

            List <string> cssFilterClasses = new List <string>();

            cssFilterClasses.Add(FilterButtonCss);
            if (_isColumnFiltered)
            {
                cssFilterClasses.Add(FilteredButtonCssClass);
            }
            _cssFilterClass = string.Join(" ", cssFilterClasses);

            List <string> cssSortingClass = new List <string>();

            cssSortingClass.Add("grid-header-title");

            if (Column.IsSorted)
            {
                cssSortingClass.Add("sorted");
                cssSortingClass.Add(Column.Direction == GridSortDirection.Ascending ? "sorted-asc" : "sorted-desc");
            }
            _cssSortingClass = string.Join(" ", cssSortingClass);

            if (Column.FilterEnabled)
            {
                FilterWidgetRender = CreateFilterWidgetComponent();
            }

            if (!string.IsNullOrWhiteSpace(Column.Name))
            {
                if (GridComponent.HeaderComponents.ContainsKey(Column.Name))
                {
                    var headerComponent = GridComponent.HeaderComponents.Get(Column.Name);
                    _allChecked     = headerComponent._allChecked;
                    _showAllChecked = headerComponent._showAllChecked;
                }
                GridComponent.HeaderComponents.AddParameter(Column.Name, this);
            }

            _shouldRender = true;
        }