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

hah*_*aha 15 php csv jquery datatables laravel

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

// 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);
}
Run Code Online (Sandbox Code Playgroud)

Mor*_*Dew 7

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