Column rendering does not work properly
Column rendering does not work properly

I am using Datatables Editor to mange library books. The books have an inventory number .
For the inventory number I created two columns in the database, for the first and second integer, Inv and SubInv. I would like to show them in one column in Datatables.
var table = $('#books').DataTable( {
"order": [[ 1, "desc" ]],
dom: 'Bfrtip',
ajax: "php/php_books.php",
columns: [
{
data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false
},
{ data :"Inv"},
{ data :"InvSub"},
{ data :"ISBN"},
{ data: "Title" },
],
columnDefs: [
{
"render": function ( data, type, row ) {
return data +' . '+ row[2];
},
"targets": 1
},
//{ "visible": false, "targets": [ 2 ] }
],
select: true,
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
} );
But in the table the InvSub is undefinded, even if in its own column the values are displayed. I'm new to datatables and I have no clue why this could be the case.
thank you in advance for your help
This question has an accepted answers - jump to answer
Answers
Likely the problem is with
return data +' . '+ row[2];
. You are using objects but that is trying to access the row data using array notation. You wil want something more like thisreturn data +' . '+ row.InvSub;
.Kevin