Get data from input in table cell using rows().data()
Get data from input in table cell using rows().data()
muhamadyuraz07
Posts: 8Questions: 3Answers: 0
hello, I'm having difficulties operating datatable when fetching data.
var table = $('#example1').DataTable({
"language": {
"sProcessing": "Procesando...",
"sLengthMenu": "Mostrar _MENU_ registos",
"sZeroRecords": "Não foram encontrados resultados",
"sEmptyTable": "Nenhum dado dísponivel nesta tabela",
"sInfo": "A mostrar registos de _START_ a _END_ de um total de _TOTAL_ registos",
"sInfoEmpty": "Mostrando registos de 0 a 0 de um total de 0 registos",
"sInfoFiltered": "(filtrado de um total de registos _MAX_)",
"sInfoPostFix": "",
"sSearch": "Pesquisar:",
"sUrl": "",
"sInfoThousands": ",",
"sLoadingRecords": "A carregar...",
"oPaginate": {
"sFirst": "Primeiro",
"sLast": "Último",
"sNext": "Seguinte",
"sPrevious": "Anterior"
},
"oAria": {
"sSortAscending": ": Ative para ordenar a coluna em ordem ascendente",
"sSortDescending": ": Ative para ordenar a coluna em ordem decrescente"
}
},
'order': [[1, 'asc']]
});
$('#example1 tbody').on("change", ".produtochkbox", function () {
var i = 0;
var data = table.rows().data();
console.log( 'The table has ' + data.length + ' records' );
console.log( 'Data', data );
data.each(function(){
//count the rows
console.log(i);
//getting all data from the table but in a raw format like an array of objects
console.log(data[i]);
//getting specific data example ( not working )
var id = table.cell('.id').data().text();
console.log(id);
i++;
});
});
My problem is that the code for getting the specific data that I want isn't working. Please help.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This example is doing something similar and should help. Note there is
row().data()
to get one row androws().data()
to get multiple rows.Kevin
Yes, I have seen those examples but my problem is that I'm trying to get specific data, not an array of data.
In my example there I used this code :
witch is not working.
What I'm aiming there is to select the text of the class '.id' witch is in the data cell.
Is there a way that I can do that?
The same goes for input in the table.
The data that is returning is :
What I want is :
For array based data you can do something like
row().data()[1]
for the data in column 1. Or if usingrows().data()
you can usepluck()
to get the specific column.However you can use
cell().data()
or you may need to usecell().node()
to get thetd
instead of the data. Usingtable.cell('.id').data()
is not specific enough as it doesn't limit to the row that is clicked. In your change event you probably will want something like this:Then parse the
data
variable to get what you want. Please see thecell()
docs for all the options of selecting the cell.If you need further help please build a simple tests case with examples of your data so we can provide more specific help.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thank you kthorngren.
Your answer solved my issue!!