Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit modal should respect render function #220

Open
moham96 opened this issue Sep 1, 2022 · 0 comments
Open

Edit modal should respect render function #220

moham96 opened this issue Sep 1, 2022 · 0 comments

Comments

@moham96
Copy link

moham96 commented Sep 1, 2022

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant