Friday, July 31, 2020

JSLink for customizing list items using date and time as an example

In this article, I will show a simple example of how to separate the date and time string of list items, using the "example " of one of the ask in the MSDN forum.
(function() { 
        var linkFilenameFiledContext = {}; 
        linkFilenameFiledContext.Templates = {}; 
        linkFilenameFiledContext.Templates.Fields = { 
            "Date": { "View": linkFilenameFiledTemplate } 
        };
            SPClientTemplates.TemplateManager.RegisterTemplateOverrides(linkFilenameFiledContext); 
    })(); 

    function linkFilenameFiledTemplate(ctx) {
        var currentdate = ctx.CurrentItem["Date"];
        if (currentdate != "") {
        var date = currentdate.toString().substring(currentdate.lastIndexOf(" "), - 1);
        var time = currentdate.toString().substring(currentdate.lastIndexOf(" ") + 1);
        return date + "<br>" + time;
        }
    }

Result:
Happy Coding!

No comments:

Post a Comment