How can I get the value of a file type field with datatable?

How can I get the value of a file type field with datatable?

rrzavaletarrzavaleta Posts: 78Questions: 52Answers: 2

Hi, I'm trying to get the value of a file type field embedded within the rows of datatables.

$('#dtables').DataTable({
"lengthMenu": [[5, 10], [5, 10]],
"data":[{"Tipo":"RFC","Obligatorio":"SI","nombrearchivo":"archivo1","id":"1","Verificararchivo":"si" ,"status":"aprobado"}, {"Tipo":"Curp","Obligatorio":"No","nombrearchivo":"archivo2","id":"2","Verificararchivo":"no","status":"rechazado" }, {"Tipo":"ReciboCFE","Obligatorio":"SI","nombrearchivo":"archivo3","id":"3","Verificararchivo":"no","status":"rechazado" }],
"columns": [
{"width": "10%", "data": "Tipo"},
{"width": "40%", "data": "Obligatorio"},
{"width": "40%", "data": "nombrearchivo"},
{"width": "40%", "data": "id"},
{"width": "40%", "data": "Verificararchivo"},
{"width": "40%", "data": "status"},
{
data: null,
className: "center",
render: function(){
return '\<input type="file" />';
}
}
]
});

To obtain the data I use the following

$('#dtables tbody').off().on('click', 'tr', function (e) {
var dtables = $("#dtables").DataTable();
var fila = $(this).closest('tr');
var column_data = $(fila).children('td').parents('tr');

var Tipo = dtables.row(column_data).data()["Tipo"];
var Obligatorio = dtables.row(column_data).data()["Obligatorio"];
var nombrearchivo = dtables.row(column_data).data()["nombrearchivo"];
var id = dtables.row(column_data).data()["id"];
var Verificararchivo = dtables.row(column_data).data()["Verificararchivo"];
var idpersona = dtables.row(column_data).data()["idpersona"];
var files = dtables.row(column_data).$('input[type=file]')[0].files[0];

alert( files);

});

But I can not get the data (file) that corresponds to the row that is selected with the click event on the line. How can I solve get the value of field file when selecting the row to which I have clicked?

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Try using row().node() to get the tr element for the row. Then use jQuery to select the input[type=file] from that node.

    Allan

This discussion has been closed.