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()); }