0

The code I have it's used to change colors on a row in a custom list with a ribbon button when the ribbon button is pressed you got a dialog box comming upp with 4 buttons with 4 differt colors.

The problem is that i can only selecet one item at the time to change color but i want to select as many item i want, how do i do it? I use SharePoint online and Visual Studio 2013. The color code is in a seperate JS Link file.

This is the code:

'use strict';

var clientContext, hostweburl, parentContext, parentWeb, selectedItem, itemId, listId;

clientContext = new SP.ClientContext.get_current();
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
listId = decodeURIComponent(getQueryStringParameter("SPListId"));
itemId = decodeURIComponent(getQueryStringParameter("SPListItemId"));
parentContext = new SP.AppContextSite(clientContext, hostweburl);
parentWeb = parentContext.get_web();
selectedItem = parentWeb.get_lists().getById(listId).getItemById(itemId);


$(document).ready(function () {
clientContext.load(selectedItem);
clientContext.executeQueryAsync(OnSuccess, OnFail);
});



function OnSuccess() {

$("#Blue").click(function () {

    selectedItem.set_item('Color', 'Blue');
    selectedItem.update();
    clientContext.load(selectedItem);
    clientContext.executeQueryAsync(function () { window.parent.postMessage('CloseCustomActionDialogRefresh', '*'); }, function (sender, args) { alert('Error:' + args.get_message()); });
});

$("#Green").click(function () {

    selectedItem.set_item('Color', 'Green');
    selectedItem.update();
    clientContext.load(selectedItem);
    clientContext.executeQueryAsync(function () { window.parent.postMessage('CloseCustomActionDialogRefresh', '*'); }, function (sender, args) { alert('Error:' + args.get_message()); });
});

$("#Red").click(function () {

    selectedItem.set_item('Color', 'Red');
    selectedItem.update();
    clientContext.load(selectedItem);
    clientContext.executeQueryAsync(function () { window.parent.postMessage('CloseCustomActionDialogRefresh', '*'); }, function (sender, args) { alert('Error:' + args.get_message()); });
});

$("#Transparent").click(function () {

    selectedItem.set_item('Color', 'No Color');
    selectedItem.update();
    clientContext.load(selectedItem);
    clientContext.executeQueryAsync(function () { window.parent.postMessage('CloseCustomActionDialogRefresh', '*'); }, function (sender, args) { alert('Error:' + args.get_message()); });
});

}


function OnFail() {
alert("Error");
}


function getQueryStringParameter(paramToRetrieve) {
var params =
document.URL.split("?")[1].split("&");
var strParams = "";
for (var i = 0; i < params.length; i = i + 1) {
    var singleParam = params[i].split("=");
    if (singleParam[0] == paramToRetrieve)
        return singleParam[1];
}
}
1

When it comes to modifying the view of a list or it's items in SharePoint 2013 or SharePoint online recommended approach is to use JSLink and display templates..

JSLink & Display Templates

JSLink and Display Templates Part 2 – Changing how individual fields display

| improve this answer | |
  • Not what i'm looking for Want to know how i can do changes to more then one item at the time – linkan94 Sep 22 '14 at 11:43
0

you can use the below jquery in Script Editor web part:

$(document).ready(function(){$Text = $("td.ms-cellstyle.ms-vb2:contains('Open')");$Text.parent().css("background-color", "#FF9900");});
| improve this answer | |
  • I dont want to use script editor want to do this in my code – linkan94 Sep 22 '14 at 10:05

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.