0

我有一个列表,通过使用数据表插件,我对它们进行了清晰的排序。在此之前,我只通过 php 编码制作了排序列表。根据当前列表,我可以导出到 csv 文件。我的代码如下:

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');



  // create a file pointer connected to the output stream
    $output = fopen('php://output', 'w');

$rows = mysql_query(base64_decode($_REQUEST['qur']));
        $number = mysql_num_rows($rows);
        if($number > 0){

            fputcsv($output, array('Name','Username','Email','Age','Location','Contact','Privilege','JoiningDate','Status'));

            // loop over the rows, outputting them
            $blankArray = array();
            while ($row = mysql_fetch_assoc($rows)) {
                $name = $row['admin_name'];
                $username = $row['username'];
                $email = $row['email'];
                $age = $row['age'];
                $location = $row['location'];
                $cont = $row['contact_no'];
                $priv = get_role_name_by_id($row['role']);
                $doj = substr($row['creation_date'],0,10);
                $status = ($row['status'] == '1')?"enable":"disable";
                $blankArray['Name'] = $name;
                $blankArray['Username'] = $username;
                $blankArray['Email'] = $email;
                $blankArray['Age'] = $age;
                $blankArray['Location'] = $location;
                $blankArray['Contact'] = $cont;
                $blankArray['Privilege'] = $priv;
                $blankArray['JoiningDate'] = $doj;
                $blankArray['Status'] = $status;

                fputcsv($output, $blankArray);

            }
        }else{
            fputcsv($output, array('No Record Found'));
        }

从我使用以下代码的页面开始:

<a href="export.php?report=user&qur=<?php echo base64_encode($search_sql); ?>"><button>Export to CSV</button></a>

现在,当我更改数据表插件中的排序选项时,我使用以下代码:

$('#example').dataTable( {
                                "bProcessing": true,
                                "bServerSide": true,
                                "sAjaxSource": "datatabledb.php",
                                "bJQueryUI": true,
                                "sPaginationType": "full_numbers",
                                //"sDom": 'T<"clear">lfrtip',
                                "oTableTools": {
                                    "aButtons": [
                                        {
                                            "sExtends": "copy",
                                            "sButtonText": "Copy to clipboard"
                                        },
                                        {
                                            "sExtends": "csv",
                                            "sButtonText": "Save to CSV"
                                        },
                                        {
                                            "sExtends": "xls",
                                            "sButtonText": "Save for Excel"
                                        }
                                    ]
                                }                       
                            } );

但它仍然没有显示按钮。请帮我。

4

1 回答 1

0

您可以使用 TableTools 来满足您的需求。

看到这个链接!例如,请参阅此链接以获取文档!

于 2012-05-16T13:38:33.313 回答