如何从数据表按钮保存信息

时间:2015-04-16 12:51:08

标签: javascript php ajax codeigniter

我正在使用数据表来显示我的数据库信息。我希望在用户从表中保存excel或csv或pdf时保存用户信息。我编写了一个保存用户信息的功能。单击按钮时如何保存它们。如何解决这个问题? TIA

功能:

 public  function save_export(){
    $data = array(
    $sdob=date('Y-m-d'),
    'export_date'=>$sdob,
    $modifiedby = $this->session->userdata('user_name'),
    'user_name' => $modifiedby,
    'export_tb_name'=>$this->input->post('')

    );

   $this->db->insert('mytable', $data); 
    }

datatable js:

<script>
    var oTable;
    $(document).ready(function () {
        $(".pull-right").on('click', '.glyphicon-chevron-up, .glyphicon-chevron-down', function () {
            $(this).toggleClass("glyphicon-chevron-down glyphicon-chevron-up");
        });
        $.datepicker.regional[""].dateFormat = 'yy-mm-dd';
        $.datepicker.regional[""].changeMonth = true;
        $.datepicker.regional[""].changeYear = true;
        $.datepicker.setDefaults($.datepicker.regional['']);
        oTable = $('#player_table').dataTable({
        "bProcessing": true,
                "bServerSide": true,
                 "stateSave": true,
                "stateSave": true,
                "sServerMethod": "GET",
                "sAjaxSource": site_url + "backend/players/ajaxData",
                "iDisplayLength": 10,
                "aLengthMenu": [[10, 25, 50, - 1], [10, 25, 50, "All"]],
                "aaSorting": [[0, 'desc']],
                "sPaginationType": "full_numbers",
                "dom": 'T<"clear">lfrtip',
                tableTools: {
                "sRowSelect": "multi",
        "sSwfPath": site_url + "js/swf/copy_csv_xls_pdf.swf",
               "aButtons": [
                   "select_all", "select_none",
                   "copy",
                   "csv",
                   "xls",
                   {
                       "sExtends": "pdf",
                       "sTitle": "Report Name",
                       "sPdfMessage": "Summary Info",
                       "sPdfOrientation": "landscape",
                       "fnClick": function (nButton, oConfig, flash) {
                           customName = 'Playerlist' + ".pdf";
                           flash.setFileName(customName);
                           this.fnSetText(flash,
                                   "title:" + 'Hurrycane' + "\n" +
                                   "message:" + 'Player List' + "\n" +
                                   "colWidth:" + this.fnCalcColRatios(oConfig) + "\n" +
                                   "orientation:" + oConfig.sPdfOrientation + "\n" +
                                   "size:" + oConfig.sPdfSize + "\n" +
                                   "--/TableToolsOpts--\n" +
                                   this.fnGetTableData(oConfig)
                                   );
                       }
                   },
                   "print"
               ],        
        },
                "aoColumns": [
                {"bVisible": true, "bSearchable": true, "bSortable": true},
                {"bVisible": true, "bSearchable": true, "bSortable": true},
                {"bVisible": true, "bSearchable": false, "bSortable": false}]
    });
    oTable.columnFilter({
        sRangeSeparator: "&%&",
        sPlaceHolder: "head:before",
            aoColumns: [
                {type: "text"},
                {type: "text"},

                null
            ]
        });    
</script>

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:-1)

使用此代码,您无法将数据保存为CSV或Excel文件,但可以保存为PDF文件。

CodeIgniter提供了一个库,它将HTML代码转换为.pdf文件。

首先使用表格在HTML页面中显示所有数据,然后将其转换为PDF文件。

$this->load->library('cezpdf');

http://www.code2learn.com/2012/03/generating-tabulated-pdf-file-from.html

http://www.tutorialized.com/tutorial/Generate-PDF-Files-from-Database-using-CodeIgniter/74395