I'm working on a web app with java play! framework, in a specific view I'm using DataTable for displaying a list of customers, I need to make the name column as a link, on click it should display the customer sheet.
My problem is this snippet:
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$('td:eq(0)', nRow).html(
'<a href="@routes.Dashboard.dettagliCliente("'+aData[3]+'")">'+aData[0] + '</a>');
return nRow;
}
When the app is running, and I click on a given customer, the view reach the controller but it doesn't pass the value of aData[3] to method, instead it pass literally the string "aData[3]"
This is the specific route:
GET /dashboard/dettagli_cliente/:idCliente controllers.Dashboard.dettagliCliente(idCliente:String)
And this is the controller:
public static Result dettagliCliente(String id){
Logger.info("CUSTOMER ID "+id);
final Cliente cliente = Cliente.findById(id);
Form<Cliente> formCliente = Form.form(Cliente.class).bindFromRequest();
Form<Cliente> filledForm = formCliente.fill(cliente);
return ok(registra_utente_form.render(User.findByEmail(request().username()),filledForm,cliente));
}
Update: This is the complete dataTable call on the view:
$(document).ready(function() {
$('#clienti_table').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "@routes.Dashboard.testList()",
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$('td:eq(0)', nRow).html('<a href="@routes.Dashboard.dettagliCliente("'+aData[3]+'")">'+aData[0] + '</a>');
return nRow;
},
});
});
If I wrote a sample customer id instead of aData[3]
, inside the href attribute, it works: on click on one of the customer list element it open the details for that given customer(id)
this is an example:
$(document).ready(function() {
$('#clienti_table').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "@routes.Dashboard.testList()",
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$('td:eq(0)', nRow).html('<a href="@routes.Dashboard.dettagliCliente("c0ed22dc-6c92-4a70-ad30-ea73e8b0c314")">'+aData[0] + '</a>');
return nRow;
},
});
});
Thank you everyone