Author Topic: SummaryData not working  (Read 853 times)

ibizlink

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 8
    • View Profile
SummaryData not working
« on: January 05, 2022, 07:13:19 pm »
Hi,

I am trying to implement summary data at the bottom of grid (or Column total).

Paramquery is on the modal and I have the below code for paramquery to be shown on the modal.

   $("#modal_" + $this.variables.vModal).on("shown.bs.modal", function () {
                $this.variables.vGrid.refresh();
    });

Paramquery is working okay but doesn't show the total numbers.
(it caculates the total nubmers correctly in log but not showing the total numbers on the summary line.)
I can see the summary line but nothing shown up there.

Please help!




                    let obj = {
                        showTop: false,
                        height: 350,
                        resizable: true,
                        filterModel: { on: true, mode: "AND", header: false },
                        swipeModel: { on: 'touch' },
                        stripeRows: false,
                        editable: false,
                        dataModel: { data: responseData },
                        colModel: $this.variables.colM,
                        numberCell: { show: false },
                        wrap: true,
                        hwrap: true,
                        sortModel: { ignoreCase: true },
                        scrollModel: { autoFit: false },
                        menuIcon: true,
                        postRenderInterval: -1,
                        create: function () {
                            const $grid = this;
                            $.getJSON("/core/get/getParamQueryState?query=" + $this.variables.vPqGrid, function (response) {
                                $grid.loadState({ state: JSON.parse(response), refresh: true });
                            });
                        }
                    }

                    $this.variables.vGrid = pq.grid("#collectionSummaryGrid", obj);
                    $this.variables.vGrid.option('summaryData', $this.calculateSummary());


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: SummaryData not working
« Reply #1 on: January 05, 2022, 11:31:52 pm »
Please call refresh method after setting summaryData option dynamically.

or

you could also use excel formulas in the summary rows, e.g., https://paramquery.com/pro/demos/summary_json

ibizlink

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: SummaryData not working
« Reply #2 on: January 06, 2022, 09:49:26 am »
Thanks for your reply and I prefer to use refresh method after setting summaryData option but it doesn't work.

It works with using excecl formulas but don't want to use it as when it export it doesn't make sense. (Formula inherited in the excel template and looks funny... (e.g. SUM(G:G) means that it includes its cell self in the formula...)

I call refresh method after summaryData option like  $this.variables.vGrid.refresh(); and nothing shown up in the summary row...
My calcuateSummary function is as per below..


        calculateSummary: function () {
            const $this = this;
           
            let payhourTotal = 0,
                profitTotal = 0,
                data = $this.variables.vGrid.option('dataModel.data');

            for (var i = 0; i < data.length; i++) {
                payhourTotal += data.totalhours;
            }

            let totalData = ["Total: ", "", "", "", "", payhourTotal];
            return [totalData]; //2 dimensional array.
        }

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: SummaryData not working
« Reply #3 on: January 06, 2022, 10:53:18 am »
1. Field names are missing in yours' summary data.

Please add field names / dataIndx:
Code: [Select]
let totalData = [ dataIndx1: "Total: ", dataIndx2: "", ...];

2. Excel formulas can be modified or entirely removed while export to Excel.