Has anyone managed to incorporate the setting of the viewstyle into a CSR?

I have come across the following links:

Using CSR to change row color - how do I keep the view style shaded view?



I have tried the following code, and the viewstyle (in particular the alternate coloured lines) is not displaying. I have confirmed that 17 is the correct number for our site.

(function () {
   var ctx = {};
   ctx.ViewStyle = 17; 
   ctx.Templates = {};
   ctx.ViewStyle = 17;
   ctx.ViewStyle = 17;

It would have been useful to have used the inbuild style, but is the only option to render the lines individually?


The particular problem that I am having is that on the view, the fields have a Group clause. I have discovered that using the grouping with a CSR removes the column headings. If I remove the grouping from the view, the rendering works as expected.

So how do I add the columns titles back in with both the render and the grouping functions?

I have added in some prerender code to see what is in the header HTML (class="ms-listviewtable"), but can see no column headers. This seems to contradict what was on the codeproject website.

Anyway, I've tried some code according to the site below to try and process the Current column titles through code similar to that allItemsRenderAnnouncements(ctx) on the website


function allItemsRenderAnnouncements(ctx) {
  // create item style
  var itemStyle = "width:600px;margin:12px;";
  var titleStyle = "background-color:black;color:white;padding:2px; padding-left:12px;font-size:1.25em;border-top-left-radius:16px";
  var bodyStyle = "border:black 1px solid;background-color:#ddd;color:#333;padding:4px;border-bottom-right-radius:16px";

  // create and return HTML for each item
  return "<div style='" + itemStyle + "'>" +
         "<div style='" + titleStyle + "'>" + ctx.CurrentItem.Title    + "</div>" +
         "<div style='" + bodyStyle + "'>" + ctx.CurrentItem.Body + "</div>" +

and the fields ctx.CurrentItem.Title are coming up as '.', which seems to be related to the fact that the table is grouped, therefore no column headings?????

So, no luck with that idea.

My next hope was that if the ctx.ViewStyle = 17; couldn't stick, then perhaps I could work out what was in the HTML before the CTX.TEMPLATES were cleared using a prerender, save it to a variable, then in the subsequent Templates.Header call (or postrender call), reinstate that value as it was before in the prerender state.

Alternatively I use jquery to somehow retrieve this value using some code like $(“table.ms-???? ....
then restore the settings with this value in the CSR postrender or .Header call?

I'm really lost on this one. A very frustrating problem, that should be so simple.

1 Answer 1


Part of the problem I was having was that the column headings were not coming out either.

Solutions to both problems was posted here:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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