I need some help. The result is showing up, but the data table formatting isn’t working—none of the buttons or search boxes are functioning.
Script
<code>$(document).ready(function() {
function initializeDataTable(numChave) {
new DataTable('#datatable-basic' + numChave, {
language: {
url: '//cdn.datatables.net/plug-ins/1.13.7/i18n/pt-BR.json',
decimal: ',',
},
ajax: {
url: '{{ route("get.ops", ":num_chave") }}'.replace(':num_chave', numChave),
type: 'GET',
dataSrc: 'data'
},
columns: [
{ data: 'COD_PRODUTO', name: 'COD_PRODUTO' }
],
processing: true,
serverSide: true,
dom: 'Bfrtip',
lengthMenu: [
[10, 25, 50, -1],
['10 Linhas', '25 Linhas', '50 Linhas', 'Mostrar tudo']
],
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print', 'pageLength'
],
initComplete: function() {
this.api().columns().every(function() {
let column = this;
let title = column.footer().textContent;
// Create input element
let input = document.createElement('input');
input.placeholder = title;
column.footer().replaceChildren(input);
// Event listener for user input
input.addEventListener('keyup', () => {
if (column.search() !== input.value) {
column.search(input.value).draw();
}
});
});
}
});
}
// Inicializar DataTables para cada tabela dinâmica
@foreach ($mrpsOps as $op)
initializeDataTable({{ $op->NUM_CHAVE }});
@endforeach
</code>
<code>$(document).ready(function() {
function initializeDataTable(numChave) {
new DataTable('#datatable-basic' + numChave, {
language: {
url: '//cdn.datatables.net/plug-ins/1.13.7/i18n/pt-BR.json',
decimal: ',',
},
ajax: {
url: '{{ route("get.ops", ":num_chave") }}'.replace(':num_chave', numChave),
type: 'GET',
dataSrc: 'data'
},
columns: [
{ data: 'COD_PRODUTO', name: 'COD_PRODUTO' }
],
processing: true,
serverSide: true,
dom: 'Bfrtip',
lengthMenu: [
[10, 25, 50, -1],
['10 Linhas', '25 Linhas', '50 Linhas', 'Mostrar tudo']
],
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print', 'pageLength'
],
initComplete: function() {
this.api().columns().every(function() {
let column = this;
let title = column.footer().textContent;
// Create input element
let input = document.createElement('input');
input.placeholder = title;
column.footer().replaceChildren(input);
// Event listener for user input
input.addEventListener('keyup', () => {
if (column.search() !== input.value) {
column.search(input.value).draw();
}
});
});
}
});
}
// Inicializar DataTables para cada tabela dinâmica
@foreach ($mrpsOps as $op)
initializeDataTable({{ $op->NUM_CHAVE }});
@endforeach
</code>
$(document).ready(function() {
function initializeDataTable(numChave) {
new DataTable('#datatable-basic' + numChave, {
language: {
url: '//cdn.datatables.net/plug-ins/1.13.7/i18n/pt-BR.json',
decimal: ',',
},
ajax: {
url: '{{ route("get.ops", ":num_chave") }}'.replace(':num_chave', numChave),
type: 'GET',
dataSrc: 'data'
},
columns: [
{ data: 'COD_PRODUTO', name: 'COD_PRODUTO' }
],
processing: true,
serverSide: true,
dom: 'Bfrtip',
lengthMenu: [
[10, 25, 50, -1],
['10 Linhas', '25 Linhas', '50 Linhas', 'Mostrar tudo']
],
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print', 'pageLength'
],
initComplete: function() {
this.api().columns().every(function() {
let column = this;
let title = column.footer().textContent;
// Create input element
let input = document.createElement('input');
input.placeholder = title;
column.footer().replaceChildren(input);
// Event listener for user input
input.addEventListener('keyup', () => {
if (column.search() !== input.value) {
column.search(input.value).draw();
}
});
});
}
});
}
// Inicializar DataTables para cada tabela dinâmica
@foreach ($mrpsOps as $op)
initializeDataTable({{ $op->NUM_CHAVE }});
@endforeach
Route
<code>Route::get('/get-ops/{num_chave}', [MrpItemController::class, 'getOps'])->name('get.ops');
</code>
<code>Route::get('/get-ops/{num_chave}', [MrpItemController::class, 'getOps'])->name('get.ops');
</code>
Route::get('/get-ops/{num_chave}', [MrpItemController::class, 'getOps'])->name('get.ops');
Controller
<code>public function getOps($num_chave, Request $request) {
$ops = DB::table('my_treqdevmats')
->where('NUM_CHAVEOP', $num_chave)
->select(['COD_PRODUTO', 'NUM_REQMATERIAL', 'QTD_REQUISITADA', 'DAT_CANCEL', 'FLG_CANCELADO'])
->get();
return response()->json([
'data' => $ops
]);
}
</code>
<code>public function getOps($num_chave, Request $request) {
$ops = DB::table('my_treqdevmats')
->where('NUM_CHAVEOP', $num_chave)
->select(['COD_PRODUTO', 'NUM_REQMATERIAL', 'QTD_REQUISITADA', 'DAT_CANCEL', 'FLG_CANCELADO'])
->get();
return response()->json([
'data' => $ops
]);
}
</code>
public function getOps($num_chave, Request $request) {
$ops = DB::table('my_treqdevmats')
->where('NUM_CHAVEOP', $num_chave)
->select(['COD_PRODUTO', 'NUM_REQMATERIAL', 'QTD_REQUISITADA', 'DAT_CANCEL', 'FLG_CANCELADO'])
->get();
return response()->json([
'data' => $ops
]);
}
The information in the column is appearing correctly, but none of the buttons or the search box are working. I would like to know what is wrong with the script so that the datatable functions, such as pagination, filtering, and the search box, are not working.