TypeError: kisditor.field
TypeError: kisditor.field
i tried to follow that example: https://datatables.net/blog/2016-03-25, but i got an error (TypeError: kisditor.field)at this part of code:
carsTable.on('select', function() {
kistable.ajax.reload();
kisditor
.field( 'pOrder.fCar' )
.def( carsTable.row( { selected: true } ).data().id );
});
this is the code:
/*
* Editor client script for DB table tblaCars
* Created by http://editor.datatables.net/generator
*/
(function($) {
$.fn.dataTable.ext.errMode = 'throw';
$(document).ready(function() {
var carsEditor = new $.fn.dataTable.Editor({
ajax: 'php/table.tblaCars.php',
table: '#tblaCars',
fields: [{
"label": "id:",
"name": "id"
},
{
"label": "Αυτοκίνητο:",
"name": "pCar"
},
{
"label": "Ιδιοκτήτης:",
"name": "pName"
},
{
"label": "Τηλέφωνο:",
"name": "pPhone"
},
{
"label": "Email:",
"name": "pEmail"
},
{
"label": "Φύλλο:",
"name": "pMan",
"type": "select",
"options": [
"\u0386\u03bd\u03b4\u03c1\u03b1\u03c2",
"\u0393\u03c5\u03bd\u03b1\u03af\u03ba\u03b1"
]
}
]
});
//φίλτρο υποσέλιδου
$('#tblaCars tfoot th').each(function() {
var title = $(this).text();
$(this).html('<input type="text" placeholder="Αναζήτηση ' + title + '" />');
});
//
var carsTable = $('#tblaCars').DataTable({
ajax: 'php/table.tblaCars.php',
columns: [{
"data": "id"
},
{
"data": "pCar"
},
{
"data": "pName"
},
{
"data": "pPhone"
},
{
"data": "pEmail"
},
{
"data": "pMan"
}
],
select: true,
lengthChange: true,
buttons: [
//{ extend: 'create', editor: editor },
{
extend: 'edit',
editor: carsEditor
},
{
extend: 'remove',
editor: carsEditor,
formMessage: function(e, dt) {
var rows = dt.rows(e.modifier()).data().pluck('pcar');
return 'Θέλετε σίγουρα να διαγράψετε την εγγραφή(ες) ' +
'με στοιχεία? <ul><li>' + rows.join('</li><li>') + '</li></ul>';
}
}
]
});
carsTable.columns().every(function() {
var that = this;
$('input', this.footer()).on('keyup change', function() {
if (that.search() !== this.value) {
that
.search(this.value)
.draw();
}
});
});
//
var kisditor = new $.fn.dataTable.Editor({
ajax: {
url: 'php/table.OrderFromCar.php',
data: function(d) {
var selected = carsTable.row({
selected: true
});
if (selected.any()) {
d.Car = selected.data().id;
}
}
},
table: '#fKiniseis',
fields: [{
"label": "id:",
"name": "pOrder.id"
},
{
"label": "fCar:",
"name": "pOrder.fcar"
},
{
"label": "pDate:",
"name": "pOrder.pdate",
"type": "datetime",
"format": "DD\/MM\/YY"
},
{
"label": "pValue:",
"name": "pOrder.pValue"
}
]
});
//
var kistable = $('#fKiniseis').DataTable( {
ajax: {
url: 'php/table.OrderFromCar.php',
type: 'post',
data: function(d) {
var selected = carsTable.row({
selected: true
});
if (selected.any()) {
d.Car = selected.data().Id;
}
}
},
columns: [
{
"data": "pOrder.id"
},
{
"data": "pOrder.fCar"
},
{
"data": "pOrder.pdate"
},
{
"data": "pOrder.pValue"
}
],
select: true,
lengthChange: true,
buttons: [
//{ extend: 'create', editor: editor },
],
language: {
processing: "Traitement en cours...",
search: "Αναζήτηση :",
lengthMenu: "Εμφάνιση _MENU_ εγγραφών",
info: "Εμφάνιση _START_ Από _END_ από σύνολο _TOTAL_ εγγραφών",
infoEmpty: "Εμφάνιση 0 Από 0 από σύνολο 0 εγγραφών",
infoFiltered: "(Ευρεθείσες εγγραφές από _MAX_ συνολικά)",
infoPostFix: "",
loadingRecords: "Φόρτωση Δεδομένων...",
zeroRecords: "Δεν υπάρχουν εγγραφές!",
emptyTable: "Δεν υπάρχουν εγγραφές σε αυτόν τον πίνακα!",
paginate: {
first: "Πρώτη",
previous: "Προηγούμενη",
next: "Επόμενη",
last: "Τελευταία"
},
aria: {
sortAscending: ": activer pour trier la colonne par ordre croissant",
sortDescending: ": activer pour trier la colonne par ordre décroissant"
}
},
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
total = api
.column( 3)
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Total over this page
pageTotal = api
.column( 3, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
var num = $.fn.dataTable.render.number(',', '.', 0, '').display(pageTotal);
var numT = $.fn.dataTable.render.number(',', '.', 0, '').display(total);
$( api.column( 2 ).footer() ).html(
' ( Γενικό Σύνολο '+ numT +' )'
);
$( api.column( 1 ).footer() ).html(
'Σύνολο Σελίδας: '+num + ' '
);
}
} );
//
//πρόσθετος κώδικας modal
//
carsTable.on('select', function() {
kistable.ajax.reload();
kisditor
.field( 'pOrder.fCar' )
.def( carsTable.row( { selected: true } ).data().id );
});
//
carsTable.on('deselect', function() {
kistable.ajax.reload();
});
});
}(jQuery));
any idea about the mistake that is causing the error?
Thanks for help
This discussion has been closed.
Replies
In the event handler the field is called
pOrder.fCar. But in the Editor setup it is calledpOrder.fcar. Note the difference in case forCar.The field names are case sensitive.
Allan
i corrected the code as this. (i followed your advise about case sensitive)
and my php code is this:
but some how the js file isn't sending the "Car" variable to post
It's ok now i found the problem.
thanks