Forum Discussion
Need help, SharePointOnline, ListView Web Part issues with JSLink .
Hi,
This is working for me for the last 4 years and suddenly having this issue.
One list- Tools and 2 views (Business Systems) and Inquires. Both have their own JSlink.
I add the list webpart to the page, set the view (Business Systems) and add JSlink. Now as soon as I add another webpart, it default takes the first webpart view and style. I want to set this with totally different view (Inquires) and Jslink. I did not create the JS and hence not sure how to fix this. Any help is much appreciated. Below is the JSlink ( BusinessSytem) and Inquires. Any help is appreciated. Thanks
JsLink-BusinessSystem.js
(function () {
var overrideContext = {};
overrideContext.Templates = {};
overrideContext.Templates.Header = overrideHeader;
overrideContext.Templates.Item = overrideTemplate;
overrideContext.Templates.Footer = overrideFooter;
overrideContext.ListTemplateType = 100;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
})();
function overrideTemplate(ctx) {
var titleLink = ctx.CurrentItem.Link;
if(titleLink.indexOf('href') != -1) {
titleLink = $(titleLink).attr('href');
}
if (ctx.view !='{AC67F030-0CEF-4C9C-986D-8CCAD2E85BC0}'){
if (ctx.CurrentItem.Group_x0020_Number == '1') {
return "<div class='linkColumnOne'><a href='" + titleLink + "' target='_blank'><img src='" + ctx.CurrentItem.Picture1 + "' /></a></div>";
}
if (ctx.CurrentItem.Group_x0020_Number == '2') {
return "<div class='linkColumnTwo'><a href='" + titleLink + "' target='_blank'><img src='" + ctx.CurrentItem.Picture1 + "' /></a></div>";
}
if (ctx.CurrentItem.Group_x0020_Number == '3') {
return "<div class='linkColumnThree'><a href='" + titleLink + "' target='_blank'><img src='" + ctx.CurrentItem.Picture1 + "' /></a><div>";
}
}
else if (ctx.view !='{333399BC-515F-47F5-A379-094D2FB395C9}') {
if (ctx.CurrentItem.Group_x0020_Number == '1') {
return "<div class='inquiriesC1'><a href='" + titleLink + "' target='_blank'>" + ctx.CurrentItem.Title + "</a></div>";
}
if (ctx.CurrentItem.Group_x0020_Number == '2') {
return "<div class='inquiriesC2'><a href='" + titleLink + "' target='_blank'>" + ctx.CurrentItem.Title + "</a></div>";
}
}
}
function overrideHeader() {
if (ctx.view !='{AC67F030-0CEF-4C9C-986D-8CCAD2E85BC0}'){
var cssId = 'jsLink-BusinessSystems';
if (!document.getElementById(cssId))
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = cssId;
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = '/sites/sitecollection/Style Library/Web Parts/jsLink-BusinessSystems.css';
link.media = 'all';
head.appendChild(link);
}
return "<div class='businessSystemsContainer'><div class='columnOne'></div><div class='columnTwo'></div><div class='columnThree'></div>";
}
else if (ctx.view !='{333399BC-515F-47F5-A379-094D2FB395C9}') {
var cssId = 'jsLink-InquiriesReports';
if (!document.getElementById(cssId))
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = cssId;
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = '/sites/sitecollection/Style Library/Web Parts/jsLink-InquiriesReports.css';
link.media = 'all';
head.appendChild(link);
}
return "<h2 class='inquiriesHeader'>Inquiries</h2><div class='inquiriesReportsContainer'><div class='inquiriesColumnOne'></div><div class='inquiriesColumnTwo'></div>";
}
}
function overrideFooter() {
if (ctx.view !='{AC67F030-0CEF-4C9C-986D-8CCAD2E85BC0}'){
$('.columnOne').append($('.linkColumnOne'));
$('.columnTwo').append($('.linkColumnTwo'));
$('.columnThree').append($('.linkColumnThree'));
return "</div>";
}
else if (ctx.view !='{333399BC-515F-47F5-A379-094D2FB395C9}') {
$('.inquiriesColumnOne').append($('.inquiriesC1'));
$('.inquiriesColumnTwo').append($('.inquiriesC2'));
return "</div>";
}
}
JsLink-Inquires.js
(function () {
var overrideContext = {};
overrideContext.Templates = {};
overrideContext.Templates.Header = overrideHeader;
overrideContext.Templates.Item = overrideTemplate;
overrideContext.Templates.Footer = overrideFooter;
overrideContext.ListTemplateType = 100;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);
})();
function overrideTemplate(ctx) {
var titleLink = ctx.CurrentItem.Link;
if(titleLink.indexOf('href') != -1) {
titleLink = $(titleLink).attr('href');
}
if (ctx.CurrentItem.Group_x0020_Number == '1') {
return "<div class='linkColumnOne'><a href='" + titleLink + "' target='_blank'>" + ctx.CurrentItem.Title + "</a></div>";
}
if (ctx.CurrentItem.Group_x0020_Number == '2') {
return "<div class='linkColumnTwo'><a href='" + titleLink + "' target='_blank'>" + ctx.CurrentItem.Title + "</a></div>";
}
}
function overrideHeader() {
var cssId = 'jsLink-Inquiries';
if (!document.getElementById(cssId))
{
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.id = cssId;
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = '/sites/sitecollection/Style Library/Web Parts/jsLink-Inquiries.css';
link.media = 'all';
head.appendChild(link);
}
return "<div class='inquiriesContainer'><div class='columnOne'></div><div class='columnTwo'></div>";
}
function overrideFooter() {
$('.columnOne').append($('.linkColumnOne'));
$('.columnTwo').append($('.linkColumnTwo'));
return "</div>";
}