How to use "select" plugin with Ajax

How to use "select" plugin with Ajax

jstuardojstuardo Posts: 91Questions: 37Answers: 0

Hello,

I have this HTML table:

<table id="grd" class="table table-striped table-bordered" style="width:100%">
    <thead>
        <tr>
            <th></th>
            <th>ID</th>
            <th>Nombre</th>
            <th>Dirección</th>
            <th>Fecha Registro</th>
            <th>Fecha Actualización</th>
        </tr>
    </thead>
</table>

And then, this in JavaScript:

$('#grd').DataTable({
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.19/i18n/Spanish.json"
},
"processing": true,
"serverSide": true,
"ajax": "{{ path('empresa_get_all') }}",
"columns": [
{"data": "id"},
{"data": "id"},
{"data": "nombre"},
{"data": "direccion"},
{"data": "createdAt"},
{"data": "updatedAt"}
],
"order": [[1, "asc"]],
"scrollX": true,
"columnDefs": [ {
orderable: false,
className: 'select-checkbox',
targets: 0
} ],
"select": {
style: 'os',
selector: 'td:first-child'
},
});

I have "select" plugin loaded, of course.

After that execution, in checkbox column the record ID is displayed, instead of the checkbox. When I set an empty value for "data" in columns definition, an error is shown. If I remove the first "data", all columns appear left shifted.

I don't know what else to try.

Regsards
Jaime

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.