I'm using the Datatables Editor with a field select for two tables with the data of the examples. I've built a seletc field with the name of the city. Cities are in a different table from the one with staff names, In the staff table I have a field which is id_ciudad (the id of the city in the cities table).
The trouble is that I can't get the right city seleceted. It aways appears selected Edimburgh, even if that is not the city o the member of the staff I'm editing. The Editor object has been created in the following way:
var objetoEditor = new $.fn.dataTable.Editor({
ajax: 'crud_editor_04.php',
table: '#tabla_de_personal',
idSrc: 'id',
i18n: {
create: {
button: "Nuevo",
title: "Crear nuevo registro",
submit: "Grabar"
},
edit: {
button: "Editar",
title: "Editar registro",
submit: "Actualizar"
},
remove: {
button: "Borrar",
title: "Borrar registro",
submit: "Borrar",
confirm: {
_: "¿Estás seguro de eliminar estos %d registros?",
1: "¿Estás seguro de eliminar este registro?"
}
},
multi: {
title: "Múltiples valores",
info: "Los registros seleccionados contienen diversos valores para este campo. Para editar este campo con el mismo valor en los registros seleccionados, pulsa aquí. En caso conterario, los registros mantendrán sus valores individuales en este campo.",
restore: "Restaurar los valores múltiples",
noMulti: "Esta entrada puede ser modificada individualmente, pero no como parte de un grupo."
},
datetime: {
previous: 'Anterior',
next: 'Siguiente',
months: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
weekdays: ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb']
}
},
fields: [
{label: 'Nombre:', name: 'personal.nombre', attr: {class:'form-control'}},
{label: 'Apellido:', name: 'personal.apellido', attr: {class:'form-control'}},
{label: 'Cargo:', name: 'personal.cargo', attr: {class:'form-control'}},
``` {```
``` label: 'Ciudad:', ```
``` name: 'personal.id_ciudad',```
``` attr: {class:'form-control'}, ```
``` type: "select", ```
``` options: [```
``` {label:'Edinburgh', value:'1'},```
``` {label:'London', value:'2'},```
``` {label:'New York', value:'3'},```
``` {label:'San Francisco', value:'4'},```
``` {label:'Sidney', value:'5'},```
``` {label:'Singapore', value:'6'},```
``` {label:'Tokyo', value:'7'}```
``` ]```
``` },```
{
label: 'F. Ingreso:',
name: 'personal.fecha_de_ingreso',
type: 'date',
def: function(){return new Date();},
dateFormat: 'dd-mm-yy',
attr: {readonly:true, class:'form-control', style:'display:inline'},
opts:{
buttonImage:'editor/images/calendar.png',
buttonImageOnly: true,
buttonText: 'Elegir fecha',
dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sá'],
dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'],
firstDay: 1,
monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
changeMonth: true,
changeYear: true,
prevText: "Anterior",
nextText: "Siguiente"
}
},
{
label: 'Salario anual:',
name: 'personal.salario_bruto_anual',
attr: {class:'form-control'},
fieldInfo: 'El salario debe ir como valor numérico, con dos decimales (incluso si son 00), separados por un punto.'
},
]
});
How can I mark an option of the select field as selected? I've tried def: 'personal.id_ciudad', def:'ciudades.id' and def:'ciudades.id' but nothing works. No preselected option in my select.
I've bought a single developer License today, for the case it is a trial limitation, but it does not work all the same.
Can someone help me?
Thanks a lot everyone.
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.