Patrick Kwinten
Patrick Kwinten

Reputation: 2048

DataTables - -how to get rowgrouping working with objects as data

I am using datatables and here is how my data looks like:

{
    "data": [{
        "request": {
            "responsible": "Pete Jackson",
            "valuta": " EUR",
            "customer": "Jim Manner",
            "office": "123 Houston",
            "UNID": "9D574D34B9140D3CC1257B8E002A487E"
        }
    }, {
        "request": {
            "responsible": "Jane Awesome",
            "valuta": " EUR",
            "customer": "Christian Slater",
            "office": "503 New York",
            "UNID": "2444DAA352E89A44C1257B8E002A487F"
        }
    }]
}

The datatables columns I have defined as followed:

'columns': [{
            data: 'request.office',         
            'render': function(data) {
                return data;
            }
        }, {
            data: 'request.responsible',       
            'render': function(data) {
                return data;
            }
        }, {
            data: 'request.customer', 
            'render': function(data) {
                return data;
            }
        }
]

Now I want to apply rowGrouping according the following example that I have found: http://live.datatables.net/migixiqi/1/edit

However it uses the rows for grouping and its seems the columns defined as dataSrc are considered as objects cause I get 'No group' returned as row group label.

How can I send in a real value as source in the rowgroup definition instead of the (expected) column value?

Upvotes: 1

Views: 1361

Answers (1)

davidkonrad
davidkonrad

Reputation: 85528

Perhaps I dont understand what you are hoping to do, but you can just pass the JSON path to the rowGroup.dataSrc exactly as you do with columns.data :

rowGroup: {
  dataSrc: 'request.customer' //just a guess you want to group by custumer
},

http://jsfiddle.net/tgsz78jk/

PS: render() callbacks are unnecessary unless you actually need to do something special with a columns content, sort, filter or search behaviour.

Upvotes: 1

Related Questions