AnsweredAssumed Answered

sum grid data

Question asked by Mr_Kirkwood on Nov 3, 2014
Latest reply on Nov 3, 2014 by Mr_Kirkwood

I am creating a dojo grid. I would like to have the grid give me unique values for the Lease Type with the sum in a column next to it. The output looks like this:

 

leasetype.PNG

I would like it to show one Lease Type with the sum of the Annual Revenue. Here is the code i am using:

 


var grid;
var myLeaseData;
var myQueryTask;
var UniqueLeaseCodes = [];
var FoundLeaseCode = false;
var myQuery;
require([
    "esri/tasks/QueryTask", "esri/tasks/StatisticDefinition", "esri/tasks/query",
    "dojo/number", "dojo/date/locale", "dojo/dom", "dojo/on",
    "dojo/_base/array", "dojo/store/Memory",
    "dgrid/OnDemandGrid", "dojo/domReady!"
], function (
        QueryTask, StatisticDefinition, Query,
        number, locale, dom, on,
        arrayUtils, Memory,
        OnDemandGrid
        ) {
    // create a dgrid 
    var sortAttr = [{
            attribute: "LEASE_TYPE",
            descending: false
        }];
    grid = new OnDemandGrid({
        store: new Memory({
            idProperty: "name"


        }),
        columns: {
            name: "Lease Type",
            annualExpense: {
                label: "Annual Expense",
                formatter: formatRound
            }
         
        },
        sort: sortAttr,
        query: {STATUS: "Active"},
    }, "grid");


    myQueryTask = new QueryTask(getUrlKlondike('Leases'));
    var myDate = new Date();
    var myMS = myDate.getMilliseconds();
    myQuery = new Query();


    myQuery.outFields = ['*'];
    myQuery.returnGeometry = false;
    myQuery.where = "(" + myMS + "=" + myMS + ")";


    myQueryTask.execute(myQuery, function (results) {

        myLeaseData = [
            {name: "", id: ""},
            {name: "", id: ""}
        ];

        for (var i = 0; i < results.features.length; i++) {
            if (results.features[i].attributes.LEASE_TYPE) {
                myLeaseData.push({
                    name: results.features[i].attributes.LEASE_TYPE,
                    annualExpense: results.features[i].attributes.ANNUAL_EXPENSE,
                    annualRevenue: results.features[i].attributes.ANNUAL_REVENUE,
                    leaseDPSF: results.features[i].attributes.DOLLARS_PER_SQ_FT,
                    objectIDCheck: results.features[i].attributes.LEASE_ID,
                    id: results.features[i].attributes.LEASE_ID,
                    OBJECTID: results.features[i].attributes.OBJECTID,
                    SQ_FT: results.features[i].attributes.SQ_FT,
                    EFFECTIVE_DATE: results.features[i].attributes.EFFECTIVE_DATE,
                    EXPIRATION_DATE: results.features[i].attributes.EXPIRATION_DATE,
                    LINK_TO_DOC: results.features[i].attributes.LINK_TO_DOC,
                    LESSEE: results.features[i].attributes.LESSEE,
                    LESSOR: results.features[i].attributes.LESSOR,
                    LEGAL_DESCRIPTION: results.features[i].attributes.LEGAL_DESCRIPTION,
                    LEASE_TERM_YEARS: results.features[i].attributes.LEASE_TERM_YEARS,
                    ANNUAL_REVENUE: results.features[i].attributes.ANNUAL_REVENUE,
                    ANNUAL_EXPENSE: results.features[i].attributes.ANNUAL_EXPENSE,
                    LESSOR_NAME: results.features[i].attributes.LESSOR_NAME,
                    LESSEE_NAME: results.features[i].attributes.LESSEE_NAME,
                    STATUS: results.features[i].attributes.STATUS,
                    CONTACT_DEPT: results.features[i].attributes.CONTACT_DEPT,
                    LEASE_USE: results.features[i].attributes.LEASE_USE,
                    LEASE_TYPE: results.features[i].attributes.LEASE_TYPE,
                    NOTES: results.features[i].attributes.NOTES,
                    DOC_ACRES: results.features[i].attributes.DOC_ACRES,
                    DOLLARS_PER_SQ_FT: results.features[i].attributes.DOLLARS_PER_SQ_FT,
                    RENEWAL_NOTIFICATION: results.features[i].attributes.RENEWAL_NOTIFICATION,
                    LEASE_ID: results.features[i].attributes.LEASE_ID
                });
            }


        }


        console.log('Query A: ' + myLeaseData.length);
        updateGrid(myLeaseData);
    });


    // formatting function for numbers
    function formatRound(value) {
        return number.round(value, 2);
    }

    function updateGrid(myLeaseData) {
        grid.store.setData(myLeaseData);
        grid.refresh();
    }


});

Outcomes