Question about .each()
Question about .each()
orionaselite
Posts: 49Questions: 13Answers: 4
I have the following code
<!-- start test -->
<script>
var editor;
$(document).ready(function() {
//alert("test 1");
editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.portfolio.php',
table: '#portfolio',
fields: [
{
"label": "Coin:",
"name": "coin_name"
},
{
"label": "Num. Coins:",
"name": "amount_of_coins"
},
{
"label": "Coin Value:",
"name": "current_coin_value"
}
]
} );
//alert("test 2");
var table = $('#portfolio').DataTable( {
dom: 'Bfrtip',
ajax: 'php/table.portfolio.php',
columns: [
{
"data": "coin_name"
},
{
"data": "amount_of_coins"
},
{
"data": "current_coin_value"
},
{
"data": "current_cash"
},
{
"data": "perc"
}
],
select: true,
lengthChange: false,
buttons: [
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
});
/*start*/
table
.column( 0 )
.data()
.each( function ( value, index ) {
console.log( 'Data in index: '+index+' is: '+value );
} );
/*end*/
} );
</script>
<!-- end test -->
I know I am making some kind of stupid javascript mistake but shouldn't I see the values in my cells show up in my browser console. I see no erors in the console the table renders with the correct values
ideas?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Since you use ajax sourced data - and ajax is asynchronous - you need to use an event. Try "draw" or "init".
https://datatables.net/reference/event/
Or use the
initComplete
callback.Allan
thanks stupid mistake