数据表过滤器选项中不需要的字符 - JS JQuery

问题描述 投票:0回答:1

有人可以帮助我解决数据表的这个问题吗?我正在尝试按列值过滤行,并努力寻找一种方法来删除出现的 the 字符">

var a = $("#datatable-buttons").DataTable({
    lengthChange: !1,
    buttons: [{
        className: 'btn btn-outline-danger btn-sm waves-effect rounded-pill waves-light',
        text: '<i class="mdi mdi-account-plus-outline"></i> Add User',
        init: function(api, node, config) {
            $(node).removeClass('btn-secondary');
        },
        action: function(e, dt, node, config) {
            //This will send the page to the location specified
            window.location.href = 'add_user.php';
        }
    }],
    ordering: false,
    pageLength: 20,
    lengthChange: false,
    scrollY: "550px",
    initComplete: function () {
        this.api().columns().every(function () {
            var column = this;
            var select = $('<select class="form-select form-select-sm"><option value=""></option></select>')
                .appendTo($(column.header()).empty())
                .on('change', function () {
                    var val = $.fn.dataTable.util.escapeRegex(
                        $(this).val()
                    );

                    column
                        .search(val ? '^' + val + '$' : '', true, false)
                        .draw();
                });

            column.data().unique().sort().each(function (d, j) {
                select.append('<option value="' + d + '">' + d + '</option>');
            });
        });
    }
});

a.buttons().container().appendTo("#datatable-buttons_wrapper .col-md-6:eq(0)");
$(".dataTables_length label").addClass("form-label");
javascript jquery filter datatable
1个回答
0
投票

改变

                select.append('<option value="' + d + '">' + d + '</option>');

                select.append($('<option>', {
                    value: d,
                    text: d
                });

d
中的某些字符会导致 HTML 被错误解析。使用面向对象的方法可以避免这种情况。

© www.soinside.com 2019 - 2024. All rights reserved.