2

I have a field in my SharePoint list of type Hyperlink.

I want to format the list view so that all the items in it will display as bullet items.

I am using JSLink and below is my code. I want the DOM property URL.DESC. When I tried overrideCtx.CurrentItem.URL.desc it is not working.

However it is showing in the DOM.

enter image description here

Code:

(function () {
    var overrideCtx = {};
    overrideCtx.Templates = {};
     overrideCtx.Templates.Header = " " +
        "<hr><ul id='unorderedlist'>";

    overrideCtx.Templates.Item = CustomItem;
    overrideCtx.Templates.Footer = "</ul>";
    overrideCtx.BaseViewID = 1;
    overrideCtx.ListTemplateType = 103;
    overrideCtx.OnPreRender = preRenderHandler;
    overrideCtx.OnPostRender = postRenderHandler;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();

function CustomItem(overrideCtx) {
    var ret = "<li>"+ overrideCtx.CurrentItem.URL + "</li>";
    //console.log("Testqwew"+ret);
    return ret;
}
// The preRenderHandler attends the OnPreRender event
function preRenderHandler(ctx) {

    // Override the default title with user input.
    //ctx.ListTitle = prompt("Type a title", ctx.ListTitle);
}

// The postRenderHandler attends the OnPostRender event
function postRenderHandler(ctx) {

    // You can manipulate the DOM in the postRender event
    var ulObj;
    var i, j;

    ulObj = document.getElementById("unorderedlist");

    // Reverse order the list.
    for (i = 1; i < ulObj.children.length; i++) {
        var x = ulObj.children[i];
        for (j = 1; j < ulObj.children.length; j++) {
            var y = ulObj.children[j];
            if(x.innerText<y.innerText){                  
                ulObj.insertBefore(y, x);
            }
        }
    }
}
2

Try using:

var urlDesc = overrideCtx.CurrentItem['URL.desc'];

You can create a link like:

var urlLink = ctx.overrideCtx.URL;
var urlDesc = ctx.overrideCtx['URL.desc'];
var appendlnk = "<a href=" + urlLink + " target='_blank'>" + urlDesc + "</a>";  

Source: How to get the description of Hyperlink column of Custom List using JSLink

1
3

Sorry for the short answer, but this is how you get the URL's description:

ctx.CurrentItem["URL.desc"]

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.