Sharepoint 2013 list using JS Link

Source: Internet
Author: User

Use JS link to register a script with the SharePoint list, rewrite the field template, and change the format and style for fields that match the criteria. But there is a problem is, page postback words, JS will not be triggered, do not know how to solve, have to know the message under, thank you.

Add the JS Link in a WebPart or a list

JS link address format as follows, cannot write relative path or absolute path, otherwise alert does not come out.

~sitecollection/siteassets/js/xxxxxx.js

Instance code, the function is, a URL type field, if the text date of the field is displayed in yellow this month, is the next month's display pink, is the last month's display green.

Field type

var mydate = new Date (); var month=mydate.getmonth () +1; (function () {///Create object that has the context information about the field that we want to change it ' s output     Render var gatefiledcontext = {};     Gatefiledcontext.templates = {}; GateFiledContext.Templates.Fields = {//Apply the new rendering for priority field on List View "gate_x002         0_4_x0020_due_x0020_dat ": {" View ": Gatefiledtemplate}," Gate_x0020_5_x0020_due_x0020_dat ": { "View": Gatefiledtemplate}, "Gate_x0020_6_x0020_due_x0020_dat": {"View": Gatefiledtemplate}, "gate_x0020_7_     X0020_due_x0020_dat ": {" View ": Gatefiledtemplate}};  SPClientTemplates.TemplateManager.RegisterTemplateOverrides (Gatefiledcontext);  })(); This function provides the rendering logic for List view function gatefiledtemplate (CTX) {var gateorgin=ctx. Currentitem[ctx.    Currentfieldschema.name]; var gate = ctx. Currentitem[ctx. currentfieldschema.name+ '. Desc '];    if (gate!= "") {var value=parseint (gate.split ('/') [0]); if (value==month+1) {return "<span style= ' Background-color:pink; '     > "+ gate+" </span> ";     } else if (value==month) {return "<span style= ' Background-color:yellow ' >" + gate+ "</span>";     } else if (value==month-1) {return "<span style= ' Background-color:green ' >" + gate+ "</span>";    }else{return "<a href= '" +gateorgin+ ">" + gate+ "</a>";;  }    } }

Effect

The demo above MSDN

https://code.msdn.microsoft.com/office/Client-side-rendering-JS-2ed3538a

Sharepoint 2013 list using JS Link

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.