Replies: 1 comment
-
@WebVPF sorry for the delay in responding. I believe the data table widget needs to work with arrayed data - it won't work with database collections, which is why it can count the number of items but otherwise cannot populate the data. You could perhaps try creating an accessor in the model which can return the array of items and set the datatable field to the accessor. Not sure if it'll work, but you could give it a try: // In model
protected $purgeable = [
'itemArray',
];
protected function itemArray(): Attribute
{
return Attribute::make(
get: function ($value) {
return $this->items()->toArray();
},
set: function ($value) {
// Set the relation items here
return null;
}
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to use a Datatable field through relations?
I have two models: Category and Item.
In the category model, I have a relation with Item
plugins\webvpf\plugname\models\Category.php
In field definition I have specified
datatable
field foritems
plugins\webvpf\plugname\models\category\fields.yaml
The table correctly sees the number of Items, but it does not see the data
Please tell me how to do it right?
Beta Was this translation helpful? Give feedback.
All reactions