7

I just posted this on Andrei Markeev his Cisar issue list.

Can someone confirm CSR can not be applied to Personal Views,

or tell me I am talking poop (je praat poep! in Dutch)

BTW anyone doing any CSR development should use Cisar

I can not find a way to set a JSlink.

The misconception is we all call it a View Template while technically we attach a JSlink to a WebPart.. which displays a View.

I fear Personal Views are all 2003 technology.. they do not get their own ASPX page (or own ListView WebPart) Personal Views are served like:

/Lists/Tasks/PersonalViews.aspx?PageView=Personal&ShowWebPart={A8E42828-D606-4089-83CB-D8AFC5041B31}

And when you EDIT that page... Its is Blank!

Even the good old &toolpaneview=2 hack doesn't reveal any webparts

Tried one other ViewID from the same list for the ShowWebPart URL parameter, but it presents a totally blank page

I use JSOM code to set JSlinks on WebParts with one click.. it doesn't work for this PersonalViews.aspx page.

Couldn't find any blogs related to this.

I am inclined to say that you can NOT apply CSR to Personal Views,

seems to me the View declaration (but not the WebPart with a JSlink option) is stored in the database

That means... Issue closed :-)

Update 1

Cool.. yes you can set jsLink on a VIEW (with code).. and when you create a Personal View from it.. it copies the jsLink setting. Cisar only works with the jsLink on WebParts.

Note: for a Task list there are default VIEW jsLink settings (hierarchytaskslist.js```and/orclienttemplates.js``), so do not just set links without checking what is there...

Now all we need is one tool to set all jsLinks for WebParts, Views, Fields

  • I think the only way it might work is if you generate a personal view from a view that has the CSR in place. This is just a guess though, no CSR dev experience yet. – Eric Alexander Dec 9 '15 at 20:31
  • That does not work because the jslink is on the webpart, not associated with the view – Danny '365CSI' Engelman Dec 9 '15 at 20:49
  • I have never worked with personal views, but are they SPView objects, and can you get to them the same way you can get to public views, through the SPList.Views view collection? – Dylan Cristy Dec 9 '15 at 20:52
  • custom rendering using jslink works for personal views as well. check my answer – HarryB Dec 10 '15 at 11:14
  • But still, this only gets applied if the view is copied from an existing view. More valid would be Andrey Markeev's solution. A field being on many views would be more probable I guess. – Akhoy Dec 10 '15 at 17:31
0

Personal views can also be rendered with a jsLink.

What @Eric Alexander said in his comment is valid. JSLink can be attached to a view so that where ever that view is used(or gets copied to a personal view) it gets rendered using the attached JSLink file. JSLink property of a view can be set using PowerShell,CSOM,JSOM,SSOM

You can also get the guid of the view using ctx.ListSchema.View and use that guid to get the view using CSOM or JSOM and set its jsLink property.

enter image description here

  • Cool.. yes you can set jsLink on a VIEW (with code).. and when you create a Personal View from it.. it copies the jsLink setting. Cisar only works with the jsLink on WebParts. Note: for a Task list there are default VIEW jsLink settings (hierarchytaskslist.js```and/or clienttemplates.js``), so do not just set links without checking what is there... Now all we need is one tool to set all jsLinks for WebParts, Views, Fields – Danny '365CSI' Engelman Dec 10 '15 at 16:35
  • Good point about the default jsLinks for some OOTB list views such tasks , thumbnails (Images library) and promoted links (Tiles view). – HarryB Dec 10 '15 at 17:29
  • @DannyEngelman clienttemplates.js gets added automatically if it's not there – Andrey Markeev Dec 10 '15 at 21:13
  • This by the way will not work if there are some existing personal views. – Andrey Markeev Dec 10 '15 at 21:19
11

Personal views

Surely you don't actually want to edit a personal view page? This only is relevant for one user.

Rather, I think you might want to ensure that all views of a certain list have same customizations, even if personalized views are added.

CSR vs JSLink

Just to make things clear, CSR is completely separate from JSLink. They can be used together and ofter are, but you can also do CSR without JSLink. Just deploy a CSR code to the page using any method (ScriptLink, Script Editor, link on masterpage or pagelayout, etc.), and it will be applied to all views/list forms on this page.

SPContentType.JSLink

So if I assume correctly and you want certain customizations to be visible on all views of the list, including personal views, then the best solution for this would have been to use SPList.ContentTypes[0].JSLink.

Unfortunately (and I just checked that), JSLink doesn't really work on Content types.

SPField.JSLink (the solution)

Another idea could be use one of the list fields for that. It is a bit of a hack, but next step would be ScriptLink or similar, which will bloat the whole site, so maybe hack is better after all. Not the first time, y'know :)

Example code for doing this (in JSOM):

var context = SP.ClientContext.get_current();
var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
// based on testing, doesn't work for Title for some reason, but
// all other fields I tested work, so it can be any one of them
var field = list.get_fields().getByInternalNameOrTitle('AssignedTo');
// put the path of your js file here
field.set_jsLink("~sitecollection/style library/tasks.js");
field.update();
context.executeQueryAsync(
    function() { console.log('ok'); },
    function() { console.log(arguments); }
);

Go to some page of your list, e.g. to default view, and paste this into browser console, and you're done.

Notes

Execution of the script above causes tasks.js to appear:

  1. on all pages where there are views of this list that show "Assigned To" column
  2. on all list forms of this list

Because of 2., please don't forget to perform necessary checks inside your CSR template, so that customizations only affect views or whatever they should affect.

In the context of Cisar, you can actually create your customizations as usual, attached to one of the normal views, and then use the code above to attach it also to the field. This is OK, because if the URLs of the JSLink files are same (I mean, exactly same), they won't be duplicated even if included several times from different JSLinks (and ScriptLinks, because JSLink uses ScriptLink internally).

More gotchas about CSR can be found here:

  • By that token, couldn't you create an app that staples your JS as a custom action, you could then perform your hack by looking if you are on the personal view and on the desired list then do your thing, otherwise do nothing? – Eric Alexander Dec 10 '15 at 4:13
  • 1
    Sure, ScriptLink custom action is an option, but the script will then appear on every page of the site, which means extra request (and SharePoint is already slow), while SPField.JSLink approach is more targeted, so I'd rather use it instead of custom action. – Andrey Markeev Dec 10 '15 at 11:14
  • Too lazy to test.. So there is jsLinks on (Form), WebPart, View, Field, if you have different CSR files (but same Fieldname) on all of them, are they all applied? – Danny '365CSI' Engelman Dec 10 '15 at 19:50
  • If you have many CSR files, you put them into JSLink separated by | – Andrey Markeev Dec 10 '15 at 21:10
  • And yes, all relevant JSLinks are merged, duplicates removed, and the resulting list of scripts is then added to the page. – Andrey Markeev Dec 10 '15 at 21:17
1

While it's true that you can set up a JSLink for a list view web part, there is definitely also a JSLink property on Views.

I have used the <JSLink> element declaratively in a list definition schema to attach some JavaScript (non-CSR) files to a view, and they get loaded, and there is no value in the JSLink property of the list view web part. So it does work directly on views.

So, if personal views are SP.View (JSOM) objects, and you can get them out of the list's view collection, then you should be able to set the jsLink property on the view object itself.

SP.View properties on MSDN

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.