rapyd-laravel
rapyd-laravel copied to clipboard
DataGrid buildCSV not respecting filter
If I have a datagrid which is filtered to a specific subset of records, then I call 'buildCSV' at the end of the method, then the CSV contains the unfiltered results.
I would expect it to produce just the unfiltered results?
$filter = \DataFilter::source(new Member);
$filter->add('membership_id', 'Membership ID', 'number');
$filter->add('firstName', 'First Name', 'text');
$filter->add('lastName', 'Last Name', 'text');
$filter->submit('search');
$filter->reset('reset');
$grid = \DataGrid::source($filter);
$grid->add('membership_id','Member ID', true)->cell( function( $value, $row) {return sprintf('<a href="%s">%s</a>', url('member/show', [$value]), $value);});
$grid->add('firstName', 'First Name', true);
$grid->add('lastName', 'Last Name', true);
// Returns all the records in the database
return $grid->buildCSV('export_articles', 'Y-m-d.His');
// Returns a paginated list of the filter
//$grid->paginate(20);
//return view('member.list', compact('filter', 'grid'));
You probably need to manually call the build
method:
// Returns all the records in the database
$grid->build();
return $grid->buildCSV('export_articles', 'Y-m-d.His');
Let me know if it works for you.
Hi @tacone, I'm afraid that didn't seem to make much difference - it still shows me the full data.
If I try ->build or ->buildCSV, I get a sub-class of \Illuminate\Database\Eloquent\Model
and if I try the "output' method, I get a sub-class of \Illuminate\Database\Eloquent\Builder
instead in Zofe\Rapyd\DataSet
's build method.
I don't know this code well enough to debug further though.
you've to do $filter->build()
on the filter before $grid->buildCSV()
on the grid
@zofe That works - but I find it odd that building it for a view would work but building it for a CSV requires extra steps? I still consider that to be an issue, personally.
if (some condition) {
return $grid->buildCSV('export_articles', 'Y-m-d.His');
}
return view ..
"some condition" can be .. a qs param or an uri node..
I think I similar issue. This method work for my case.
$url = new Zofe\Rapyd\Url(); $grid->link($url->append('export',1)->get(),"Export to Excel", "TR");
https://github.com/zofe/rapyd-laravel/issues/312