我有一个datatables,其中包含从数据库检索到的数据.当我在搜索文本框(搜索文本框由datatables生成)中输入一些关键字时,表的结果将发生变化.这很好.但当我单击export to 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

Laravel相关问答推荐

如何更改LIVE上的Filament占位符内容?

Laravel:在行的子集上同步多对多

Laravel 模型事件:delete() 不会从存储中删除文件

如何为 CMP 横幅安装谷歌同意脚本?

函数接受 Laravel 集合对象,尽管只允许使用字符串

如何通过单击进入 vs 代码中的类

找不到 Laravel 5 类日志(log)

在 laravel 4.2 中,用户 'root'@'localhost' 的 Laravel 访问被拒绝(使用密码:YES)

Laravel + Plupload 上传到 S3 响应以进行预检无效 - CORS

Laravel 4:如何将 WHERE 条件应用于 Eloquent 类的所有查询?

Laravel + SQLite = SQLSTATE[HY000]一般错误:8次try 写入只读数据库

Laravel中具有两个外键字段的数据库一对多

Laravel:如何在没有数据库的情况下对用户进行身份验证

SQLSTATE [HY000]:一般错误:1005 无法创建表 - Laravel 4

laravel 搜索多个以空格分隔的单词

我如何从给定的日期时间 struct 创建Carbon 对象?

Laravel League/flysystem 使用 AWS S3 获取文件 URL

Select,where JSON 包含数组

如何在 Laravel Mix 中将公共路径更改为包含下划线的内容?

如何在 Laravel 5 请求类中使用有时规则