Author Topic: Summary row without using grouping  (Read 6753 times)

Digital Logix

  • Newbie
  • *
  • Posts: 12
    • View Profile
Summary row without using grouping
« on: March 30, 2016, 02:02:13 am »
My grid is using remote data with paging, sorting and filtering. I want to show a summary row without using grouping. I am using the following method in grid complete event:


                var grid1 = pq.grid("div#grid_paging", obj);
               
                function calculateSummary() {
                    var grd = $("div#grid_paging");
                    var data = grd.pqGrid('option', 'dataModel.data');
                    if (data.length > 0)
                    {
                        var totalSum = 0;
                        for (var i = 0, len = data.length; i < len; i++) {
                            var rowData = data;
                            totalSum += parseFloat(rowData["Amount"]);
                        }

                        var cm = grd.pqGrid('option', 'colModel');
                        var srow = [];
                       
                        for (var i = 0; i < cm.length; i++) {
                            var column = cm;
                            if (column.dataIndx == "Amount") {
                                srow.push("Total: " + totalSum);
                            }
                            else {
                                srow.push("");
                            }
                        }

                        var sumRows = [];
                        sumRows.push(srow);
                        grd.pqGrid({ summaryData: sumRows });
                        grid1.refresh();
                    }
                }


It is showing an empty summary row.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Summary row without using grouping
« Reply #1 on: March 30, 2016, 09:06:56 pm »
Trial version shouldn't be used for more than 30 days.

http://paramquery.com/pro/license/evaluate

If you need more time for evaluation, please write to [email protected] for extension.

thanks

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Summary row without using grouping
« Reply #2 on: March 30, 2016, 10:17:18 pm »
you haven't posted complete code but it seems that you have array of objects in dataModel.data

srow should also be an object in that case.


Code: [Select]
srow = {  Amount: "Total: " + totalSum }
« Last Edit: March 30, 2016, 10:33:25 pm by paramquery »

Digital Logix

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Summary row without using grouping
« Reply #3 on: March 31, 2016, 04:11:12 am »
Thanks, changing srow to object fixed the issue.

It is now showing summary row correctly.

How can I hide the checkboxes and custom icons (used for custom button) in summary row.

Please check my work at:

http://digitallogix.net/pqtest/

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Summary row without using grouping
« Reply #4 on: March 31, 2016, 08:53:48 pm »
Please use column.render to override the default rendering of summary row.

First add a custom property to srow:
srow = {  Amount: "Total: " + totalSum, pq_grandsummary: true };

Then in checkbox and custom button columns:
Code: [Select]
column.render = function(ui){
  if( ui.rowData.pq_grandsummary){
     return "";
  }
}

Digital Logix

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Summary row without using grouping
« Reply #5 on: March 31, 2016, 10:20:08 pm »
Thanks it works.

I have another question, the summary row did not show when using virtual scrolling.

Digital Logix

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Summary row without using grouping
« Reply #6 on: April 08, 2016, 01:34:35 am »
Please let me know if Manual Summary Row works with virtual scrolling.

Thanks

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Summary row without using grouping
« Reply #7 on: April 08, 2016, 11:28:11 am »
yes it works.

As far as the summary data is concerned there are 2 options:

1) Server side: Calculate it on the server side and update summaryData option only once.

or

2) Browser side: re-calculate summaryData in every load event or dataModel.getData() callback and update summaryData option

Code: [Select]
this.option( "summaryData", [ summaryRows ] );
« Last Edit: April 08, 2016, 11:31:13 am by paramquery »

Digital Logix

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Summary row without using grouping
« Reply #8 on: April 08, 2016, 10:09:07 pm »
Yes it works with virtual scrolling. The issue was that I was setting showBottom to false, that is why it was not showing the summary row.

I am using client side option and calculating the summary data in load event and it is working fine.