How to group JSON data

421
November 26, 2016, at 10:02 PM

How to group JSON data using group_name

Json :

[
{"fullname":"fffffffff","email":"sss@gg","mobile":"3333333333","designation":"ggg","group_name":"engineers"},
{"fullname":"ddddddddddd","email":"sssg@gg","mobile":"3333333333","designation":"fffff","group_name":"programmers "},
{"fullname":"hhhhhhhhh","email":"email@hotmail.com","mobile":"020202028347","designation":"programmer","group_name":"engineers"},
]

Here I appended it dynamically to table.

jQuery:

 function (data) {
     $("#view_table").ViewTable('option', 'data', data);
 }

I managed to append data to table but it cannot be grouped and that why it shows undefined as shown in attached picture.

Answer 1

You can use Underscore.js library to achieve this.

var groupedData = _.groupBy(json, 'group_name');
READ ALSO
I don't know why same value is not correct [duplicate]

I don't know why same value is not correct [duplicate]

This question already has an answer here:

196
Jquery parseJSON not getting value

Jquery parseJSON not getting value

I am very new in cakephp and JSONHere I am trying to fetch a list by ajax and trying to put it as a input value

338