Default Value in Editor
Default Value in Editor
davidjmorin
Posts: 101Questions: 31Answers: 0
I need to have the ID from table 1 as a default value for the editor field that will save into table 2. This is what I have but it is not working.
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor({
ajax: 'php/table.query.php',
table: '#sku_request',
fields: [{
label: "Note:",
name: "dpe_notes.note"
},
{
label: "Your Name:",
name: "dpe_notes.user"
},
{
label: "Note ID:",
name: "dpe_notes.note_id",
def: function (data, type, full, meta, row) { return data.ID; }
},
]
});
The Note ID is what I need as the default from the table. The note ID is the ID from table 1.
My full script
(function($) {
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor({
ajax: 'php/table.sku_request.php',
table: '#sku_request',
fields: [{
label: "Note:",
name: "dpe_notes.note"
},
{
label: "Your Name:",
name: "dpe_notes.user"
},
{
label: "Note ID:",
name: "dpe_notes.note_id",
def: function (data, type, full, meta, row) { return full.dp_expected.note_id; }
},
]
});
$(document).ready( function () {
var table = $('#sku_request').DataTable({
ajax: 'php/table.sku_request.php',
dom: 'Bfrtip',
select: true,
pageLength: 10,
lengthChange: true,
scrollX: true,
language: {
searchPanes: {
clearMessage: 'Clear All',
collapse: 'Filter',
cascadePanes: true,
viewTotal: true,
layout: 'columns-2',
dataLength: true
}
},
buttons: [
{
extend: "remove",
text: "Delete",
editor: editor
},
{
extend: "excelHtml5",
text: "Excel"
},
{
extend: "edit",
text: "Update",
editor: editor
},
],
columns: [
{
data: "dp_expected.ID"
},
{
data: "dp_expected.Invoice_"
},
{
data: "dp_expected.District"
},
{
data: "dp_expected.Sold_By"
},
{
data: null,
render: function ( data, type, full, meta, row ) {
// Combine the first and last names into a single table field
if(full.dpe_notes.note >= 0){
return 'No Notes';
}else {
return full.dpe_notes.note+' - '+full.dpe_notes.user;
}
} },
],
});
} );
});
}(jQuery));
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The
def
function doesn’t have any arguments, so I would expect the above to throw an error about an undefined variable.Have a look at how I used a default value in this blog post which it sounds like you are doing something similar to?
Allan
@allan thank you for that link. I believe this will help me. So I could just use the following in the def: ?
Yeah so tested and confirm this does not work.
Im lost here. Any guidance is appreciated.
Can you give me a link to your page so I can help to debug it?
The first question is going to be - does it go into the
if
condition you have above? i.e. doesselected
contain any rows or not? If not, then istable
pointing at the parent table? If it does, then isid
a valid property in your data structure? Assigningid
tod.site
I would say is unusual - you could just usereturn selected.data().id;
.Allan