I don't understand how to use a Nested data object array mixed data

I don't understand how to use a Nested data object array mixed data

kabedakabeda Posts: 6Questions: 1Answers: 0
edited March 2017 in Free community support

Hi,
I have data received form Server-side processing way.
It get this kind of row data :

    {
      "id": 67,
      "nom": "Amir Parker Jr.",
      "email": "leda94@keeling.com",
      "actif": "<span class=\"glyphicon glyphicon-ok text-success\"> </span>",
      "parent": "Murl Kessler",
      "roles": [
        {
          "id": 4,
          "name": "Commercial",
          "categorie": "A",
          "order": 4,
          "created_at": "2017-03-14 12:58:38",
          "updated_at": "2017-03-14 12:58:38",
          "pivot": {
            "user_id": 67,
            "role_id": 4
          }
        }
      ],
      "action": "<a href=\" http://satisf.loc/gestion/users/67/edit\" class=\"btn blue btn-xs\"> <i class=\"fa fa-edit\"></i> Modifier </a>"
    },

In my javascript, I have

        "columns": [
            {data: 'nom'},
            {data: 'email'},
            {data: "roles.0.name"},
            {data: 'parent'},
            {data: 'actif', className: 'dt-center'},
            {data: 'action', orderable: false, searchable: false}
        ],

Every thing worked well before until I added the column 2 (role). I have [object Object] and I can't use the ordering option.

How I could retrieve the data form this nested object/array?
Thanks

Replies

  • allanallan Posts: 63,871Questions: 1Answers: 10,525 Site admin

    You need to use the array syntax of the columns.data option. For example data: 'roles[, ].name'.

    Allan

  • kabedakabeda Posts: 6Questions: 1Answers: 0
    edited March 2017

    Thanks allan,

    It works but as if I use {data: "roles.0.name"} it gave me the same error when I try to reorder this column.

    DataTables warning: table id=utilisateurs - Ajax error. For more information about this error, please see http://datatables.net/tn/7
    

    and I got SQL error

    Column not found: 1054 Champ 'roles[, ].name' unknown in order clause (SQL: select `users`.`id`, `users`.`nom`, `users`.`email`, `users`.`actif`, `users2`.`nom` as `parent` from `users` inner join `users` as `users2` on `users`.`id_parent` = `users2`.`id` order by `roles[, ]`.`name` asc limit 10 offset 0)
    

    Do I have to disable the order by orderable: false or could the order works with some other method?

  • allanallan Posts: 63,871Questions: 1Answers: 10,525 Site admin

    Are you using the Editor PHP or .NET libraries here?

    Yes, you probably will need to disable sorting on that column. Certainly the Editor libraries don't support sorting MJoined columns when server-side processing is enabled.

    Allan

This discussion has been closed.