Closed Maykonn closed 9 years ago
since it works with multidimensional arrays, it is possible to bind something like:
DataGrid::source((array)json_decode(file_get_contents('http://myapi.com/users')))
untested
Ok, thanks!
i think you can do:
DataGrid::source(json_decode(file_get_contents('http://myapi.com/users'),true))
Yes, it works fine. I write wrappers for my external API, that make requests using Guzzle:
\DataGrid::source(\External::call('/search/pagination/10,0/sort/desc?q=my-search&filters=status:!inactive|user_id:10', \Request::GET)
->getResponseBodyAsArray());
Now I will implement pagination, sort, etc. Thanks @zofe!
@zofe When I try to add a column from multidimensional array:
$grid->add('title','Title', true);
$grid->add('category.name','Category', true);
The title column is ok, but the category.name is write as 'category.name' instead the product category name.
the dot syntax is translated as "relation.fieldname", you should find an alternative:
maybe {{ $row['category.name'] }}
?
Sorry, but I don't understand:
maybe {{ $row['category.name'] }} ?
I'm try to make it, but not work, I think that I don't understand =):
$grid->add("{{$row['category.name']}}",'Category', true);
try to change the problematic key in your resultset: something like:
$rows = json_decode(file_get_contents('http://myapi.com/users'),true);
$rows = array_map(function($row) {
$cleanrow = $row;
$cleanrow['category_name'] = $row['category.name'] ;
return $cleanrow;
}, $rows);
then you can use $grid->add("category_name",'Category', true);
I will write a layer to translate the API incompatible responses to app core(a wrapper for my \External call responses, something like a Context Map from DDD). Thanks!
Is possible set datasource from an array stdclass object or a RESTful API call: