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>
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/

  • 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 2 '16 at 13:18
  • Calculated field worked along with the sorting fix as suggested. Thx – skinnane Dec 2 '16 at 15:15

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.