MDS will not be problem if you use RegisterModuleInit
:
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
function init() {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
Templates: {
Fields: {
"<field internal name>": {
View: function(ctx) {
<your code>
return <return html>;
}
}
}
}
});
}
RegisterModuleInit(
SPClientTemplates.Utility.ReplaceUrlTokens("~siteCollection/Style Library/myfile.js")
, init);
init();
});
Furthermore
- Do not proces Dates as Strings
- SharePoint provides a
GetDaysAfterToday
- SharePoint provides String.format method
Formatting can be as concise as:
"Created": {
View: function(ctx) {
var value=new Date(ctx.CurrentItem[this.Name]);
var daysDiff=GetDaysAfterToday(value);
var color='inherit';
if(daysDiff<0) color='red';
return String.format("<span style='color:{0}'>{1:d}</span>",color,value);
}
For more Date & Code examples see: https://sharepoint.stackexchange.com/search?q=getdaysaftertoday