Skip to content
Advertisement

Laravel Yajra Datatables [object Object],[object Object] Error

Recording data in array format to database workers column. I would then return this data in the appropriate JSON format. My problem is just getting the spname values ​​from the nested array in the workers column and showing it in the datatables field view. My codes are as follows.

Api controller

JavaScript

Return API file is below

JavaScript

in view file ajax

JavaScript

When I call the workers column here, gives [object Object],[object Object] error. What I want is to show the spname values ​​in workers in the view file.

Best Regards

Advertisement

Answer

Because workers is actually an array of objects, you will get exactly that (the object names) if you use data: 'workers'.

Datatables has support for this situation, using its array bracket syntax. So, for example you can do this:

JavaScript

Using your data, this will print out ok, sdsf sdfsdf in the table cell. It iterates through all the spname items, and separates them with a comma followed by a space.

If you want something more elaborate, you may need to pre-process your JSON – for example, to flatten it. But the above may be sufficient for your needs.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement