简体   繁体   English

如何使用数据表上传csv文件并将其存储到服务器中的文件夹?

[英]How to upload csv file and store it to folder in my server using datatable?

I have table and make the datatable on it, I added download csv file on it and it's working. 我有表,并使其上的数据表,我添加了下载的csv文件,它正在工作。 Now, I need to upload the same file or store it in some folder path. 现在,我需要上传相同的文件或将其存储在某个文件夹路径中。

This is my code for datatable 这是我的数据表代码

$('#account_details').DataTable({
    dom: 'lBfrtip',
    lengthMenu: [
        [ 10, 25, 50, 100, 250, 500 -1 ],
        [ '10', '25', '50', '100', '250', '500' ]
    ],
    pageLength: 10,
    buttons: [
        { 
            extend: 'excelHtml5',
            text:'', 
            className: 'excelbtn',
            filename: 'Account_details', 
            title: 'Account Details', 
            titleAttr: 'Excel', 
            exportOptions: { columns: [ 0, 1, 2, 3, 4 ] }
        }, { 
            extend: 'pdfHtml5', 
            text:'',
            className: 'pdfbtn',
            filename: 'Account_details', 
            title: 'Account Details', 
            titleAttr: 'PDF', 
            exportOptions: { columns: [ 0, 1, 2, 3, 4 ] }
        }, { 
            extend: 'print',
            text:'',
            className: 'print',
            filename: 'Account_details', 
            title: 'Account Details', 
            titleAttr: 'Print', 
            exportOptions: { columns: [ 0, 1, 2, 3, 4 ] }
        }, { 
            extend: 'csv', 
            text:'',
            className: 'csv',
            filename: 'Account_details', 
            title: 'Account Details', 
            titleAttr: 'Reports', 
            exportOptions: { columns: [ 0, 1, 2, 3, 4 ] }
        }
    ],
    responsive: true,
    colReorder: true,
    stateSave:  true,
    stateSaveCallback: function(settings, data) {
        console.log(data);
        update_customize_table_settings('account_details','accounts');
    }
});

My problem is: Need to search for some records from frontend using datatable and store the result in another table in the db . 我的问题是:需要使用datatable从前端搜索一些记录,并将结果存储在db中的另一个表中。 i stored the results on csv file and downloaded it . 我将结果存储在csv文件中并下载了。 i just to extract data from that file and store it in the another table in db and display it . 我只是从该文件中提取数据并将其存储在db的另一个表中并显示它。

Please can anyone help me ? 有人可以帮我吗?

  1. Add a button which user will click on after searching. 添加一个按钮,用户将在搜索后单击该按钮。

      initComplete: function () { $("div.toolbar").html( '<a href="#" class="btn btn-info btn-secondary" style="margin: 5px" id="insertbtn" onclick="InsertRows()">Insert</a>'); } 
  2. InsertRows function InsertRows函数

      function InsertRows() { var table = $("#dtexample").DataTable(); var data = table.rows().data(); data.each(function (value, index) { console.log(`For index ${index}, data value is ${value}`); console.dir(value); //call AJAX below to insert each row to table }); } 

    This will make n number of insert AJAX requests which is fine if you're inserting small number of rows. 这将产生n个插入的AJAX请求,如果您要插入少量的行,则很好。 But if the searched number of rows are greater, then I would advice to add the data to an array and POST array to Webservice to insert it into table. 但是,如果搜索的行数更多,那么我建议将数据添加到数组中,并将POST数组添加到Webservice中,以将其插入表中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在nodeJs中使用cli上传文件夹中的文件 - how to upload file in folder using cli in nodeJs 使用javascript和django将文本文件上传到服务器中的某个文件夹 - using javascript and django to upload a text file to some folder in server 使用jquery文件上传将图像上传到cloudinary和我自己的服务器 - Upload image to cloudinary and to my own server using jquery file upload 任何使用JavaScript将文件上传到我的Google Drive公用文件夹的人 - Anyone to upload a file to my Google Drive public folder using JavaScript 如何在服务器中动态指定jsp文件上传存储文件夹路径 - how to specify jsp file upload storage folder path dynamically in server 如何在 angular 中上传 csv 文件 13 错误:“my-app” - How to upload csv file in angular 13 Error:"my-app" 如何使用文件流在服务器文件夹中存储两个或多个图像 - How to store two or more images in server folder with file stream 如何使用 Nodejs 将文件夹中的数据作为文件名写入 CSV 文件 - How to write a data as file names in a folder to CSV file using Nodejs 将CSV角文件上传到范围中而不发布到服务器 - Angular upload csv file into scope not post to server 如何使用ExtJS客户端上传和处理CSV文件 - How to upload and process CSV File using ExtJS Client Side
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM