[英]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 ? 有人可以帮我吗?
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>'); }
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.