简体   繁体   English

DataTables行详细信息row()未定义

[英]DataTables Row Details row() undefined

I'm currently trying to implement this kind of table : https://datatables.net/examples/server_side/row_details.html 我目前正在尝试实现这种表: https//datatables.net/examples/server_side/row_details.html

I did a copy/paste of the example javascript to add it to my table but it keeps crashing on this : 我做了一个示例javascript的复制/粘贴,将它添加到我的表中,但它一直在崩溃:

   $("#dyntable2 tbody").on("click", "tr td.details-control", function () {
                var tr = $(this).closest("tr");
                var row = dt.row(tr); <<< At this line

With that error : "Uncaugth TypeError: undefined is not a function (anonymous function)" 出现该错误:“Uncaugth TypeError:undefined不是函数(匿名函数)”

EDIT : Here is the full javascript : 编辑:这是完整的JavaScript:

    var $ = jQuery.noConflict();

    function format(d) {
        return 'Flow Name + Id: ' + d.Flow.Name + ' ' + d.Flow.Id + '<br>' +
            'Id Session: ' + d.Id + '<br>' +
            'Placeholder for now, quick monitoring tool after';
    }

    $(document).ready(function() {

        var dt = $('#dyntable2').dataTable({
            lengthMenu: [[10, 25, 50, -1], ["10", "25", "50", "All"]],
            processing: true,
            searching: true,
            paging: true,
            pagingType: "full_numbers",
            serverSide: true,
            ajax: {
                url: "url",
                type: "POST"
            },
                    language: {
                url: "jquery/datatables/French.txt"
            },
            columns: [
                {
                   "class": "details-control",
                    data: null,
                    orderable: false,
                    defaultContent: ""
                },
               [...]
            ]
        });

        var detailsRows = [];

        $("#dyntable2 tbody").on("click", "tr td.details-control", function() {
            var tr = $(this).closest("tr");
            var row = dt.row(tr);
            var idx = $.inArray(tr.attr("id"), window.detailRows);

            if (row.child.isShown()) {
                tr.removeClass("details");
                row.child.hide();

                // Remove from the 'open' array
                window.detailRows.splice(idx, 1);
            } else {
                tr.addClass("details");
                row.child(format(row.data())).show();

                // Add to the 'open' array
                if (idx === -1) {
                    window.detailRows.push(tr.attr("id"));
                }
            }
        });

        // On each draw, loop over the `detailRows` array and show any child rows
        dt.on("draw", function() {
            $.each(window.detailRows, function(i, id) {
                $("#" + id + " td.details-control").trigger("click");
            });
        });

    });

How can i solve this problem since i used the same code as the example ? 我怎么能解决这个问题,因为我使用了与示例相同的代码?

In your code dt is a jQuery object which does not have a row() function. 在你的代码中, dt是一个没有row()函数的jQuery对象。 Use the API with dt.api().row(tr) to get the row. 使用带有dt.api().row(tr)API来获取行。

PS: This is a change from version 1.10 and before to 1.11. PS:这是从版本1.10到之前的更改为1.11。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM