jqxgrid-05.Grouping

by codinine

HTML

<script src="https://www.jqwidgets.com/jquery-widgets-demo/jqwidgets/jqx-all.js"></script>
<link rel="stylesheet" href="https://www.jqwidgets.com/jquery-widgets-demo/jqwidgets/styles/jqx.base.css">
<link rel="stylesheet" href="https://jqwidgets.com/public/jqwidgets/styles/jqx.energyblue.css">
<div id='jqxWidget' style="font-size: 13px; font-family: Verdana; float: left; width:100%">
  <div id="jqxgrid">
  </div>
</div>

JavaScript

$(document).ready(function () {
var data = '[{ "name": "홍길동", "age": "23", "address": "경기","phone": "010-1234-XXXX", "birthday": "1990-02-05","allowance": 5000, "gender":"남"}, { "name": "이몽룡", "age": "18", "address": "서울","phone": "010-9999-XXXX", "birthday": "1995-06-10","allowance": 20000, "gender":"남"}, { "name": "성춘향", "age": "18", "address": "경기","phone": "010-1593-XXXX", "birthday": "1995-08-23","allowance": 12000, "gender":"여"}, { "name": "김흥부", "age": "32", "address": "서울","phone": "010-2854-XXXX", "birthday": "1984-07-11","allowance": 8000, "gender":"남"}, { "name": "박놀부", "age": "35", "address": "경기","phone": "010-4675-XXXX", "birthday": "1982-05-22","allowance": 35000, "gender":"남"}, { "name": "심청이", "age": "21", "address": "서울","phone": "010-8948-XXXX", "birthday": "1991-11-25","allowance": 15000, "gender":"여"}]';

  var source = {
    datatype: "json",
    datafields: [
        {name: 'name',type: 'string'},
        {name: 'age',type: 'int'},
        {name: 'address',type: 'string'},
        {name: 'phone',type: 'string'},
        {name: 'birthday',type: 'date'},
        {name: 'allowance',type: 'number'},
        {name: 'gender',type: 'string'}
    ],
    localdata: data
  };
  var dataAdapter = new $.jqx.dataAdapter(source);
  
    var groupsrenderer = function (text, group, expanded, data) {
    var title = data.groupcolumn.text + ': ' + group;
    var allowance_sum;
        if (data.subItems.length > 0) {
            allowance_sum = this.getcolumnaggregateddata('allowance', ['sum'], true, data.subItems);
        } else {
           var rows = new Array();
            var getRows = function (group, rows) {
                if (group.subGroups.length > 0) {
                    for (var i = 0; i < group.subGroups.length; i++) {
                        getRows(group.subGroups[i], rows);
                    }
                } else {
                    for (var k = 0; k < group.subItems.length; k++) {
                       ...