javascript - Get user input in table to send to database
问题描述
I apologize if this is confusing, I am very new to coding.
I have an HTML web page with a table in javascript that pulls from a database in postgre. Right now, you can view the table and click on individual cells, but I want users to be able to overwrite any cell in the last column and for their input to be added to the database that the original table was pulled from.
Does anybody know how to do this?
Thank you! :)
var endpoint = '/reports/lead_time/endpoint' $(document).ready(function() {
$('#lead_time thead tr').clone(true).appendTo( '#lead_time thead' );
$('#lead_time thead tr:eq(1) th').each( function (i) {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="'+title+'" />' );
$( 'input', this ).on( 'keyup change', function () {
if ( table.column(i).search() !== this.value ) {
table.column(i).search( this.value ).draw();
}
} );
} );
var table = $('#lead_time').DataTable( {
orderCellsTop: true,
scrollY: "700px",
scrollX: true,
pageLength: 50,
order: [[ 1, "asc" ]],
processing: true,
serverSide: true,
search: "Quick Search...",
dom: 'Blfrtip',
keys: true,
deferRender: true,
scroller: true,
infoFiltered: "(Filtered from _MAX_ total entries)",
searching: true,
language: {
processing: "Processing...",
search:"Quick Search:",
},
ajax: {
"method":"GET",
"url": endpoint,
"serverSide": true,
},
buttons: [
'columnsToggle'
],
columns: [
{ data: 'part_no'},
{ data: "supplierid" },
{ data: "item_minimum" },
{ data: "item_q1" },
{ data: "item_median" },
{ data: "item_q3" },
{ data: "vendor_minimum" },
{ data: "vendor_q1" },
{ data: "vendor_median" },
{ data: "vendor_q3" },
{ data: "lead_time" },
{ data: "lt_type" },
{ data: "lt_override" },
],
} );
$('a.toggle-vis').on( 'click', function (e) {
e.preventDefault();
// Get the column API object
var column = table.column( $(this).attr('data-column') );
// Toggle the visibility
column.visible( ! column.visible());
} );
$('#lead_time tbody').on( 'click', 'td', function () {
console.log( table.cell( this ).data() );
} );
} );
解决方案
有几种方法可以做到这一点。一种方法是放在<table>
里面 a<form>
以便您可以提交它。
推荐阅读
- swift - Swift 代码问题!=
- python - 仅将文本附加到非空值 pandas Dataframe
- ssms - 从 SSMS 处理 Azure 分析服务器模型时出错
- python - nltk : 根据 POS 用其他词替换标记
- vim - Vim 拆分函数参数
- php - PHP 的 MySQL 数据库迁移 UTF-8 问题
- tensorflow - 是否可以训练 Tensorflow 来检测物体上的缺陷?
- c# - 如何使用 Selenium c# 将剪贴板中的 url 粘贴到 Chrome 中的地址栏?
- javascript - 反应最佳实践:将状态传递给孩子还是让孩子直接检查状态?
- laravel - 在 IIS 服务器中使用 htaccess 更改主 URL