Related Items Sum
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi Tom,
You can either add 'total' to the list view and then pick this view in the related items control or calculate total with JavaScript:
;
You can either add 'total' to the list view and then pick this view in the related items control or calculate total with JavaScript:
Code: Select all
var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item.FieldName)
});
alert(total)
Hi Dmitry,
in the Quick Edit mode of the Related Item the sum it will not displayed. And the java script works not for me.
Can you give me more information about the script?
var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData.Row; relateditems is the css class? ctx is the name of the list?
rows.forEach(function(item) {
total += parseFloat(item.FieldName) Fieldname ist the name of the field from my project costs ?
});
alert(total);
Best wishes
Tom
in the Quick Edit mode of the Related Item the sum it will not displayed. And the java script works not for me.
Can you give me more information about the script?
var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData.Row; relateditems is the css class? ctx is the name of the list?
rows.forEach(function(item) {
total += parseFloat(item.FieldName) Fieldname ist the name of the field from my project costs ?
});
alert(total);
Best wishes
Tom
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi Tom,
Here you just need to set the right zero-based index of the Related Items control in the form:
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
Leave other code without changes.
Here you should set the right Internal Name of the field from the related list that you need to sum:
total += parseFloat(item.FieldName)
Here you just need to set the right zero-based index of the Related Items control in the form:
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
Leave other code without changes.
Here you should set the right Internal Name of the field from the related list that you need to sum:
total += parseFloat(item.FieldName)
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
Try to replace this line:
with:
To assign the result to a field, use the code:
Try to replace this line:
Code: Select all
total += parseFloat(item.FieldName);
Code: Select all
total += parseFloat(item[FieldName + '.']);
Code: Select all
fd.field('FieldName').value(total);
Hi Dmitry,
thanks for the information. If i use
var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item.Kosten)
});
fd.field('Gesamt').value(total);
The field "Gesamt" is filled.
If i use
var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item[Kosten + '.']);
});
fd.field('Gesamt').value(total);
the field "Gesamt" is not filled.
What's wrong?
Best wishes
Tom
thanks for the information. If i use
var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item.Kosten)
});
fd.field('Gesamt').value(total);
The field "Gesamt" is filled.
If i use
var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item[Kosten + '.']);
});
fd.field('Gesamt').value(total);
the field "Gesamt" is not filled.
What's wrong?
Best wishes
Tom
Hi Dmitry,
i found the error.
var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item.Kosten + ',')
});
fd.field('Gesamt').value(total);
But one question, the field "Gesamt" is filled with one number
For example: in the field "Kosten" i typed in 1000, in the field "Gesamt" i see only the number 1. I think this is a problem from javascript.
What must i do to display the number in the correct format?
Best wishes
Tom
i found the error.
var total = 0;
var rows = fd.relatedItems(0).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item.Kosten + ',')
});
fd.field('Gesamt').value(total);
But one question, the field "Gesamt" is filled with one number
For example: in the field "Kosten" i typed in 1000, in the field "Gesamt" i see only the number 1. I think this is a problem from javascript.
What must i do to display the number in the correct format?
Best wishes
Tom
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
item.Kosten contains a formatted value e.g. '1 000 $'. There should be another field, most likely it's item['Kosten.'] which contains a number. Try to replace this line:
with this:
Code: Select all
total += parseFloat(item.Kosten + ',')
Code: Select all
total += parseFloat(item['Kosten.');
-
- Information
-
Who is online
Users browsing this forum: No registered users and 22 guests