Totals in view

Hello- I’m looking to have a total at the bottom of my list view in my app. I have an app that has all my donor information and at the bottom of the view I would like to see the total of the donations. I know I can create a chart to see this total, but would rather have it directly in my view. Any suggestions? 

Hello Natalie!

The following is an example of how to display a total on the Record List page:

  1. Using the Record List Event, trigger an event of when to show the totals.*1

  2. Using the kintone REST API Request, run the “Get Records” API to obtain all the records in your app.*2

  3. Add all the obtained data using JavaScript.

  4. Display the sum data on the Record List page.*3

*1 Event lists for the Record List is noted on the following page:
kintone Developer Network - List of Events for the Record List
https://developer.kintone.io/hc/en-us/articles/212494758/

*2 Since the limit of Get Records API is 500, you will need to loop the Get Records API in case if it goes over the limit. Also, even though data information of Record List is inside the event object, it only includes the information of what is displayed in the list and the max display is 100 records. Thus, we are using REST API for this case)

*3 Since placing/displaying a total in the Record List is similar to placing buttons explained on the following page, this page should be useful in doing so.

kintone developer network - Add Buttons (Record List_
https://developer.kintone.io/hc/en-us/articles/213149437/

We recommend placing  at either “kintone.app.getHeaderMenuSpaceElement()” or “kintone.app.getHeaderSpaceElement()” since if placed in other locations, the DOM structure may change at the update of kintone so it may corrupt the display.

 

For Yuzo’s point 2, there’s actually an article with a sample for getting all records from an app
https://developer.kintone.io/hc/en-us/articles/230613327

Thank you both, this was very helpful!

Hi, I am trying to do this. I feel that I am close, but I know I am missing a key component - could anyone take a look and see if anything stands out?

(function () {
"use strict";

kintone.events.on('app.record.index.show', function(event){

if (document.getElementById('my_button') != null) {
return;
}

var button = document.createElement('button');
button.id = 'my_button';
button.innerHTML = 'Show Total';
kintone.app.getHeaderMenuSpaceElement().appendChild(button);

function fetchRecords(appId, opt_offset, opt_limit, opt_records) {
var offset = opt_offset || 0;
var limit = opt_limit || 100;
var allRecords = opt_records || [];
var params = {app: appId, query: 'limit ' + limit + ' offset ' + offset};
return kintone.api('/k/v1/records', 'GET', params).then(function(resp) {
allRecords = allRecords.concat(resp.records);
if (resp.records.length === limit) {
return fetchRecords(appId, offset + limit, limit, allRecords);
}
return allRecords;
});
}

button.onclick = function myFunction(item) {
fetchRecords(kintone.app.getId()).then(function(records) {
console.log(records);
var numbers = record['number']['value'];
function getSum(total, num) {
return total + num;
}
kintone.app.getHeaderMenuSpaceElement().innerHTML = numbers.reduce(getSum);
});
}
});
})();