自定义导出
<h1>自定义导出</h1>
<p>dcat-admin的数据表格默认支持导出csv文件,</p>
<pre><code class="language-php">&lt;?php
namespace App\Admin\Extensions;
use Dcat\Admin\Grid\Exporters\AbstractExporter;
class CustomExporter extends AbstractExporter
{
public function export()
{
$filename = $this-&gt;getTable().'.csv';
$data = $this-&gt;getData();
$output = '';
$headers = [
'Content-Encoding' =&gt; 'UTF-8',
'Content-Type' =&gt; 'text/csv;charset=UTF-8',
'Content-Disposition' =&gt; &quot;attachment; filename=\&quot;$filename\&quot;&quot;,
];
response(rtrim($output, &quot;\n&quot;), 200, $headers)-&gt;send();
exit;
}
}</code></pre>