Need help, SharePointOnline, ListView Web Part issues with JSLink .

%3CLINGO-SUB%20id%3D%22lingo-sub-1170589%22%20slang%3D%22en-US%22%3ENeed%20help%2C%20SharePointOnline%2C%20ListView%20Web%20Part%20issues%20with%20JSLink%20.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1170589%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3CBR%20%2F%3EThis%20is%20working%20for%20me%20for%20the%20last%204%20years%20and%20suddenly%20having%20this%20issue.%3CBR%20%2F%3EOne%20list-%20Tools%20and%202%20views%20(Business%20Systems)%20and%20Inquires.%20Both%20have%20their%20own%20JSlink.%3CBR%20%2F%3E%3CSPAN%3EI%20add%20the%20list%20webpart%20to%20the%20page%2C%20set%20the%20view%20(Business%20Systems)%20and%20add%20JSlink.%20Now%20as%20soon%20as%20I%20add%20another%20webpart%2C%20it%20default%20takes%20the%20first%20webpart%20view%20and%20style.%20I%20want%20to%20set%20this%20with%20totally%20different%20view%20(Inquires)%20and%20Jslink.%26nbsp%3B%3C%2FSPAN%3EI%20did%20not%20create%20the%20JS%20and%20hence%20not%20sure%20how%20to%20fix%20this.%20Any%20help%20is%20much%20appreciated.%20Below%20is%20the%20JSlink%20(%20BusinessSytem)%20and%20Inquires.%26nbsp%3B%20Any%20help%20is%20appreciated.%20Thanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJsLink-BusinessSystem.js%3C%2FP%3E%3CP%3E(function%20()%20%7B%3CBR%20%2F%3Evar%20overrideContext%20%3D%20%7B%7D%3B%3CBR%20%2F%3EoverrideContext.Templates%20%3D%20%7B%7D%3B%3CBR%20%2F%3EoverrideContext.Templates.Header%20%3D%20overrideHeader%3B%3CBR%20%2F%3EoverrideContext.Templates.Item%20%3D%20overrideTemplate%3B%3CBR%20%2F%3EoverrideContext.Templates.Footer%20%3D%20overrideFooter%3B%3CBR%20%2F%3EoverrideContext.ListTemplateType%20%3D%20100%3B%3CBR%20%2F%3ESPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext)%3B%3CBR%20%2F%3E%7D)()%3B%3C%2FP%3E%3CP%3Efunction%20overrideTemplate(ctx)%20%7B%3CBR%20%2F%3Evar%20titleLink%20%3D%20ctx.CurrentItem.Link%3B%3CBR%20%2F%3E%3CBR%20%2F%3Eif(titleLink.indexOf('href')%20!%3D%20-1)%20%7B%3CBR%20%2F%3EtitleLink%20%3D%20%24(titleLink).attr('href')%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20(ctx.view%20!%3D'%7BAC67F030-0CEF-4C9C-986D-8CCAD2E85BC0%7D')%7B%3CBR%20%2F%3Eif%20(ctx.CurrentItem.Group_x0020_Number%20%3D%3D%20'1')%20%7B%3CBR%20%2F%3Ereturn%20%22%3C%2FP%3E%3CDIV%20class%3D%22'linkColumnOne'%22%3E%3CA%20href%3D%22'%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3CIMG%20src%3D%22'%26quot%3B%22%20%2F%3E%3C%2FA%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3Eif%20(ctx.CurrentItem.Group_x0020_Number%20%3D%3D%20'2')%20%7B%3CBR%20%2F%3Ereturn%20%22%3CDIV%20class%3D%22'linkColumnTwo'%22%3E%3CA%20href%3D%22'%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3CIMG%20src%3D%22'%26quot%3B%22%20%2F%3E%3C%2FA%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3Eif%20(ctx.CurrentItem.Group_x0020_Number%20%3D%3D%20'3')%20%7B%3CBR%20%2F%3Ereturn%20%22%3CDIV%20class%3D%22'linkColumnThree'%22%3E%3CA%20href%3D%22'%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3CIMG%20src%3D%22'%26quot%3B%22%20%2F%3E%3C%2FA%3E%3CDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CP%3E%3C%2FP%3E%3CP%3E%7D%3CBR%20%2F%3Eelse%20if%20(ctx.view%20!%3D'%7B333399BC-515F-47F5-A379-094D2FB395C9%7D')%20%7B%3CBR%20%2F%3Eif%20(ctx.CurrentItem.Group_x0020_Number%20%3D%3D%20'1')%20%7B%3CBR%20%2F%3Ereturn%20%22%3C%2FP%3E%3CDIV%20class%3D%22'inquiriesC1'%22%3E%3CA%20href%3D%22'%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%22%20%2B%20ctx.CurrentItem.Title%20%2B%20%22%3C%2FA%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3Eif%20(ctx.CurrentItem.Group_x0020_Number%20%3D%3D%20'2')%20%7B%3CBR%20%2F%3Ereturn%20%22%3CDIV%20class%3D%22'inquiriesC2'%22%3E%3CA%20href%3D%22'%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%22%20%2B%20ctx.CurrentItem.Title%20%2B%20%22%3C%2FA%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CP%3E%3C%2FP%3E%3CP%3Efunction%20overrideHeader()%20%7B%3C%2FP%3E%3CP%3Eif%20(ctx.view%20!%3D'%7BAC67F030-0CEF-4C9C-986D-8CCAD2E85BC0%7D')%7B%3CBR%20%2F%3Evar%20cssId%20%3D%20'jsLink-BusinessSystems'%3B%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20(!document.getElementById(cssId))%3CBR%20%2F%3E%7B%3CBR%20%2F%3Evar%20head%20%3D%20document.getElementsByTagName('head')%5B0%5D%3B%3CBR%20%2F%3Evar%20link%20%3D%20document.createElement('link')%3B%3CBR%20%2F%3Elink.id%20%3D%20cssId%3B%3CBR%20%2F%3Elink.rel%20%3D%20'stylesheet'%3B%3CBR%20%2F%3Elink.type%20%3D%20'text%2Fcss'%3B%3CBR%20%2F%3Elink.href%20%3D%20'%2Fsites%2Fsitecollection%2FStyle%20Library%2FWeb%20Parts%2FjsLink-BusinessSystems.css'%3B%3CBR%20%2F%3Elink.media%20%3D%20'all'%3B%3CBR%20%2F%3Ehead.appendChild(link)%3B%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3Ereturn%20%22%3C%2FP%3E%3CDIV%20class%3D%22'businessSystemsContainer'%22%3E%3CDIV%20class%3D%22'columnOne'%22%3E%3C%2FDIV%3E%3CDIV%20class%3D%22'columnTwo'%22%3E%3C%2FDIV%3E%3CDIV%20class%3D%22'columnThree'%22%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3Eelse%20if%20(ctx.view%20!%3D'%7B333399BC-515F-47F5-A379-094D2FB395C9%7D')%20%7B%3CBR%20%2F%3Evar%20cssId%20%3D%20'jsLink-InquiriesReports'%3B%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20(!document.getElementById(cssId))%3CBR%20%2F%3E%7B%3CBR%20%2F%3Evar%20head%20%3D%20document.getElementsByTagName('head')%5B0%5D%3B%3CBR%20%2F%3Evar%20link%20%3D%20document.createElement('link')%3B%3CBR%20%2F%3Elink.id%20%3D%20cssId%3B%3CBR%20%2F%3Elink.rel%20%3D%20'stylesheet'%3B%3CBR%20%2F%3Elink.type%20%3D%20'text%2Fcss'%3B%3CBR%20%2F%3Elink.href%20%3D%20'%2Fsites%2Fsitecollection%2FStyle%20Library%2FWeb%20Parts%2FjsLink-InquiriesReports.css'%3B%3CBR%20%2F%3Elink.media%20%3D%20'all'%3B%3CBR%20%2F%3Ehead.appendChild(link)%3B%3CBR%20%2F%3E%7D%3CP%3E%3C%2FP%3E%3CP%3Ereturn%20%22%3C%2FP%3E%3CH2%20class%3D%22'inquiriesHeader'%22%20id%3D%22toc-hId--1409994970%22%3EInquiries%3C%2FH2%3E%3CDIV%20class%3D%22'inquiriesReportsContainer'%22%3E%3CDIV%20class%3D%22'inquiriesColumnOne'%22%3E%3C%2FDIV%3E%3CDIV%20class%3D%22'inquiriesColumnTwo'%22%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CP%3E%3C%2FP%3E%3CP%3Efunction%20overrideFooter()%20%7B%3CBR%20%2F%3Eif%20(ctx.view%20!%3D'%7BAC67F030-0CEF-4C9C-986D-8CCAD2E85BC0%7D')%7B%3CBR%20%2F%3E%24('.columnOne').append(%24('.linkColumnOne'))%3B%3CBR%20%2F%3E%24('.columnTwo').append(%24('.linkColumnTwo'))%3B%3CBR%20%2F%3E%24('.columnThree').append(%24('.linkColumnThree'))%3B%3CBR%20%2F%3E%3CBR%20%2F%3Ereturn%20%22%3C%2FP%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3Eelse%20if%20(ctx.view%20!%3D'%7B333399BC-515F-47F5-A379-094D2FB395C9%7D')%20%7B%3CBR%20%2F%3E%24('.inquiriesColumnOne').append(%24('.inquiriesC1'))%3B%3CBR%20%2F%3E%24('.inquiriesColumnTwo').append(%24('.inquiriesC2'))%3B%3CP%3E%3C%2FP%3E%3CP%3Ereturn%20%22%3C%2FP%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CP%3E%3C%2FP%3E%3CP%3EJsLink-Inquires.js%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(function%20()%20%7B%3CBR%20%2F%3Evar%20overrideContext%20%3D%20%7B%7D%3B%3CBR%20%2F%3EoverrideContext.Templates%20%3D%20%7B%7D%3B%3CBR%20%2F%3EoverrideContext.Templates.Header%20%3D%20overrideHeader%3B%3CBR%20%2F%3EoverrideContext.Templates.Item%20%3D%20overrideTemplate%3B%3CBR%20%2F%3EoverrideContext.Templates.Footer%20%3D%20overrideFooter%3B%3CBR%20%2F%3EoverrideContext.ListTemplateType%20%3D%20100%3B%3CBR%20%2F%3ESPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext)%3B%3CBR%20%2F%3E%7D)()%3B%3C%2FP%3E%3CP%3Efunction%20overrideTemplate(ctx)%20%7B%3CBR%20%2F%3Evar%20titleLink%20%3D%20ctx.CurrentItem.Link%3B%3CBR%20%2F%3E%3CBR%20%2F%3Eif(titleLink.indexOf('href')%20!%3D%20-1)%20%7B%3CBR%20%2F%3EtitleLink%20%3D%20%24(titleLink).attr('href')%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20(ctx.CurrentItem.Group_x0020_Number%20%3D%3D%20'1')%20%7B%3CBR%20%2F%3Ereturn%20%22%3C%2FP%3E%3CDIV%20class%3D%22'linkColumnOne'%22%3E%3CA%20href%3D%22'%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%22%20%2B%20ctx.CurrentItem.Title%20%2B%20%22%3C%2FA%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3Eif%20(ctx.CurrentItem.Group_x0020_Number%20%3D%3D%20'2')%20%7B%3CBR%20%2F%3Ereturn%20%22%3CDIV%20class%3D%22'linkColumnTwo'%22%3E%3CA%20href%3D%22'%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%22%20%2B%20ctx.CurrentItem.Title%20%2B%20%22%3C%2FA%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CP%3E%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3Efunction%20overrideHeader()%20%7B%3CBR%20%2F%3Evar%20cssId%20%3D%20'jsLink-Inquiries'%3B%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20(!document.getElementById(cssId))%3CBR%20%2F%3E%7B%3CBR%20%2F%3Evar%20head%20%3D%20document.getElementsByTagName('head')%5B0%5D%3B%3CBR%20%2F%3Evar%20link%20%3D%20document.createElement('link')%3B%3CBR%20%2F%3Elink.id%20%3D%20cssId%3B%3CBR%20%2F%3Elink.rel%20%3D%20'stylesheet'%3B%3CBR%20%2F%3Elink.type%20%3D%20'text%2Fcss'%3B%3CBR%20%2F%3Elink.href%20%3D%20'%2Fsites%2Fconnect%2FStyle%20Library%2FWeb%20Parts%2FjsLink-Inquiries.css'%3B%3CBR%20%2F%3Elink.media%20%3D%20'all'%3B%3CBR%20%2F%3Ehead.appendChild(link)%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3Ereturn%20%22%3C%2FP%3E%3CDIV%20class%3D%22'inquiriesContainer'%22%3E%3CDIV%20class%3D%22'columnOne'%22%3E%3C%2FDIV%3E%3CDIV%20class%3D%22'columnTwo'%22%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CP%3E%3C%2FP%3E%3CP%3Efunction%20overrideFooter()%20%7B%3CBR%20%2F%3E%24('.columnOne').append(%24('.linkColumnOne'))%3B%3CBR%20%2F%3E%24('.columnTwo').append(%24('.linkColumnTwo'))%3B%3CBR%20%2F%3E%3CBR%20%2F%3Ereturn%20%22%3C%2FP%3E%3C%2FDIV%3E%22%3B%3CBR%20%2F%3E%7D%3CP%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

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>";
}

 

0 Replies