JQuery DataTable重置按钮点击

时间:2017-09-07 15:12:39

标签: javascript jquery button datatables click

我在一个网站上使用jQuery DataTables,该网站具有常规搜索框和一些预设按钮,按下时按列对表进行排序。当按钮重置时,代码确实对表进行排序,但它会在1/2秒内立即重置。这是我的代码:

//CATEGORY BUTTONS
        $("#Term").on('click', function (event) {
            dataTable.column(2).search('Term').draw();

        });

我四处搜寻并查看了许多论坛。这应该是正确的,但结果总是立即重置表单。我删除了搜索框功能,看看是否存在干扰并导致问题,但问题仍然存在。它只是快速地将结果闪烁,然后将其全部重置为再次显示整个列表。这可能是Internet Explorer的事情(这台机器无法访问任何其他浏览器)?

以下是完整代码:

$(document).ready(function () {
        //USES API FOR DYNAMIC SEARCHING
        //RENDERS TABLE
        var dataTable = $("#videos").DataTable({
            "paging": false,
            bjQueryUI: true,
            ajax: {
                url: "/api/videos",
                dataSrc: ""
            },
            columns: [
                {
                    width: "70%",
                    data: "title",
                    render: function (data, type, video) {
                        var videoTitle = video.title.toUpperCase();
                        return "<VideoItem><a href='" + "../" + video.url + "'>" + "<spacerTop>" + videoTitle + "</spacerTop></a></VideoItem>";
                    }
                },
                {
                    width: "10%",
                    visible: false,
                    data: "description",
                    render: function (data) {
                        return data;
                    }
                },
                {
                    width: "10%",
                    visible: false,
                    data: "categoryName",
                    render: function (data) {
                        return data;
                    }
                },
                {
                    width: "10%",
                    visible: false,
                    data: "meta",
                    render: function (data) {
                        return data;
                    }
                },
                {
                    width: "10%",
                    visible: false,
                    data: "date",
                    render: function (data) {
                        return data;
                    }
                },
                {
                    width: "10%",
                    visible: false,
                    data: "categoryID",
                    render: function (data) {
                        return data;
                    }
                }

            ]


        });


        //CONTROLS DELETE BUTTON ACTION
        $("#videos").on("click", ".js-delete", function () {
            var button = $(this);

            bootbox.confirm("Are your sure you want to delete this video?", function (result) {
                if (result) {
                    $.ajax({
                        url: "/api/videos/" + button.attr("data-video-id"),
                        method: "DELETE",
                        success: function () {
                            button.parents("tr").remove();
                        }
                    });
                }
            });

        });

        //MAKES SEARCH BOX ON TOP INTERACT WITH DATATABLE
        $(".search-box-input").keyup(function () {
            dataTable.search(this.value).draw();
        });

        //CATEGORY BUTTONS
        $("#Term").on('click', function (event) {
            dataTable.column(2).search('Term').draw();

        });


    });

0 个答案:

没有答案