Hello @mnikitina,
Here in ss,
Thanks for look into this.
Hello @mnikitina,
Does it seem like list or library control is not ready/load after complete spRender?
i am facing above plus one more problem for that, here i write my code below and attached screenshot,
it is terrible because while i get one error for this, my all forms rules are not working, even the code user above for filter is also not working, as a security and performance, it creates problem.
Please find code below,
function calcTotal() {
var value = fd.control('Contracts').widget.dataItems();
var total = 0;
if (value) {
for (var i = 0; i < value.length; i++) {
if (value[i].MyTUMid == fd.field('Mytumlogin').value) {
if (value[i].Hours)
//total += parseInt(value[i].Hours.replace(/[^0-9.]/g, ""));
//we get number as (comma) , and we have to convert it as . (dot)
var decimalPoint = value[i].Hours.replace(",", ".");
total += parseFloat(decimalPoint);
}
}
}
fd.field('TotalHoursActiveContracts').value = total;
}
function filterDT(dt) {
dt.filter = "<Contains><FieldRef Name='MyTUMid'/><Value Type='Text'>"
+ fd.field('Mytumlogin').value + "</Value></Contains>";
dt.refresh();
}
var myVar = setInterval(calcTotal, 2000);
dtContract.ready().then(function (dt) {
filterDT(dtContract);
});
Above code, I am using to count hours from list or library control and simple filtration.
the error I am getting while using the above code.
Please lookinto this, let me know if there is problem from my end.
Thanks.
Hello @harshp924,
You are calling calcTotal function outside of the ready event. Please try out the following code:
fd.control('Contracts').ready().then(function (dt) {
var myVar = setInterval(calcTotal, 2000);
});
Thanks @mnikitina,
i was try below and it works...!
function calcTotal() {
fd.control('Contracts').ready().then(function(dt) {
//dt parameter is the same as fd.control('SPDataTable0')
//fd.control('Contracts').refresh();
//fd.control('Contracts')._dataProvider.refresh();
var datalibrary = dt.widget.dataItems();
console.log(datalibrary,"calcTotal");
var total=0;
if(datalibrary){
for(var i=0;i<datalibrary.length;i++){
if(datalibrary[i].Hours){
var decimalPoint = datalibrary[i].Hours.replace(",", ".");
total += parseFloat(decimalPoint);
}
}
console.log(total);
}
fd.field('TotalHoursActiveContracts').value = total;
});
}
I want to know that in spRender method it is good to use more than one Ready event? is it best practice vice ok or not?
Thanks.
Hello @harshp924,
I'm glad its working now!
You can add as many ready events for the control as required by your code.