DataTables warning: table id=datatable-buttons - Requested unknown parameter '0' for row 1, column 0

DataTables warning: table id=datatable-buttons - Requested unknown parameter '0' for row 1, column 0

buenzbuenz Posts: 5Questions: 1Answers: 0

I got this error when using this code. There is a null data that was inserted in the first row before my retrieved data

function retrieve_user(){
  $.ajax({
    url:'../conn/callFunc.php',
    method:'POST',
    data:{
      _trans:'retrieve_user'
    },
    success:function(msg){
        var table = $('#datatable-buttons').DataTable();
        table.rows.add( $(msg) ).draw();
      }
    })
}

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,771

    table.rows.add( $(msg) ).draw();

    Assuming that msg has the correct data structure you will probably want to change the above line to:

    table.rows.add( msg ).draw();

    Kevin

  • buenzbuenz Posts: 5Questions: 1Answers: 0

    When i change the code. It still produce an error and it populates 1.6k+ of data to the table.

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,771

    I believe that error provides a link to help you troubleshoot:
    https://datatables.net/manual/tech-notes/4

    What are your findings from following the steps provided?

    Without knowing your table structure and the structure of the data being returned its hard to help. Maybe you can provide a ink to your page with the issue.

    Kevin

  • buenzbuenz Posts: 5Questions: 1Answers: 0

    https://ibb.co/h7uqf6 - with ($(msg))

    https://ibb.co/b40ADR - with (msg)

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,771
    edited November 2017

    ($(msg))

    Ok, you are returning HTML then?

    Can you post your HTML table structure?

    Can you post the returned HTML?

    Kevin

  • buenzbuenz Posts: 5Questions: 1Answers: 0
                    <table id="datatable-buttons" class="table table-striped table-bordered">
                          <thead>
                            <tr>
                              <th>ID</th>
                              <th>Full Name</th>
                              <th>Age</th>
                              <th>Address</th>
                              <th>Action</th>
                            </tr>
                          </thead>
                      <tbody>
                      </tbody>
                    </table>
    
  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,771

    I created an example:
    http://live.datatables.net/wawitutu/1/edit

    Adding HTML formatted table data works in the example using the code you have provided.

    There must be something in the HTML data being returned from your ajax call. Can you post the returned HTML? If not can you post a link to your page for troubleshooting?

    Kevin

  • buenzbuenz Posts: 5Questions: 1Answers: 0


    1.png 11.8K
    3.png 8.6K
  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,771

    It looks like you are returning 3 rows. You are providing only a portion of the returned data using screenshots which is not providing enough info to help. Can you post the actual text of the full returned HTML?

    Or put your returned data into the test case I provided? You will need to remove one column.

    Kevin

This discussion has been closed.