Editor - What if I don't want you to determine the field from the source
Editor - What if I don't want you to determine the field from the source
supportNE
Posts: 23Questions: 7Answers: 0
In editor, when I try to add buttons to a column of each row, using defaultContent, I get the error " Unable to automatically determine field from source. Please specify the field name.". The thing is, I don't want there to be a field name attached to this column, I just want a couple of buttons, which will eventually link into laravel routes, but don't yet.
Very patient, kind and understanding people might want to see my JS, so here it is.
$(document).ready(function() {
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
var editor = new $.fn.dataTable.Editor( {
ajax: '/editor-php/controllers/quotes.php',
table: '#example',
fields: [
{ label: 'Name', name: 'quote.client_name'},
{ label: 'Email', name: 'quote.email'},
{ label: 'Phone', name: 'quote.telephone'},
{ label: 'Source', name: 'quote.source', type: 'select'},
{ label: 'Date Received', name: 'quote.date_received', type: 'datetime', def: new Date().toJSON().slice(0,10).replace(/-/g,'-')},
{ label: 'Follow Up Date', name: 'quote.follow_up_date', type: 'datetime', def: tomorrow.toJSON().slice(0,10).replace(/-/g,'-')},
{ label: 'Case Type', name: 'quote.case_file_type', type: 'select', def: '2'},
{ label: 'Quote Fees', name: 'quote.quote_fees'},
{ label: 'Quote Dbs', name: 'quote.quote_dbs'},
{ label: 'Notes', name: 'quote.notes'},
{ label: 'Status', name: 'quote.status'},
]
} );
// Activate an inline edit on click of a table cell
$('#example').on('click', 'tbody td:not(:first-child)', function (e) {
editor.inline(this);
});
$('#example').DataTable({
dom: "Bfrtip",
ajax: "/editor-php/controllers/quotes.php",
order: [[7, 'desc']],
columns: [
{
data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false
},
{data: "quote.client_name"},
{data: "quote.email"},
{data: "quote.telephone"},
{data: "quote.quote_fees", render: $.fn.dataTable.render.number(',', '.', 0, '£')},
{data: "quote.quote_dbs", render: $.fn.dataTable.render.number(',', '.', 0, '£')},
{data: "quote.date_received"},
{data: "quote.follow_up_date"},
{data: "source.name", editField: "quote.source" },
{data: "case_file_type.name", editField: "quote.case_file_type"},
{data: "quote.notes"},
{
data: null,
defaultContent: '<input type="button" class="convert" value="Converted"/><input type="button" class="notConvert" value="Not Converted">',
}
],
select: {
style: 'os',
selector: 'td:first-child'
},
buttons: [
{extend: "create", editor: editor},
{extend: "edit", editor: editor},
{extend: "remove", editor: editor}
]
});
});
$('#example tbody').on('click', '.convert', function () {
var id = $(this).attr("id").match(/\d+/)[0];
console.log(id);
var data = $('#example').DataTable().row( id ).data();
console.log(data[0]);
});
Thanks for any feedback.
This discussion has been closed.
Answers
Hmm - this post is being shown as answered, but no answer has been given.
I think I may have answered this myself. This appears to work anyway.
Glad you figured it out. But please don't duplicate your posts as I provided an answer in your other thread.
Kevin
Sorry about that Kevin - will try to be a better user.