I am working on a sharepoint server 2016. and i want to show the sum of my list fields.. so i follow this appraoch:-
which worked well. but if the column i want to show the Sum of have an item which contain empty value, i will get this result sum=NaN
. so seems it can not do the sum for null values.
now i try modifying the script as follow, to check if the column is null and assign it zero as follow:-
function CalculatedFieldViewTemplate(ctx) {
if(ctx.CurrentItem.Yearof2016MLC != null){
_totalValue += parseFloat((ctx.CurrentItem.Yearof2016MLC).replace(',', ''));
return ctx.CurrentItem.Yearof2016MLC;
}
else
{
return 0;
}
}
but this did not solve the issue. i also try checking the following typeof ctx.CurrentItem.Yearof2016MLC != "undefined"
but same problem... now the Yearof2016MLC is of type number and which does not have any defualt value and it is optional... and again if there is not any empty value for the Tearof2016MLC every thing will work well. so how i can solve this?
replace()
onctx.r
. What isctx.r
?r
is your copy.ctx.r
is nothing.( )
instead of(ctx)
and all should work the same (because ctx is global object)