Я делаю представление в веб-приложении cake php, где есть раскрывающийся список, и идея в том, что таблица, представленная в представлении, изменяется в соответствии с элементом, выбранным пользователем, но код Ajax, который я имею, не обновляется.таблица.
Я пробовал несколько кодов для вызова метода, который взимает плату с таблицы, но пока ни один из них не сработал.
$(document).ready(function () {
alert('JQuery is succesfully included');
$('.stateOption').click(function() {
var option = $(this).text();
alert(option);
if(option == "All"){
type = "Todos";
}
else if(option == "Pending"){
type = "Pendiente";
}
else if(option == "Published"){
type = "Publicado";
}
else if(option == "Rejected"){
type = "Rechazado";
}
else if(option == "Unpublished"){
type = "Despublicado";
}
var table = $('#tablaEstados').DataTable( {
"ajax": "CatRegistroTable.php",
"bPaginate":true,
"bProcessing": true,
"pageLength": 5,
"columns": [
{ type: 'type' } ,
]
});
});
});
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Choose a state
</button>
<ul class="dropdown-menu" id="publicationState" aria-labelledby="dropdownMenuButton">
<li role="presentation"><a href=# class ="stateOption" role="menuitem" tabindex="-1" >All</a></li>
<li role="presentation"><a href=# class="stateOption" role="menuitem" tabindex="-1" >Pending</a></li>
<li role="presentation"><a href=# class="stateOption" role="menuitem" tabindex="-1">Rejected</a></li>
<li role="presentation"><a href=# class="stateOption" role="menuitem" tabindex="-1" >Unpublished</a></li>
<li role="presentation"><a href=# class="stateOption" role="menuitem" tabindex="-1">Published</a></li>
</div>
</div>
<div class="mt-5 table-content">
<table id="tablaEstados" cellpadding="0" cellspacing="0" class="table table-striped table-hover">
<thead>
<tr>
<th scope="col"><?= $this->Paginator->sort('TITULO', 'Title') ?></th>
<th scope="col"><?= $this->Paginator->sort('AUTORES_PERSONAL', 'Author') ?></th>
<th scope="col"><?= $this->Paginator->sort('DISPONIBILIDAD', 'Available') ?></th>
<?php if($estado== "RECHAZADO" || $estado == "RECHAZADO" ):?>
<th scope="col"><?= $this->Paginator->sort('Notas', 'Notes') ?></th>
<?php endif; ?>
<th scope="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($catRegistro as $catRegistro): ?>
<tr style="cursor: pointer;">
<td class="w-50"><?= h($catRegistro->TITULO) ?></td>
<td class="w-25"><?= h($catRegistro->AUTORES_PERSONAL) ?></td>
<?php if ($catRegistro->DISPONIBILIDAD) { ?>
<td class="w-auto">Yes</td>
<?php } else { ?>
<td class="w-auto">No</td>
<?php } ?>
<td class="actions w-auto">
<?php if($estado == "RECHAZADO" ): /*Si el estado es rechazado se cargan las notas */?>
<td class="w-50"> Rejected </td>
<?php elseif( $estado == "Unpublished"): ?>
<td class="w-50"> Unpublished </td>
<?php endif; ?>
<?= $this->Html->link(__('View'), ['action' => 'view', $catRegistro->ID_REGISTRO, $catRegistro->TIPO_DE_MATERIAL], ['class' => 'd-none']) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $catRegistro->ID_REGISTRO, $catRegistro->TIPO_DE_MATERIAL], ['class' => 'pr-5']) ?>
<?php
echo $this->Html->link(__(''),
' ',
[
'class' => 'fas fa-trash-alt',
'data-toggle' => 'modal',
'data-target' => '#ConfirmDelete',
'data-id' => $catRegistro->ID_REGISTRO,
'escape' => false
]);
?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
public function myEntries($type = NULL)
{
$user = $this->Auth->user('ID_USUARIO');
$result = $this->CatRegistro->getUserEntries($user, $type);
debug($type);
$this->set('estado',$type );
$this->set('catRegistro', $this->paginate($result));
$this->set('_serialize', ['catRegistro']);
}
Iожидается, что таблица обновится после того, как пользователь щелкнет элемент раскрывающегося списка, вызвав функцию myEntries.