0

My list has a "Year" and "Meeting Date" field which are used for grouping which produces a result as per the image at

enter image description here

Using javascript, how do I convert the meeting date to ddmmmyy format rather than the system setting format. I could do it using a calculated column but am looking for a js solution.

Below code is currently used to hide the group titles, can this be expanded to modify the field value [Meeting Date] format. If possible, what changes to the below code would be required to get the grouped field value to show the date in ddmmmyy format:

<script type="text/javascript" language="javascript">
_spBodyOnLoadFunctionNames.push("HideHeaders");

function HideHeaders() {
    var elements = getElementsByClassName(document, "td", "ms-gb");
    var elem;
    for (var i = 0; i < elements.length; i++) {
        elem = elements[i];
        elem.childNodes[0].childNodes[1].nodeValue = "";
        elem.childNodes[1].nodeValue = 
        elem.childNodes[1].nodeValue.replace(':', 'YEAR:');
    }

    elements = getElementsByClassName(document, "td", "ms-gb2");
    for (var i = 0; i < elements.length; i++) {
        elem = elements[i];
        elem.childNodes[1].childNodes[1].nodeValue = "";
        elem.childNodes[2].nodeValue = 
        elem.childNodes[2].nodeValue.replace(':', 'Meeting Date:');
    }
}

function getElementsByClassName(oElm, strTagName, strClassName) {
    var arrElements = (strTagName == "*" && oElm.all) ? oElm.all : 
    oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for (var i = 0; i < arrElements.length; i++) {
        oElement = arrElements[i];
        if (oRegExp.test(oElement.className)) {
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}
</script>
skinnane
  • 1
  • 4

1 Answers1

0

Might be easier to use two Calculated Columns, format those and use them for Grouping

 ="Year:" & TEXT( [mydate] , "yyyy" )

 ="Meeting date:" & TEXT( [mydate] , "dd mmmm" )

Fix the sorting by adding spaces (which HTML will ignore), as Christophe blogged: https://blog.pathtosharepoint.com/2013/10/31/trick-or-treat-group-items-by-month/

Danny '365CSI' Engelman
  • 21,176
  • 7
  • 35
  • 79
  • Did that but it messed up the sorting of the groups. Could group them with a week number but I am looking for a solution via js a I have another requirement which an answer to the original question would solve. – skinnane Dec 02 '16 at 13:18
  • For JS dates, see http://sharepoint.stackexchange.com/questions/160806/changing-date-format-using-javascript/160808#160808 – Danny '365CSI' Engelman Dec 02 '16 at 13:57
  • Calculated field worked along with the sorting fix as suggested. Thx – skinnane Dec 02 '16 at 15:15