php - 基于数据表 Laravel 4 导出 CSV 或 PDF

标签 php jquery laravel csv datatables

我有一个数据表,其中包含从数据库中检索到的数据。当我在搜索文本框中输入一些关键字时(搜索文本框是由数据表生成的),表格的结果会发生变化。这很好。但是,当我单击导出到 csv 或 pdf 时,将从数据库而不是数据表中检索 csv 或 pdf 格式的结果。

如何使用laravel导出基于datatables插件的csv/pdf?

//数据表插件

<link href="plugins/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<script src="plugins/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js" type="text/javascript"></script>

//PHP

public function sales_csv(){    

    // columns      
    $arrSelectFields = array(
        -- columns --
    );

    // query
    -- sql queries --

    // passing the columns which I want from the result set. Useful when we have not selected required fields
    $arrColumns = $arrSelectFields;

    // define the first row which will come as the first row in the csv
    $arrFirstRow = $arrSelectFields;

    // building the options array
    $options = array(
        'columns' => $arrColumns,
        'firstRow' => $arrFirstRow,
    );
    // creating the Files object from the Utility package.
    $Files = new Files;
    return $Files->convertToReportsSalesCSV($query, $options);
}

最佳答案

我可能会将关键字发布到我的服务器并再次运行 sql 查询来过滤这些结果,然后创建 csv/pdf

关于php - 基于数据表 Laravel 4 导出 CSV 或 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32173798/

相关文章:

jQuery 可拖动选项元素

Javascript 也更新了页面

php - 为什么 HTTP 请求在 Chrome 中卡在待定状态?

javascript - 正则表达式匹配聊天室字符串中的非法字符

javascript - 如何滚动到先前隐藏但在标签单击时可见的 div

php - 获取 Laravel 中未设置为外键的行的数据

laravel - 我想在 Docker 容器中发布 Laravel 应用程序,我应该在 Docker 中使用 Docker 还是使用 docker-compose 来添加所有服务?

laravel - isset 或空 Laravel 中的偏移类型非法

javascript - 如何在ajax中发送额外的表单数据

php - PSR2 代码风格和 PHP Code Sniffer 不一致?