[英]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.我有一个 HTML web 页面,其中有一个表 javascript 从 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() );
} );
} ); });
There are several ways to do this.有几种方法可以做到这一点。 One way is to put the <table>
inside a <form>
so that you can submit it.一种方法是将<table>
放在<form>
中,以便您可以提交它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.