SharePointJSLink (2) Change the column color in the form

Source: Internet
Author: User

SharePointJSLink (2) Change the column color in the form

Check the document properties and find that the color of the Language column has not changed:

 

To change the color, make some changes. Register an event for displayForm:

 

 

(Function () {var FieldContext ={}; FieldContext. templates ={}; FieldContext. templates. fields = {// defines an override style method "Language": {"View": FieldTemplate, "DisplayForm": DisplayTemplate} For the columns whose colors are to be modified }}; // register Context to SharePoint SPClientTemplates. templateManager. registerTemplateOverrides (FieldContext );})();


 

Then add an implementation function. Here we set the background color for the Language column.

 

 

function DisplayForm(ctx) {    var Language = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];    switch (Language) {       case "English":           return "<span style='background-color :#D9D919'>" +Language + "</span>";           break;       case "Korean (Korea)":           return "<span style='background-color :#2D882D'>" +Language + "</span>";           break;                   }}


 

The final code is:

 

function DisplayForm(ctx) {    var Language = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];    switch (Language) {       case "English":           return "<spanstyle='background-color :#D9D919'>" + Language +"</span>";           break;       case "Korean (Korea)":           return "<span style='background-color :#2D882D'>" +Language + "</span>";           break;                   }}

 

Save the file and upload it to the Style Library ).

 

Find any list item, go to the view properties page, edit page, add JSLink to the webpart attribute of the display form.

 

The following results are displayed:

 

 

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.