首页 > 解决方案 > 使用 django 排序呈现的 jQuery 数据表不起作用

问题描述

我似乎无法在点击时订购此表。该应用程序正在从 Django 检索表并成功呈现它。但是,当我继续单击表格列顶部的箭头时,会出现一个框显示“正在处理”,但不会发生重新排序。当我以编程方式禁用serverSide它以使其仅在第一次发生时,ajax 调用无论如何都会发生。

    $(document).ready( function () {
        $.fn.dataTable.ext.errMode = 'throw';
        var table = $('#{{ grid_id }}').DataTable({
            "paging": {{paging}}
            ,"searching": false
            ,"info": true
            ,"stateSave": false
            ,"orderable": true
            ,"ordering": true
            ,"processing": true
            ,"serverSide": true
            {% if ajax_url is not None %}
            ,"ajax": {
                /* "type": "POST", */
                "url": "{{ ajax_url }}",
                "dataSrc": "results",
                "data": function (d) {
                    d.customParam = "custom";
                }
            }{% endif %}{% if column_list is not None %}
            ,"columns": [
                {% for col in column_list %} { "title":"{{ col.title }}", "data": "{{ col.data }}"
                {% if col.href is not None %}, fnCreatedCell: function (nTd, sData, oData, iRow, iCol) { $(nTd).html("<a href='{{col.href}}"+oData.{{ col.href_data_attr }}+"'>"+oData.{{ col.data }}+"</a>");}{% endif %}
                },{% endfor %}
            ]
            {% endif %}
        });
    });

标签: jquerydjangodatatablesdatatables-1.10

解决方案


推荐阅读