In forms I still get a tabular view of all columns. How is it possible to modify the visualization of related items?
I’m trying to get something similar to the “classic” newsletter design.
Hi AlexZver
we have an parent list and a related one (which contains comments to the parent).
The comments should be visible like a news feed (or the “Newsletter” style known from SharePoint lists):
One of my customers would like to format the list / library control rows and columns like the JSON approach used on the SharePoint Views and Columns. Formatting would be based on form data along with list / library data in the control. While they want as much as they can get just coloring would be a start.
Example 1:
If logged in user is in the assigned to column, turn cell Green
Example 2:
If PO Number on form is in related list turn row Green & if due date is before tomorrow turn Date font color Red.
You can change the background color, font, etc. of the specific row or cell with the following code.
fd.control('SPDataTable0').ready().then(function(dt) {
//dt parameter is the same as fd.control('SPDataTable0')
var value = dt.widget.dataItems();
var row = $(dt.$el).find('tr');
var poNumber = fd.field('PONumber').value;
if(value){
for (var i = 0; i < value.length; i++){
if(value[i].Order == poNumber ) {
//sets the background color of the row to red
$(row[i+1]).attr("style","background-color:red");
//sets the font color of the cell to green
$(row[i+1].cells[2]).attr("style","color:green");
}
}
}
});
value[i].Order - where Order in is the Name of the column in List or Library control.
row[i+1].cells[2] - where 2 is the index of the column. Note that index count starts from 0.
Is there a way to keep this formatting once I add, edit or sort the list?
I looked at trying to use fd.control('AllRFIs').template but was not able to reproduce the same results with the background format & I was unable to use the $.getScript to do my date calculations.
You can use setInterval method to apply formatting periodically to the control, so in case records are deleted or added the formatting updates accordingly.
function SPDataTableStyling() {
fd.control('AllRFIs').ready().then(function(dt) {
dt.buttons[0].text = 'Add RFI';
var value = dt.widget.dataItems();
var row = $(dt.$el).find('tr');
if(value){
$.getScript('https://{mysite}.sharepoint.com/sites/pwa/Shared%20Documents/Other/moment-with-locales.js')
.then(function() {
for (var i = 0; i < value.length; i++){
var m = moment();
var b = moment(value[i].Date_x0020_Due);
var d = b.diff(m, 'days');
if (d < 0 && value[i].RFI_x0020_Status != '(3) Closed') {
$(row[i+1].cells[4]).attr("style","border-bottom:2px solid #ff6666; background-color:#ffb3b3")
} else if (d >= 0 && d <= 7 && value[i].RFI_x0020_Status != '(3) Closed') {
$(row[i+1].cells[4]).attr("style","border-bottom:2px solid #66ff66; background-color:#b3ffb3")
}
}
});
}
});
}
//call function on form load
SPDataTableStyling();
//call function periodically
setInterval(SPDataTableStyling, 1000);
Thank you. Will that have any unintended consequences with the form performance?
I achieved similar results with the following code but cannot set a background color for the entire cell (it just puts a background behind the text)
fd.control('AllRFIs').templates = {
Date_x0020_Due: function(ctx) {
var todaysDate = new Date().getTime();
var dateDue = ctx.row.Date_x0020_Due;
var dateDueTime = new Date(dateDue).getTime();
var dateDiff = Number(dateDueTime) - Number(todaysDate);
if (!dateDue) {
return '';
}
if (dateDiff < 0 && ctx.row.RFI_x0020_Status != '(3) Closed') {
return '<span style="border-bottom:2px solid #ff6666; background-color:#ffb3b3">' + dateDue + '</span>';
}
if (dateDiff >= 0 && dateDiff < 604800000 && ctx.row.RFI_x0020_Status != '(3) Closed') {
return '<span style="border-bottom:2px solid #66ff66; background-color:#b3ffb3">' + dateDue + '</span>';
}
if (dateDiff >= 604800000 && ctx.row.RFI_x0020_Status != '(3) Closed') {
return '<span>' + dateDue + '</span>'
}
if (ctx.row.RFI_x0020_Status == '(3) Closed') {
return '<span>' + dateDue + '</span>'
}
}
}