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

1 Answer 1

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/

3
  • 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. Commented Dec 2, 2016 at 13:18
  • For JS dates, see sharepoint.stackexchange.com/questions/160806/… Commented Dec 2, 2016 at 13:57
  • Calculated field worked along with the sorting fix as suggested. Thx Commented Dec 2, 2016 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.