簡體   English   中英

我需要在ajax操作之后刷新數據表

[英]I need to refresh a datatable after an ajax action

我需要在ajax操作之后刷新數據表,我已經嘗試了所有發現的內容,但沒有任何幫助,數據表手冊說要使用table.api()。ajax.reload();。 但我無法解決問題,還嘗試破壞數據表並再次呈現它,但無法正常工作,請尋求幫助。

這是我的代碼:

var form=document.getElementById("formEditMantenimientoRolDetails");
var formData = new FormData(form);
$.ajax({
    url: '{{ path('editRolMantenimiento') }}',
    type: 'POST',
    data: formData,
    cache: false,
    contentType: false,
    processData: false,
    success: function (returndata) {
        if (returndata.success == true) {
            $.unblockUI();
            $('#editRol').modal('hide');
            Notificacion("success", "Valoración RP", "Los datos se han guardado correctamente.");
            $('#sample_2').load(window.location + ' #sample_2 >  *');
        }
    }
})

這行($('#sample_2').load(window.location + ' #sample_2 > *');)有效,但是我丟失了可排序表。

編輯:

我的桌子:

<table class="table table-striped table-bordered table-hover" id="sample_2">
   <thead>
       <tr class="header">
           <th class="table-checkbox noprint">
               <input type="checkbox" class="group-checkable" data-set="#sample_2 .checkboxes" disabled/>
           </th>
           <th width="20%" style="text-align:center;" onclick="sortTable(1)">
               Rol aplicación
           </th>
           <th width="20%" style="text-align:center;" onclick="sortTable(2)">
               Descripción del rol
           </th>
           <th width="20%" style="text-align:center;" onclick="sortTable(3)">
               Nivel de Permiso
           </th>
           <th width="20%" style="text-align:center;" onclick="sortTable(4)">
               Estado
           </th>
           <th width="20%" class="noprint" style="text-align:center;">
               Acciones
           </th>
       </tr>
   </thead>
   <tbody id="tablaIndexRol">
       {% for rol in rol %}
       <tr class="odd gradeX">
           <td class="noprint">
               <input type="checkbox" class="checkboxes" disabled/>
           </td>
           <td style="text-align:center;">
               {{ rol.rol }}
           </td>
           <td style="text-align:center;">
               {{ rol.descripcion }}
           </td>
           <td style="text-align:center;">
               {{ rol.permiso.nombre }}
           </td>
           <td style="text-align:center;">
               {% if rol.enabled == 1 %}
               Activo
               {% else %}
               Inactivo
               {% endif %}
           </td>
           <td class="noprint" style="text-align:center;">
               <a class="btn btn-sm default" data-toggle="modal" onclick="showMantenimientoRol({{rol.id}})">Ver</a>
               <a class="btn btn-sm blue" data-toggle="modal" onclick="editMantenimientoRolDetails({{rol.id}})">Editar</a>
           </td>
       </tr>
       {% endfor %}
   </tbody>
</table>

謝謝。

要重新加載數據表,我使用了以下方法:

$(document).ready(function () {
    var DataTable = $('#dataTable').DataTable({
        // insert datatable commands here
    });

然后,要重新加載它,

DataTable.ajax.reload();

您的代碼沒有顯示.DataTable({})函數,因此您需要添加它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM