Skip to content Skip to sidebar Skip to footer

Undefined Values Using Jquery Datatable

I'm Using jQuery DataTable to expose data in table form; on the table, I have a button that opens a Bootstrap Modal to modify two of these value and I use Ajax to send modified val

Solution 1:

You have to define data as null (I believe you not want the button to be placed in the note column) :

...
{ "data": "note" },
{ "data": null,
  "render": function ( data, type, full, meta ) {
    return"<button type='button' class='btn btn-info btn-md' data-toggle='modal' data-id=\'" + full.id + "\' data-target='#myModal'> Edit </button>";
  }
}

and address full instead of data, i.e. data-id=\'" + full.id + "\'


$(this).data('id'); is wrong. It is jQuerys own invention of storing variables on an element. Unless you have added data-id with data() specifically you cannot retrieve it with data(). Use $(this).attr('data-id') instead.

Solution 2:

Solved by myself. Speaking with a colleague, we suppose that, cause the modal has his activation button code on a file as string and the rest of code into another, this may take some problems. We don't know if thies hypotesis is correct, but starting from this assumption we formulate this solution:

  1. we put a global variable id_event at the start of code;
  2. in the render function, set this variable with the data.id value, without using the data-id field in the modal button, by onclick in the button:

    { "data": null, "render": function ( data, type, full, meta ) {

                        return "<buttontype='button'class='btn btn-info btn-md'data-toggle='modal'data-target='#myModal'onclick=\'id_event="+data.id+"\'> Edit </button>";
    
                    }
    
  3. In the ajax function for sending data to Controller, set with IDnumber the formdata.idevent field:

    formdata.idevent = id_event; //add the event id to form data, after setting it with the IDnumber variabile

This made our code perfectly working.

Post a Comment for "Undefined Values Using Jquery Datatable"