I have a site column (Status) that I've added JSLink to, that runs my custom JavaScript. This works fine on lists. The JavaScript changes the text to a colored image.
I've then created a Visual Web Part that has some custom functionality, one of which is that I'm adding a XsltListViewWebPart
from within the code behind.
XsltListViewWebPart lvwp = new XsltListViewWebPart();
lvwp.WebId = elevatedWeb.ID;
lvwp.ListId = List.ID;
lvwp.JSLink = "/_layouts/15/JS/jquery-2.1.1.min.js|/_layouts/15/JS/JSLinkFields.js";
lvwp.ServerRender = false;
lvwp.ClientRender = true;
var view = list.GetUncustomizedViewByBaseViewId(1);
lvwp.ViewId = int.Parse(view.BaseViewID);
string organisationalFilter = "<Where><Eq><FieldRef Name=\"internalName\"/><Value Type=\"Text\">" + department + "</Value></Eq></Where>";
lvwp.XmlDefinition = "<View BaseViewID='1'>" +
"<Query>" + organisationalFilter + "</Query>" +
"<ViewFields>" +
"<FieldRef Name=\"Status\" />" +
"</ViewFields>" +
"</View>";
lvwp.BorderStyle = BorderStyle.None;
lvwp.ChromeType = PartChromeType.None;
ListViewWebPartPlaceHolder.Controls.Add(lvwp);
I've set a debugger;
in javascript and when I load the list, the script works. However when I load the Web Part, nothing happens.
From searching the web, I've come across some tips but nothing has really worked. Such as adding lvwp.ServerRender = False;
and adding the JSLink to the Webpart (lvwp.JSLink = "";
)
Would be great to get to the bottom of this.