2

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.

json

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Saif
  • 2,611
  • 3
  • 17
  • 37
  • what is tha plugin you are using to display the table using json? is it DataTables? – Imesh Chandrasiri Nov 24 '15 at 09:31
  • Possible duplicate of [Sorting JavaScript Object by property value](http://stackoverflow.com/questions/1069666/sorting-javascript-object-by-property-value) – tRx Nov 24 '15 at 09:33
  • I am using JQuery to retrieve data from function in JSON format. So the function is like `public List GetData()` – Saif Nov 24 '15 at 09:37
  • 1
    3 upvotes for what? can't get it. – Jai Nov 24 '15 at 10:03
  • anything you cannot get? I will explain it . my question is very simple and I just want to group json data by group_name and instead of showing undefined label as shown in attached picture I want to show group_name – Saif Nov 24 '15 at 10:08
  • For better understanding, Please provide a **working demo** (*code snippet,JSfiddle* ...) – Kishore Sahasranaman Nov 24 '15 at 10:27

1 Answers1

0

You can use Underscore.js library to achieve this.

var groupedData = _.groupBy(json, 'group_name');