Datatables rows.add error - Warning: Requested unknown

Datatables rows.add error - Warning: Requested unknown

DanaDana Posts: 17Questions: 10Answers: 1

I have been working with datatables for a couple of weeks and I have this custom datatables that I'm identifying by class (tableIdentifyClass):

var handleDataTable = function () {
        if ($("." + tableIdentifyClass).length) {
            table = $("." + tableIdentifyClass).DataTable({
                aaData: dataForTable,
                aoColumns: [
                    { mData: "IsDefault", title: "" },
                    { mData: "Name", title: "Name" },
                    { mData: "Icon", title: "Icon" },
                    { mData: "IsDefault", title: "" }],
                "order": [[1, "asc"]],
                "bAutoWidth": false,
                "lengthChange": false,
                "columnDefs": [{
                    "targets": 0,
                    "render": function (data, type, full, meta) {
                        if (type === 'display') {
                            if (!data)
                                return '<span class="fa-xs"><i class="fa fa-edit" style="font-size:125%" onclick:""></i></span>';
                            else return '<span></span>';
                        }
                        return (isNaN(data)) ? -1 : +data;
                    }
                },
                {
                    "targets": 2,
                    "render": function (data, type, full, meta) {
                        if (type === 'display') {
                            if (data != '')
                                return '<span class="fa-xs"><i class="fa ' + data + '" style="font-size:125%"></i></span>';
                            else return '<span>-</span>';
                        }
                        return (isNaN(data)) ? -1 : +data;
                    }
                },
                {
                    "targets": 3,
                    "render": function (data, type, full, meta) {
                        if (type === 'display') {
                            if (!data)
                                return '<a class="fa-xs"><i class="fa fa-times" style="font-size: 125%; color: red;" onclick="deletePrefLocally(' + full.UId + ',' + full.Id + ',\'' + tableIdentifyClass + '\')"></i></a>';
                            else return '<span></span>';
                        }
                        return (isNaN(data)) ? -1 : +data;
                    }
                }]
            });
        }
    }

The data for the table (dataForTable):

[ { "Icon": "fa-exclamation-circle", "IsDefault": true, "Name": "Nixon", "UId": 1 },
     { "Icon": "fa-exclamation-circle", "IsDefault": false, "Name": "Tiger", "UId": 2 }]

I'm trying to delete the second row by calling function deletePrefLocally

function deletePrefLocally(uId, deletedId, tableIdentifyClass) {
        var crtUsage = dataForTable; //same items as the table
        var inItems = crtUsage.filter(function (elem) {
            return elem.Id === deletedId; // find the item with the same id
        })[0];
        var found = crtUsage.indexOf(inItems);
        if (found != -1) crtUsage.splice(found, 1);

        table = $("." + tableIdentifyClass);
        datatable = table.DataTable();
        datatable.clear();
        datatable.rows.add(crtUsage).draw();
}

My problem is that the last row datatable.rows.add(crtUsage).draw(); pops-up a message: DataTables warning: - Request unknows parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
Why is not applying the new content? Why after closing the error box I have two search areas and paging and all the values are null? What am I doing wrong?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 47,045Questions: 1Answers: 6,628 Site admin

    Can you link to the page showing the issue or use the debugger (after the error has occurred) to give us a trace?

    Thanks,
    Allan

  • DanaDana Posts: 17Questions: 10Answers: 1
    Answer ✓

    Found the reason... After all the page was loaded I've checked if based on tableIdentifyClass I'll receive true after calling $.fn.DataTable.isDataTable( '.' + tableIdentifyClass) but it was false. When calling datatable = table.DataTable(); I was creating a datatable inside the existing one, duplicate search area and paging :( I've tried to save all the "tables" after initialization inside an global array and search for it in order to add the new rows. Perhaps this is not the best solution but it worked for me.

Sign In or Register to comment.