Robert,
An awesome awesome widget!!!
I am looking for some guidance as to how or where I modify code to be able to display multiple field sum's in the results tab.
I would like to know where/what function to look at to make these changes. I have about 15 fields to sum and display in results.
Thanks!
Rupali
Solved! Go to Solution.
Rupali,
Well I am not sure how you are going to format the text to display the results for 15 field sums.
If you look in the Widget.js at line 2275 (in 2.0.1.3 version) you will find this block of code:
if(sumfield){
sumTotal = 0;
for ( i = 0, slen = this.currentFeatures.length; i < slen; i++) {
var feature = this.currentFeatures;
sumTotal += Number(feature.attributes[sumfield]);
}
numFormat = this._getNumberFormat(sumfield, layerIndex);
if (numFormat) {
args = numFormat.split("|");
/*value,percision,symbol,thousands,decimal*/
sValue = this._formatNumber(sumTotal, args[0] || null, args[1] || null, args[2] || null);
}
currFormat = this._getCurrencyFormat(sumfield, layerIndex);
if (currFormat) {
args2 = currFormat.split("|");
/*value,percision,symbol,thousands,decimal*/
sValue = this._formatCurrency(sumTotal, args2[1] || null, args2[0] || null, args2[2] || null, args2[3] || null);
}
console.info(layerConfig.sumlabel + ': ' + sValue || sumTotal);
this.divSum.innerHTML = layerConfig.sumlabel + ' ' + sValue;
}
This the block you would have to modify to add more sum fields
You will probably have to make some css adjustment to fit 15 fields as well to the Widget.html label element that the string is added to:
<label data-dojo-attach-point="divSum" class="esearch-sum" style="display:none;"></label>
style.css
.widget-esearch .esearch-sum { position: absolute; width: 100%; height: auto; left: 0; right: 0; bottom: 0; overflow-x: hidden; overflow-y: hidden; }
Rupali,
Well I am not sure how you are going to format the text to display the results for 15 field sums.
If you look in the Widget.js at line 2275 (in 2.0.1.3 version) you will find this block of code:
if(sumfield){
sumTotal = 0;
for ( i = 0, slen = this.currentFeatures.length; i < slen; i++) {
var feature = this.currentFeatures;
sumTotal += Number(feature.attributes[sumfield]);
}
numFormat = this._getNumberFormat(sumfield, layerIndex);
if (numFormat) {
args = numFormat.split("|");
/*value,percision,symbol,thousands,decimal*/
sValue = this._formatNumber(sumTotal, args[0] || null, args[1] || null, args[2] || null);
}
currFormat = this._getCurrencyFormat(sumfield, layerIndex);
if (currFormat) {
args2 = currFormat.split("|");
/*value,percision,symbol,thousands,decimal*/
sValue = this._formatCurrency(sumTotal, args2[1] || null, args2[0] || null, args2[2] || null, args2[3] || null);
}
console.info(layerConfig.sumlabel + ': ' + sValue || sumTotal);
this.divSum.innerHTML = layerConfig.sumlabel + ' ' + sValue;
}
This the block you would have to modify to add more sum fields
You will probably have to make some css adjustment to fit 15 fields as well to the Widget.html label element that the string is added to:
<label data-dojo-attach-point="divSum" class="esearch-sum" style="display:none;"></label>
style.css
.widget-esearch .esearch-sum { position: absolute; width: 100%; height: auto; left: 0; right: 0; bottom: 0; overflow-x: hidden; overflow-y: hidden; }
Thank you very much!!
This info is very helpful! I will try and make those edits and let you know how it goes…
-Rupali
Robert,
Sorry, I will need help with this. Its a complex script and I am not able to figure out where exactly I change the code to allow for multiple sum fields. Currently only one field can be summed.
I would appreciate some extra help from you, have a time sensitive project.
Thanks,
Rupali
Rupali,
Exactly how would you expect this to look like for 15 fields?
Robert,
I agree 15 fields total would ‘not’ look good in that results panel. But, Is it possible to sum the fields and display them in a new panel, for e.g. add a new tab to the widget showing just the totals of the fields selected to sum.
Please suggest any ideas you might have…
Is that doable?
Thanks,
Rupali
Rupali,
Yes that is doable but this is not going to happen probably before your deadline. This will take time for me to workout the UI changes and code to it will be added to a possible enhancement list for future releases. I don't have the time to spend on this right now.
Robert,
Sure no problem. I will look forward to future release of the widget. Meanwhile, I will try use your previous instructions.
Thank you very much for your time and help!
-Rupali
Hi Robert,
sorry for bugging you again. Could you point me to right direction as to how do I allow for multiple sum fields?
I am thinking of storing all sum field values into an array and then looping through each value using the function below to output totals in the div...
Is that a right approach?
if(sumfield){
sumTotal = 0;
for ( i = 0, slen = this.currentFeatures.length; i < slen; i++) {
var feature = this.currentFeatures;
sumTotal += Number(feature.attributes[sumfield]);
//alert(feature.attributes[sumfield]);
}
numFormat = this._getNumberFormat(sumfield, layerIndex);
if (numFormat) {
args = numFormat.split("|");
/*value,percision,symbol,thousands,decimal*/
sValue = this._formatNumber(sumTotal, args[0] || null, args[1] || null, args[2] || null);
}
currFormat = this._getCurrencyFormat(sumfield, layerIndex);
if (currFormat) {
args2 = currFormat.split("|");
/*value,percision,symbol,thousands,decimal*/
sValue = this._formatCurrency(sumTotal, args2[1] || null, args2[0] || null, args2[2] || null, args2[3] || null);
}
console.info(layerConfig.sumlabel + ': ' + sValue || sumTotal);
this.divSum.innerHTML = layerConfig.sumlabel + ' ' + sValue;
}
Rupali,
That sounds like a good plan you would just have to remove the
this.divSum.innerHTML = layerConfig.sumlabel + ' ' + sValue; and store the sum for that particular field in a var and then update the divSum.innerHTML once you have finished looping through all the sum fields.