예제 #1
0
        private void ProcessFilter(TagHelperOutput output, TableChildContext tableHeader = null)
        {
            if (FilterData is CheckBoxTableFilterData chekbox && (chekbox.Items?.Any() ?? false))
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("<div class=\"dropdown\">");
                builder.AppendLine($"<span class=\"filtarable\" onclick=\"sortBy{tableHeader?.UniqueName}(this,'{ColumnName}', '{tableHeader?.Area}', '{tableHeader?.Controller}', '{tableHeader?.Action}')\">{DisplayName}</span>");
                builder.AppendLine(
                    "<i class=\"fa fa-filter pull-right dropdown-toggle\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\"></i>");
                builder.AppendLine(
                    $"<div class=\"dropdown-menu filter-dropdown multiselect dropdown-menu-right\" data-property=\"{chekbox.PropertyName}\" >");
                if (chekbox.IsSelectAllEnabled)
                {
                    builder.AppendLine("<div class=\"dropdown-item select-all\">");
                    builder.AppendLine("<label class=\"checkbox\">");
                    string isChecked = chekbox.Items.All(x => x.IsChecked) ? "checked=\"checked\"" : "";
                    builder.AppendLine($"<input type=\"checkbox\" class=\"first\" value=\"all\" {isChecked}> Select all");
                    builder.AppendLine("</label>");
                    builder.AppendLine("</div>");
                }

                foreach (CheckBoxTableFilterData.CheckBoxListItem item in chekbox.Items)
                {
                    builder.AppendLine("<div class=\"dropdown-item\">");
                    builder.AppendLine("<label class=\"checkbox\">");
                    string isChecked = item.IsChecked ? "checked=\"checked\"" : "";
                    builder.AppendLine($"<input type=\"checkbox\" value=\"{item.Value}\" {isChecked}> {item.DisplayName}");
                    builder.AppendLine("</label>");
                    builder.AppendLine("</div>");
                }

                output.Content.SetHtmlContent(builder.ToString());
            }
        }
예제 #2
0
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "th";
            output.Content.SetContent(DisplayName);
            output.TagMode = TagMode.StartTagAndEndTag;
            var dataContext = context.Items[typeof(TableChildContext)] as TableChildContext;

            output.Attributes.Add("data-uniqename", dataContext?.UniqueName);
            if (!IsColumnCheckbox)
            {
                if (FilterData != null)
                {
                    ProcessFilter(output, dataContext);
                }
                else
                {
                    TableChildContext tableHeader = context.Items[typeof(TableChildContext)] as TableChildContext;
                    output.Content.SetHtmlContent(
                        IsSortable
                            ? $"<span class=\"filtarable\" onclick=\"sortBy{tableHeader?.UniqueName}(this,'{ColumnName}', '{tableHeader?.Area}','{tableHeader?.Controller}', '{tableHeader?.Action}')\">{DisplayName}</span>"
                            : $"<span>{DisplayName}</span>");
                }
            }
            else
            {
                output.Content.SetHtmlContent("<div class=\"\"><input type=\"checkbox\" class=\"\" onchange=\"checkAll(this)\"></div>");
            }
        }
예제 #3
0
        public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.TagName = "thead";
            var key = $"{Action}_{Controller}_{Area}";

            if (!UniqueNames.ContainsKey(key))
            {
                UniqueNames.Add(key, Guid.NewGuid().ToString("N"));
            }

            UniqueName = UniqueNames[key];
            TableChildContext parentChildContext = new TableChildContext()
            {
                Action     = Action,
                UniqueName = UniqueName,
                Controller = Controller,
                Area       = Area,
            };

            context.Items.Add(typeof(TableChildContext), parentChildContext);


            var childs = await output.GetChildContentAsync();

            output.Content.SetHtmlContent(childs);

            StringBuilder builder = new StringBuilder();

            builder.AppendLine("<script>");
            builder.AppendLine($"function sortBy{UniqueName}(elem ,field, controller, action)");

            var url = UrlHelper.Action(Action, Controller, new { area = Area });

            builder.AppendLine("{$.ajax({type :\"GET\", url:");
            builder.AppendLine($"\"{url}\",");
            builder.AppendLine("dataType : \"html\",");
            if (Parameters == null)
            {
                builder.AppendLine("data :{sidx: field,customFilter:getAllTableFilters($(elem).closest(\"thead\")},");
            }
            else
            {
                builder.AppendLine("data:{");
                builder.AppendLine("sidx: field");

                foreach (var parameter in Parameters)
                {
                    if (parameter.Key == "sidx")
                    {
                        continue;
                    }

                    builder.AppendLine(",");
                    if (parameter.Key == "sord")
                    {
                        builder.AppendLine(parameter.Value.Contains("asc") ? $"{parameter.Key}:\"desc\"" : $"{parameter.Key}:\"asc\"");
                    }
                    else
                    {
                        builder.AppendLine($"{parameter.Key}:{parameter.Value}");
                    }
                }

                builder.AppendLine($",customFilter:JSON.stringify(getAllTableFilters($(elem).closest(\"thead\")))");
                builder.AppendLine("},");
            }
            builder.AppendLine("success: function(answer){");
            if (!string.IsNullOrEmpty(ElementToUpdateId))
            {
                builder.AppendLine($"$('#{ElementToUpdateId}').html(answer);");
            }
            if (!string.IsNullOrEmpty(SuccessCallback))
            {
                builder.AppendLine($"{SuccessCallback}();" + "}");
            }
            else
            {
                builder.Append('}');
            }

            builder.AppendLine("});}");
            builder.AppendLine("function applyFilters" + UniqueName + "(rootElement) {");
            builder.AppendLine("var area = $(rootElement).closest(\"th\").data(\"area\");");
            builder.AppendLine("var controller = $(rootElement).closest(\"th\").data(\"controller\");");
            builder.AppendLine("var action = $(rootElement).closest(\"th\").data(\"action\");");
            builder.AppendLine("var jsObj = getAllTableFilters($(rootElement).closest(\"thead\"));");
            builder.AppendLine("$.ajax({");
            builder.AppendLine("type: \"GET\",");


            builder.AppendLine($"url: \"{url}\",");
            builder.AppendLine();
            builder.AppendLine("dataType: \"html\",");
            builder.AppendLine("data: {");
            builder.AppendLine("customFilter:JSON.stringify(jsObj)");
            if (Parameters == null)
            {
                builder.AppendLine("},");
            }
            else
            {
                builder.AppendLine(",");
                int i = 0;
                foreach (var parameter in Parameters)
                {
                    if (i != 0)
                    {
                        builder.AppendLine(",");
                    }
                    builder.AppendLine($"{parameter.Key}:{parameter.Value}");
                    i++;
                }
                builder.AppendLine("},");
            }
            builder.AppendLine("success: function(answer){");
            if (!string.IsNullOrEmpty(ElementToUpdateId))
            {
                builder.AppendLine($"$('#{ElementToUpdateId}').html(answer);");
            }
            if (!string.IsNullOrEmpty(SuccessCallback))
            {
                builder.AppendLine($"{SuccessCallback}();" + "}");
            }
            else
            {
                builder.Append('}');
            }
            builder.AppendLine("});}</script>");


            output.PostContent.SetHtmlContent(builder.ToString());
        }