0
I own in an HTML a datatable and on each line I have 3 inputs (text, datepicker and select) and a button, which will send to PHP, to record what was typed or selected in inputs from that line. What I’m trying to do is get the information from the line on which I hit the button. What I thought I’d do is serialize the chart and turn it into a array using Jquery; the problem is that it brings information from all lines of datatable, but what I need is just the line I push the button.
I can’t take the figures for id of inputs for the datatable is automatically populated by PHP.
Follows code:
var table = $('#tableList').DataTable();
$("#tableList").on("click", ".btnReceived", function() {
var data = JSON.stringify(table.$('input, select').serializeArray());
console.log(data);
});
Follow HTML where the button is created:
<a class='btn btn-orange btn-xs btnReceived' href='#' title='Confirmar Recebimento'><span class='glyphicon glyphicon-saved'></span><a/>
The others are coming empty?
– Rafael Augusto
They are. If the datatable has a thousand lines and I filled only 1, it brings in a thousand lines json, with 999 empty and 1 with what I filled.
– Prisley
But in this case, Voce can check those that are empty and use one
splice
to remove them, so will only keep the ones that were typed– Rafael Augusto
I believe that checking would not be a viable way, if I think about the point of view of my user, he will first fill the inputs and then go clicking the buttons, this would end with my verification... I believe that if there was a way to get only the information from the button line that I click, it would be better.
– Prisley
You do not understand, when I say check, I say even Voce, for the user will not make a difference, because the code itself would do all this.
– Rafael Augusto