I created a custom web part with ListViewWebPart in its Controls collection. Source code:
var obtainedList = elevatedWeb.GetListFromWebPartPageUrl(FullUrl);
if (obtainedList == null)
{
throw new Exception(string.Format(ListFromUrlNotObtained,FullUrl));
}
FullUrl = HttpUtility.UrlDecode(FullUrl);
var listViewWebPart = new ListViewWebPart();
listViewWebPart.WebId = elevatedWeb.ID;
listViewWebPart.ListId = obtainedList.ID;
var obtainedListView =obtainedList.Views.OfType<SPView>().FirstOrDefault<SPView>(lv => FullUrl.EndsWith(lv.Url));
if (obtainedListView == null)
{
throw new Exception(string.Format(ViewFromUrlNotObtained,FullUrl));
}
var xml = XElement.Parse(obtainedListView.HtmlSchemaXml);
xml.Attribute("Url").Remove();
if (!string.IsNullOrEmpty(FilterQuery))
{
xml.Element(XName.Get("Query")).SetValue(WildcardProcessor.ProcessQuery(FilterQuery));
}
var updatedXml = xml.ToString();
listViewWebPart.ListViewXml = updatedXml;
listViewWebPart.
Controls.Add(listViewWebPart);
The returned data looks good. Everything is filtered based on query. However the filtering functionality isnt working good. For example if the table has 1 result and I select the dropdown that I want to filter on this results it shows me 2 options to filter on. The problem is that the header is probably rendered based on the original view that belongs to list. Is there I way how to solve this issue? I am opened to reflection and etc. Thanks a lot!