Is it possible to get Associative arrays by "rows().data().toArray()" ?
Is it possible to get Associative arrays by "rows().data().toArray()" ?
Barbaros
Posts: 3Questions: 1Answers: 0
Hi,
i inserted rows manually via
$('#AddRow').on( 'click', function () {
t.row.add( [
$('#customer_name').val(),
$('#customer_tel').val(),
$('#customer_mail').val(),
] ).draw( false );
});
and send table to server and use ajax.
data: {datax :t.rows().data().toArray()},
i got indexed array- its ok . but i want named one- for example with column names .
is it possible ? i tried to set column names at the beginning . i also used title option
but it s not working for me .
Thanks.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Hi @Barbaros ,
It depends on whether you're using arrays or objects. You're using an array with you add the row (
row.add()
), so you need to use the index for the position of each field. If you were using objects, as in the first example on that page, then you could use the element name.Cheers,
Colin
Hi @colin ,thanks for your reply.
I got it .
one more question- (without ajax): this datatable is inside form and when i submit the form i want to post all table data with hidden input. is it possible or is there any better way to pass all data ?
Thanks .
and html :
and php:
it works but it merge all data in one row .
"[\"messi,123456789,messi@messi.com,ronaldo,111444777,ronaldo@ronaldo.com\"]"
Hi @Barbaros ,
You could iterate over the rows one at a time, and add it to an array, something like this pseudo code:
That would make a 2d array which would be tidier.
Cheers,
Colin
Try JSON.stringify to serialized the data before you put it in the hidden. Then deserialize on the back end. That should give you your array to work with.
@bindrid , @colin thanks for your replies,
after i changed
and add using JSON.stringify to serialized the data
and for backend
is worked for me, thanks for your helps .