Frank
Frank

Reputation: 740

DataTables warning: Requested unknown parameter '4' from the data source for row ''

Are Days and days that I'm looking for this problem, but nothing resolved it! This warning appear after the add of a Student to my Database. The persist of the Data is Ok, so i need to hide this error or adjust it. So i have a Datables that give me this error:

enter image description here

This is my html code:

<script type="text/javascript">
    $(document).ready(function () {

        $("#companies").dataTable({
            "bServerSide": true,
            "sAjaxSource": "/studentiSource",
            "bProcessing": true,
            "sPaginationType": "full_numbers",
            "bJQueryUI": true,
            "aoColumns": [
                          {  "sName": "ID", "mDataProp": null,
                             "bSearchable": false,
                             "bSortable": false,
                             "bVisible": false
                                 },
                  { "sName": "NOME",},
                  { "sName": "COGNOME"},
                  { "sName": "USERNAME"},
                  { "sName": "PASSWORD" },
                  { "fnRender": function (oObj) {
                      console.log(oObj);                          
                      return '<a href=${pageContext.request.contextPath}/modificaStudente.jsp?id=' + oObj.aData[0] + '>' + 'Gestisci' + '</a>';
                    }}

                 ]
     }).makeEditable({
         sUpdateURL : "/updateStudenti" ,
         sAddURL: "/studenteServlet",
         sDeleteURL: "/deleteStudenti",
         fnShowError: function (message, action) {
             switch (action) {
                 case "update":
                     jAlert(message, "Update failed");
                     break;
                 case "delete":
                     jAlert(message, "Delete failed");
                     break;
                 case "add":
                     $("#lblAddError").html(message);
                     $("#lblAddError").show();
                     break;
             }
         },
         fnStartProcessingMode: function () {
             $("#processing_message").dialog();
         },
         fnEndProcessingMode: function () {
             $("#processing_message").dialog("close");
         }
      });
                });

And the table is:

 <div id="container">
        <div id="demo_jui">
        <button id="btnAddNewRow" value="Ok">Aggiungi nuovo studente...</button> 
        <button id="btnDeleteRow" value="cancel">Rimuovi utente selezionato</button>
        <div id="processing_message" style="display:none" title="Processing">Attendere.. Caricamento dati in corso</div>
            <table id="companies" class="display">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Nome</th>
                        <th>Cognome</th>
                        <th>Username</th>
                        <th>Password</th>
                        <th>Dispense</th>


                    </tr>
                </thead>
                <tbody >

                </tbody>
            </table>
        </div>


        <form id="formAddNewRow" action="#" title="Aggiungi nuovo studente">
                    <label id="lblAddError" style="display:none" class="error"></label>

            <input type="hidden" id="id" name="id" value="-1" rel="0" />
            <input type="hidden" value="aggiungi" name="action">
            <label for="name">Nome</label><input type="text" name="nome" id="name" class="required" rel="1" />
            <br />
            <label for="name">Cognome</label><input type="text" name="cognome" id="address" rel="2" />
            <br />
            <label for="name">Username</label><input type="text" name="username" id="postcode"/>
            <br />
            <label for="name">Password</label><input type="text" name="password" id="town" rel="3"/>
            <br />

        </form>

    </div>

I'm using Datatables 1.9.4

Upvotes: 0

Views: 12839

Answers (2)

mbigpro
mbigpro

Reputation: 3

The sixth element of your JSON array doesn't contain the value for key '4' because you're fetching a null value, try to parse your JSON array to http://jsoneditoronline.org/ and you'll see it.

Upvotes: 0

josephtikva1
josephtikva1

Reputation: 789

I cant give you a definitive answer, since you did not include the JSON response from the server.

This message usally means that DataTables is looking at your data source for array position 4 (which is the fifth element -- the password field) and not finding it.

You should make sure that you are returning a response with all the fields specified in the datatables definition, including the password field.

Upvotes: 2

Related Questions