Pass row().data() to php
Pass row().data() to php

Hey everyone,
we are using this great plugin for a while now and everything is working fine. But now we wanted to use data from the row().data() to use it as a filter for a database query.
How it should work is:
1. attached image 1
2. attached image 2
Code:
var a;
$(document).ready(function() {
var selected = [];
var dataTable = $('#example').DataTable( {
"paging": true,
"ordering": false,
"info": false,
"select": 'single',
"lengthChange": false,
"sDom": 'ltipr'
/* "rowCallback": function( row, data ) {
if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
$(row).addClass('selected');
}
}, */
} );
$('#example tbody').on('click', 'tr', function () {
var id = this.id;
var index = $.inArray(id, selected);
if ( index === -1 ) {
selected.push( id );
} else {
selected.splice( index, 1 );
}
//$(this).toggleClass('selected');
$('#valor').val(dataTable.row('.selected').data() );
datos = dataTable.row('.selected').data();
//alert(datos[0]);
} );
$("#filterbox").keyup(function() {
dataTable.search(this.value).draw();
});
$('#example').wrap('<div id="hide" style="display:none"/>');
$('#filterbox').keyup(function() {
$('#hide').css( 'display', 'block' );
} );
/*$("#formulario").bind("submit",function(){
// Capturamnos el boton de envío
var btnEnviar = $("#btnEnviar");
$.ajax({
type: $(this).attr("method"),
//url: ,
data: $(elemento).val(),
success: function( data ){
alert('funciono');
}
})c
});*/
$("#btnEnviar").click(function(){
a = datos[0];
//var a = JSON.stringify($('#valor').val());
$.ajax({
type: 'GET',
//url: 'prueba.php',
data: { a : a },
success: function( data ){
alert('Funciono');
alert(a);
}
})
});
});
<?php
if(isset($_GET['a'])){
$a = $_GET['a'];
echo $a;
}
I hope everything is included and understandable.
Thanks in advance for any help possible.
Regards,
This discussion has been closed.
Answers
I would suggest you try using
dataTable.row('.selected').data().toArray();
- otherwise it is a DataTables API instance you are trying to pass to the server.beyond that, we would need a link to a page showing the issue to be able to debug it.
Allan
Hello Allan,
thank you for your answer! We tried as suggested but got no result. We will look further into handling it with a API instance and hope for a positive result there.
Albert
If you can give me a link to the page showing the issue I can take a look at what is going on.
Allan