Search code examples
javascriptjqueryslickgrid

SlickGrid Display Aggregation at grouping level


I am following this example for grouping with aggregation: http://mleibman.github.io/SlickGrid/examples/example-grouping.html

This has grouping done in one row and Aggregation done in separate row. I want both to be displayed in same instead of having two separate rows

For e.g In above exampple i want to a single row to like + Duration : 3 (4 items) avg: 20 % cost:60 And then we click on expand button we see all details inside it.

Any suggestions?


Solution

  • You need to change the formatter and the lazyTotalsCalculation.

    • lazyTotalsCalculation = false

      formatter: function (g) {
        var total = sumTotalsFormatter(g.totals, columns[6]),
            avg = avgTotalsFormatter(g.totals, columns[3]);
        return "Duration:  " + g.value + "  <span style='color:green'>(" + g.count + " items)</span><span>avg: " + avg + "</span><span> cost: " +  (total.length>0?total.split(":")[1] : total) + "</span>" ;
      },
      

    That is the quick and dirty route. To make the code more robust instead of "hardcoding" the column index, you'll want to lookup the columns along the lines of:

    grid.getColumns()[grid.getColumnIndex("cost")]
    grid.getColumns()[grid.getColumnIndex("%")]