Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

SharePoint list Conditional Formatting

$
0
0

Hello!

I am trying to add some conditional formatting to my SharePoint list and I know that I have to use javascript to go about this. What I am trying to do is read some dates in a date column I have and depending on how far out that date is from today's date it will change an items background color.

More information:


I have Hiring Date column with dates formatted as the following: 01/16, 02/15, 03/15, etc... and I have another column that has a requisition number.

So for example if the date in the Hiring Date column is 90 days or less from today's date AND there requisition number is blank then that row will be yellow. If the Hiring date column is 30 days or less from today's date AND the requisition number is blank then that row will be orange. And finally if the hiring date is in the current month and there is no requisition number then the row will be red.

So far a link that helped me to format the table color depends on words instead of a formula that was performed in the javascript function.

http://techtrainingnotes.blogspot.com/2008/11/sharepoint-color-coding-sharepoint.ht

Here is what I have so far:

function CheckStatus() {
    var x = document.getElementsByTagName("TD") // find all of the TDs
    var _dueDate = new Date()
    var now = Date();

    var nowPlus30 = new Date();
    nowPlus.setDate(now.getDate() + 30);

    var nowPlus90 = new Date();
    nowPlus.setDate(now.getDate() + 90);

    if (_dueDate == '' || !_dueDate) {
        return '';
    }

    var i = 0;
    for (i = 0; i < x.length; i++) {

        if (x[i].className == "ms-vb2") //find the TDs styled for lists
        {

            if( _dueDate <= nowPlus30 ) //find the data to use to determine the color
            {
                x[i].parentNode.style.backgroundColor = 'orange'; // set the color
            }

            //repeat the above for each data value

            if (_dueDate <= nowPlus90) {
                x[i].parentNode.style.backgroundColor = 'yellow'; // set the color
            }

            if (_dueDate > nowPlus30) {
                x[i].parentNode.style.backgroundColor = 'red'; // set the color
            }


        }

    }
}

Still not working for me. A few things I am unsure of how reference are my column name which is called "Month Needed" and then the current date format. In c# I would format the string to be the following "MM/YY" in javascript not sure if there is a way to check my dates against a formatted date.

Any help on how to go about this would be great!

Thank you



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>