When customising a list with JS or XSLT, the formatting seems to be applied not just to the list view web part the property is set for - but for all parts with the same list type ID on the page containing the part.

Simply put, if I create two custom lists with unique fields and use a list view web part on a single page, how can I have two JS Link files, one for formatting each part? - a quick overview would be great.


When you apply custom XSL to the list view then add in unique class or id to the HTML. You can then use these tags to hook into the correct content from your jQuery.

So as an example, in your XSLT for list1:

<div class="list1item">
 <xsl:value-of select="@Title" />

Then from your jQuery:


This would apply the custom style only to the items from list 1.

You then need to do the same for List 2 but this time use a different class - eg list2item.

  • Thanks, but I mean the other way around. When I apply a JS link to a list view web part (and I assume XSLT too), the JS is applied to all list view web parts on the page. How can I limit JS or XSLT 'link' styling to just the part for which the file to format it is specified? – Kieren Johnstone Apr 12 '13 at 22:34
  • By default all the items in list views will have the same classes. So it depends what selector you use in your jQuery. If you use the standard generic class then it will apply that jQuery to every list item in all web parts. This is why I was suggesting you use some custom XSL to ensure there is some way to uniquely identify the items you want to apply it to. – Dave Paylor Apr 13 '13 at 2:53
  • You may not be getting what I mean though. See here: learningsharepoint.com/2013/04/04/… no jQuery or classes. If we use that exact code on one list web part's JS Link property, all list web parts on the page are automatically transformed using the same JS Link code. (those which have the same list type ID, anyway.. I've been told there's no way to give a custom list created 'OOB' - not via an app - a bespoke list type ID?) – Kieren Johnstone Apr 13 '13 at 7:45
  • Aha - you are correct, I had misunderstood what you were doing. I have not tried this approach yet in 2013 but it looks like it is applying a custom template for all lists of that type - so when you apply the JS to the list view on the page it is also applying it to any other list of the same type on the same page. I agree with you that it seems it should only apply it to the view which has the JS Link applied but it looks like others are having the same issue. – Dave Paylor Apr 13 '13 at 8:59
  • I realize this is a couple years old at this point, but after reading the code linked to above (learningsharepoint.com), what happens if you omit the itemCtx.ListTemplateType = 100; line? It seems to me that that's exactly the line of code that's making the JS Link code run for all lists of the same type, instead of just for the list that the LVWP is pointing to. – Dylan Cristy Feb 23 '15 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.