Django - Ajax 重新加载数据表

2024-06-01 08:55:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在寻找合适的解决方案,用Ajax在Django中重新加载datatable。在

目前,除了一个例外,它运行得很好。表由引导程序自动分页。当Ajax重新加载表时,它显示所有结果而不在页面上拆分。在

命令_列表.html公司名称:

<div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
        <div class="datatable-scroll">
        <table class="table datatable-basic dataTable table-striped no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
            <thead>
                <tr role="row">
                    <th class="sorting_asc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="" aria-sort="ascending">Nr.</th>
                    <th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="">Data</th>
                    <th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="">Przewoźnik</th>
                    <th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="">Status</th>
                    <th class="text-center sorting_disabled" rowspan="1" colspan="1" aria-label="Akcje" style="width: 100px;">Akcje</th>
                </tr>
            </thead>
            <tbody id="orders_table">
                {% include "orders/orders_table.html" %}
            </tbody>
        </table>
        </div>
</div>

命令_表格.html公司名称:

^{pr2}$

javascript代码:

setInterval(function(){
    $.ajax({    
       url: '/Project/zamowienia/orders_test',
          success: function(data) {
          $('#orders_table').html(data);
          }
    });
}, 10000)

在网址.py公司名称:

urlpatterns = [
    url(r'^$', orders_list),
    url(r'^orders_test$', orders_list_test),
]

观点:

def orders_list(request):
    orders = Order.objects.all().order_by('-shop_order_id')
    carriers = Carriers.objects.all().order_by('name')
    statuses = Status.objects.all().order_by('name')
    Status().import_status()
    Order().import_orders()
    return render(
            request, 'orders/orders_list.html', 
            {
                'namespace': 'Zamówienia',
                'icon': 'credit-card',
                'statuses': statuses,
                'carriers': carriers,
                'orders': orders
            }
        )


def orders_list_test(request):
    orders = Order.objects.all().order_by('-shop_order_id')
    return render(
                request, 'orders/orders_table.html', 
                {
                    'orders': orders
                }
            )

Tags: idhtmltableorderlabellistclassdatatables