Butto at first position in DT version 1.10.12
Butto at first position in DT version 1.10.12
Hi, i have a datatables that work well with edit and delete button at end of datatables column. So for some DT i need to have botton at [0], [1] position.
What happen to me is that if i change
"aTargets": [14] to "aTargets": [0]
and
"aTargets": [15] to "aTargets": [1]
acoordling with html table i will receive error like this:
TypeError: f is undefined
...r[0];b=0;for(c=a.length;b<c;b++)f=l[b],f.nTf=a[b].cell,f.sClass&&h(f.nTf).addCla...
jquery.....min.js (linea 27, col 64)
So the question is_ how i can put my button on first and second position?
Thanks in advance.
This Is my js code:
var oTable;
$(document).ready(function() {
oTable = $('#example4').DataTable( {
"scrollX": true,
"lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"ajax": {
"url": "http://mysite.it/api/v5/read/anagrafica",
"dataSrc": ""
},
"columns": [
{ "mData": "id"},
{ "mData": "cognome"},
{ "mData": "nome"},
{ "mData": "indirizzo"},
{ "mData": "civico"},
{ "mData": "cap"},
{ "mData": "citta"},
{ "mData": "provincia"},
{ "mData": "nazione"},
{ "mData": "telefono"},
{ "mData": "cellulare"},
{ "mData": "email"},
{ "mData": "altraEmail"},
{ "mData": "bioShot"}
],
'columnDefs': [{
'searchable':false,
'orderable':false,
"mData":"id",
},
{"mRender": function (data, type, row) {
return '<button type="submit" class="btn btn-xs btn-outline btn-primary" onClick="edit_person(\'' + row.id + '\')" ><span class="glyphicon glyphicon-pencil"></span> Edit</button>';
},
"aTargets": [14]
},
{"mRender": function (data, type, row) {
return '<button type="submit" class="btn btn-xs btn-outline btn-danger" onClick="delete_person(\'' + row.id + '\')" ><span class="glyphicon glyphicon-trash"></span> Delete</button>';
},
"aTargets": [15]
},
],
} );
// start BUTTONs
new $.fn.dataTable.Buttons( oTable, {
buttons: [
{
extend: 'copyHtml5',
text: '<i class="fa fa-files-o" style="font-size:18px;color:black"></i>',
titleAttr: 'Copy',
footer: "true"
},
{
extend: 'excelHtml5',
text: '<i class="fa fa-file-excel-o" style="font-size:18px;color:green"></i>',
titleAttr: 'Excel',
footer: "true"
},
{
extend: 'csvHtml5',
text: '<i class="fa fa-file-text-o" style="font-size:18px;color:orange"></i>',
titleAttr: 'CSV',
footer: "true"
},
{
extend: 'pdfHtml5',
text: '<i class="fa fa-file-pdf-o" style="font-size:18px;color:red"></i>',
download: 'open',
titleAttr: 'PDF',
footer: "true"
},
{
extend: 'print',
text: '<i class="fa fa-print" style="font-size:18px;color:blue"></i>',
titleAttr: 'STAMPA',
footer: "true"
}
], } );
// end BUTTONs
oTable.buttons().container().appendTo('#cruscotto');
} );
HTML
<thead>
<tr>
<th>Id</th>
<th>Cognome</th>
<th>Nome</th>
<th>Indirizzo</th>
<th>Civico</th>
<th>Cap</th>
<th>Citta</th>
<th>Provincia</th>
<th>Nazione</th>
<th>Telefono</th>
<th>Cellulare</th>
<th>Email</th>
<th>AltraEmail</th>
<th>BioShot</th>
<th>edit</th>
<th>delete</th>
</tr>
</thead>
This question has an accepted answers - jump to answer
Answers
I would suggest not having both
columns
andcolumnDefs
options in the same initialisation - I think that will just confuse this! Move the edit and delete columns into thecolumns
array in the first and second positions and hopefully that will help clear things up.If not, can you link to a test case showing the issue please.
Allan
Thank you Allan!!! Work so well after following your suggestion. Thank You.
Sandro