I have a node.js program that I am working on but have not been able to get my dropdown column to work properly. I query a sql server database and populate the datatable. The last column is my "Format" column with a dropdown list where the user can select a format number (1-10). I need to be able to save whatever format selection is made and update the database after. I haven't been able to even get the correct selection to console.log.
//Here is where I have tried to console.log the selection after a selection is made.
//I only get whatever value is selected in the first row, not the row that was actually changed.
$('#Slapper').on('change', function(){
var value = $('#Slapper option:selected').val();
console.log(value);
});
//Here is where I create the datatable. The dropdown list looks fine visually but doesn't function at all:
function createBarcode(data){
mainTable = $('#Slapper').dataTable({
data: data,
columns: [
{title: "Barcode ID",
data: "barcodeID",
orderable: true,
visible: false},
{title: "Print",
data: "printYesNo",
render: function ( data, type, row ) {
if ( type === 'display' ) {
printArray[row.barcodeID] = row.printYesNo;
// console.log(printArray);
return '<input type="checkbox" class="editor-print" id='+ row.barcodeID+' >';
}
return data;
},
orderable: true,
visible: true},
{title: "Code",
data: "codeText",
orderable: true},
{title: "Commodity",
data: "Commodity",
orderable: true},
{title: "Variety",
data: "Variety",
orderable: true},
{title: "Grade",
data: "Grade",
orderable: true},
{title: "Style",
data: "Pack",
orderable: true},
{title: "Size",
data: "Size",
orderable: true},
{title: "Is Active",
data: "active",
orderable: true,
visible: false},
{title: "Label",
data: "Label",
orderable: true,
visible: true},
{title: "PLU",
data: "Lot",
orderable: true,
visible: true},
{
title: "Format",
data: "Format",
render: function(d,t,r){
var $select = $('<select id=' + r.barcodeID + '></select>', {
'id': r +'start',
'value': d,
});
$.each(formats, function(k,v){
var $option = $('<option></option>', {
'text': v,
'value': v
});
if(d === v){
formatArray[r.barcodeID] = r.Format;
$option.attr('selected', 'selected')
}
$select.append($option);
});
return $select.prop('outerHTML');
}
},
],