How do i make a datatables editor view show the lookup labels instead of values
How do i make a datatables editor view show the lookup labels instead of values
defdog
Posts: 8Questions: 3Answers: 0
for example
var editor = new $.fn.dataTable.Editor( {
ajax: 'js/DataTablesEditor/php/table.trailer.php',
table: '#trailer',
fields: [
{
"label": "ID",
"name": "id_trailer",
"type": "readonly"
},
{
"label": "Trailer #",
"name": "number"
},
{
"label": "Type",
"name": "type",
"type": "select",
"options": [
{ label: 'van', value: 'van' },
{ label: 'reefer', value: 'reefer' },
{ label: 'flatbed', value: 'flatbed' },
{ label: 'container', value: 'container' },
{ label: 'rail', value: 'rail' }
// etc
]
},
{
"label": "Length",
"name": "size"
},
{
"label": "Carrier",
"name": "id_carrier"
},
{
"label": "Status",
"name": "id_trailer_status"
},
]
} );
var table = $('#trailer').DataTable( {
dom: 'Bfrtip',
ajax: 'js/DataTablesEditor/php/table.trailer.php',
columnDefs: [
{ targets: [ 0 ], visible:false },
{ targets: [ 5, 8 ], render:function ( data, type, row, meta ) {
return ((data=='1')?'<img src="img/greencheck.png" width="15" alt="1" />':'<img src="img/redx.png" width="15" alt="0" />');
} },
{ targets: [ 2,4,6,7 ], render:function ( data, type, row, meta ) {
console.log(data,type,row,meta);
if (false == true) alldd.ddval({name: 'carrier',type:'val',ref:$(this),arg:data});
return (data);
} },
],
columns: [
{ "data": "id_trailer" },
{ "data": "number" },
{ "data": "type" },
{ "data": "size" },
{ "data": "id_carrier" },
{ "data": "id_trailer_status" },
{ "data": "trailer_owned" },
{ "data": "id_condition" },
{ "data": "in_yard_status" },
],
select: true,
lengthChange: false,
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
} );
How do i show the label for type (column 3) and the label for id_carrier (5) . Also how do i get the values for the editor for a select box (they are in separate tables)?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi,
You need to use a
leftJoin
in the server-side script. Have a read through the documentation for this and let me know if you have any questions about it.Allan
That was super helpful - i have it displaying the values - what I want now is to be able to do inline edit. Edit will use a select.
php code is:
This example shows how you can do an inline edit with a joined table and a select input.
The key is to use
columns.editField
to tell Editor which field it should edit for the given column.Allan
Thanks! I got it working!