dotdiego
dotdiego

Reputation: 157

DataTables Row Details row() undefined

I'm currently trying to implement this kind of table : 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 :

   $("#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)"

EDIT : Here is the full 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 ?

Upvotes: 1

Views: 3824

Answers (1)

Raidri
Raidri

Reputation: 17550

In your code dt is a jQuery object which does not have a row() function. Use the API with dt.api().row(tr) to get the row.

PS: This is a change from version 1.10 and before to 1.11.

Upvotes: 3

Related Questions