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());
        }
        public void TestWithParameter()
        {
            var queryStringParameters = new NameValueCollection();
            queryStringParameters.Add("key1", "value1");
            queryStringParameters.Add("key2", "value2");
            queryStringParameters.Add("key3", "value3");

            _builder = new CustomQueryStringBuilder(queryStringParameters);

            var str1 = _builder.GetQueryStringWithParameter("key4", "value4");
            Assert.AreEqual(str1, "?key1=value1&key2=value2&key3=value3&key4=value4");

            str1 = _builder.GetQueryStringWithParameter("key4", "value4new");
            Assert.AreEqual(str1, "?key1=value1&key2=value2&key3=value3&key4=value4new");
        }
        public void TestExcept()
        {
            var queryStringParameters = new NameValueCollection();
            queryStringParameters.Add("key1", "value1");
            queryStringParameters.Add("key2", "value2");
            _builder = new CustomQueryStringBuilder(queryStringParameters);

            var str1 = _builder.GetQueryStringExcept(new[] { "key1" });
            Assert.AreEqual(str1, "?key2=value2");

            str1 = _builder.GetQueryStringExcept(new[] { "key2" });
            Assert.AreEqual(str1, "?key1=value1");

            str1 = _builder.GetQueryStringExcept(new[] { "key1", "key2" });
            Assert.AreEqual(str1, string.Empty);
        }
 private string GetSortUrl(string columnName, GridSortDirection? direction)
 {
     //switch direction for link:
     GridSortDirection newDir = direction == GridSortDirection.Ascending
                                    ? GridSortDirection.Descending
                                    : GridSortDirection.Ascending;
     //determine current url:
     var builder = new CustomQueryStringBuilder(_settings.Context.Request.QueryString);
     string url =
         builder.GetQueryStringExcept(new[]
             {
                 GridPager.DefaultPageQueryParameter,
                 _settings.ColumnQueryParameterName,
                 _settings.DirectionQueryParameterName
             });
     if (string.IsNullOrEmpty(url))
         url = "?";
     else
         url += "&";
     return string.Format("{0}{1}={2}&{3}={4}", url, _settings.ColumnQueryParameterName, columnName,
                          _settings.DirectionQueryParameterName,
                          ((int) newDir).ToString(CultureInfo.InvariantCulture));
 }