When adding row: Requested unknown parameter '0' for row 1, column 0.

When adding row: Requested unknown parameter '0' for row 1, column 0.

spillino72spillino72 Posts: 9Questions: 2Answers: 0
edited November 2021 in Select

I have two Datatables:
transportInterfaceTable = $('#transportsInterfaceList').DataTable
transportAttachedInterfacesTable= $('#transportsInterfaceAttached').DataTable

I'm copying rows from transportInterfaceTable to transportAttachedInterfacesTable using select extension.
The row is added to the Datatable transportAttachedInterfacesTable but without the data as the error is returned: Requested unknown parameter '0' for row 1, column 0.

I'm using this code to do that:

$(document).on('click', '#attachInterfaceBTN', function(){
// Get selected rows data as an array
var data = transportInterfaceTable.rows( {selected: true} ).data().toArray();
console.log(data);
// Add selected rows to table2
transportAttachedInterfacesTable.rows.add( data ).draw();
});

The console log returns this correct data:

[{…}]
0:
capacity: "n/a"
description: "No Attach"
interfacename: "ATM1/0"
ipaddress: "0.0.0.0"
status: "In Service"
tipo: "Local Loop A"
[[Prototype]]: Object
length: 1
[[Prototype]]: Array(0)

Code for each Datatable:

var transportAttachedInterfacesTable= $('#transportsInterfaceAttached').DataTable({
                //retrieve: true,
                dom: '<lf<t>ip>',
                serverSide: true,
                destroy: true,
                select: true,
                language: {
                    emptyTable: "Hostname doesn't exist!"
                },
                ajax: {
                    url: rotta1
                },
                columns: [
                            { data: 'interfacename', name: 'interfacename', className: "textCenter" },
                            { data: 'ipaddress', name: 'ipaddress', className: "textCenter" },
                            { data: 'description', name: 'description', className: "textCenter" },
                            { data: 'tipo', name: 'tipo', className: "textCenter" },
                            { data: 'capacity', name: 'capacity', className: "textCenter" },
                            { data: 'status', name: 'status', className: "textCenter",
                                render: function(data, type, row, meta){
                                    // some code
                                }
                            },
                            {
                                data: 'interfaceID', 
                                orderable: false,
                                searchable: false,
                                defaultContent: '',
                                checkboxes: {
                                selectRow: true,
                                }, 
                            },
                        ],
                        select: {
                            style: 'multi',
                        }
            });

var transportInterfaceTable = $('#transportsInterfaceList').DataTable({
                dom: "<'row'<'col-sm-4'f><'col-sm-2'r><'col-sm-4'l><'col-sm-2 bottoneModifica'>>" +
                    "<'row'<'col-sm-12't>>" +
                    "<'row'<'col-sm-6'i><'col-sm-6'p>>",
                serverSide: true,
                destroy: true,
                select: true,
                language: {
                    emptyTable: "Hostname richiesto non esiste!"
                },
                ajax: rotta,
                columns: [
                            { data: 'interfacename', name: 'interfacename', className: "textCenter" },
                            { data: 'ipaddress', name: 'ipaddress', className: "textCenter" },
                            { data: 'description', name: 'description', className: "textCenter" },
                            { data: 'tipo', name: 'tipo', className: "textCenter" },
                            { data: 'capacity', name: 'capacity', className: "textCenter" },
                            { data: 'status', name: 'status', className: "textCenter",
                                render: function(data, type, row, meta){
                                    // some code
                                }
                            },
                            {
                                //data: 'id', 
                                data: 'interfaceID',
                                orderable: false,
                                searchable: false,
                                defaultContent: '',
                                checkboxes: {
                                selectRow: true,
                                }, 
                            },
                        ],
                select: {
                    style: 'multi',
                }
            });

HTML has identical tables.

Can you explain to me why having identical Datatables in the definition of the columns the error is returned: Requested unknown parameter '0' for row 1, column 0.
And please how could I fix it?
Thanck's in advance
Regards

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,948
    Answer ✓

    The row is added to the Datatable transportAttachedInterfacesTable but without the data as the error is returned: Requested unknown parameter '0' for row 1, column 0.

    The error seems inconsistent with the code you posted.

    Requested unknown parameter '0'

    Indicates an array based table but you are using columns.data for the table transportAttachedInterfacesTable. Is the id referenced in the error transportsInterfaceAttached?

    The row is added to the Datatable transportAttachedInterfacesTable

    You are using serverSide: true, which means rows.add() won't work as it is for client side processing only. You can see in this simple example that the row is not added with server side processing:
    http://live.datatables.net/runepaju/1/edit

    Comment out serverSide: true and re=run the test case. You will see the row is added. With server side processing you will need to update the server database then have transportAttachedInterfacesTable use draw() or ajax.reload() to update the client side table. Or use client side processing by removing serverSide: true.

    In order to help please post a link to your page or a test case replicating the issue so we can see what is happening.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • spillino72spillino72 Posts: 9Questions: 2Answers: 0

    Thanks for your response. I followed your directions. I commented serverside but I always get the same error: "DataTables warning: table id=transportsInterfaceAttached - Requested unknown parameter '0' for row 1, column 0." and the lines are added blank.

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,948

    I took your basic code snippets and put them into this example (without server side processing):
    http://live.datatables.net/hakonina/1/edit

    The test case works as expected. In order to help we will need to see the problem occur. As noted in the technote the "unknown parameter '0'" indicates the Datatable is expecting the rows to be arrays not objects but you have defined Datatables to use objects with columns.data. There is something inconsistent with the code you posted and the error.

    Kevin

  • spillino72spillino72 Posts: 9Questions: 2Answers: 0

    Thank you so much. I solved. I was sticking to using an existing datatable. I modified the code to destroy the second datatable and created a new datatable client side. It works. Thanks again, your support has been greatly appreciated.

Sign In or Register to comment.