Skip to content

Edit modal should respect render function #220

@moham96

Description

@moham96

Hi,
My backend (Laravel) returns data like so:

{
    "draw": 0,
    "recordsTotal": 1,
    "recordsFiltered": 1,
    "data": [
        {
            "id": 1,
            "name": "super",
            "branch_id": null,
            "created_at": "2022-09-01T22:02:12.000000Z",
            "updated_at": "2022-09-01T22:02:12.000000Z",
            "branch": null,
            "roles": [
                {
                    "id": 3,
                    "name": "super-admin",
                    "guard_name": "web",
                    "created_at": "2022-09-01T22:02:12.000000Z",
                    "updated_at": "2022-09-01T22:02:12.000000Z",
                    "pivot": {
                        "model_id": 1,
                        "role_id": 3,
                        "model_type": "App\\Models\\User"
                    }
                }
            ]
        }
    ],
    "queries": [
        {
            "query": "select count(*) as aggregate from `users`",
            "bindings": [],
            "time": 0.28
        },
        {
            "query": "select count(*) as aggregate from `users`",
            "bindings": [],
            "time": 0.22
        },
        {
            "query": "select * from `users`",
            "bindings": [],
            "time": 0.25
        },
        {
            "query": "select * from `branches` where 0 = 1",
            "bindings": [],
            "time": 0.31
        },
        {
            "query": "select `roles`.*, `model_has_roles`.`model_id` as `pivot_model_id`, `model_has_roles`.`role_id` as `pivot_role_id`, `model_has_roles`.`model_type` as `pivot_model_type` from `roles` inner join `model_has_roles` on `roles`.`id` = `model_has_roles`.`role_id` where `model_has_roles`.`model_id` in (1) and `model_has_roles`.`model_type` = ?",
            "bindings": [
                "App\\Models\\User"
            ],
            "time": 0.67
        }
    ],
    "input": []
}

I want to parse the roles array and show/edit the name of the role in the datatable, I did this in the columnDefs:

{
                       "data": "roles",
                       "title": "role",
                       type: "text",
                       render: function(data, type, row, meta) {

                           if (data == null || row == null)
                               return null;
                           return data.map(x=>x.name)

                       }
                   },

which works fine and show 'super-admin' in the datatable, but when I click 'edit' it shows "[Object Object]", so it seems it doesn't use data from the render function? how can I solve this ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions