Hello everybody,
I have two tables and I am working with Datatables and what I would like to
do is use the child row to show more information about a particular row.
For example, on the table I will display first name, last name, username,
and email and on the child or expandable row, I will show the nationality
of that user.
The problem I am having is that when I expand the row, it shows only the id
from the 'User' table and not the description associated to that id.
this is my first time dealing with Datatables so I don't have my experience
with it.
Any suggestions to solve this issue?
Thanks :)
DB
db.define_table('User',
Field('first_name', 'string'),
Field('last_name', 'string'),
Field('email','string'),
Field('username','string'),
Field('nationality','reference Nationality', requires =
IS_IN_DB(db,db.Nationality.id,'%(description)s')
)
db.define_table('Nationality',
Field('description','string'),
format = '%(descripcion)s'
)
My controler
def user():
import json
usuario = json.dumps(db(db.auth_user.id>0).select().as_list())
return dict(formListar=XML(usuario))
My view
<script>
var tabla;
$(document).ready(function(){
tabla= $('#tablaGenerica').DataTable({
"data": {{=formListar}},
"scrollX": false,
"dom": 'lrtip',
"searching": true,
"sRowSelect": "single",
"columns": [
{
"class":"details-control",
"orderable":false,
"data":null,
"defaultContent": ""
},
{ data: 'first_name' },
{ data: 'last_name' },
{ data: 'email' },
{ data: 'username' },
]
});
$('#tablaGenerica tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = tabla.row( tr );
if ( row.child.isShown() ) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child( format(row.data()) ).show();
tr.addClass('shown');
}
} );
function format ( d ) {
// `d` is the original data object for the row
return '<table cellpadding="5" cellspacing="0" border="0"
style="padding-left:50px;">'+
'<tr>'+
'<td>Nationality:</td>'+
'<td>'+d.nationality+'</td>'+
'</tr>'+
'</table>';
}
</script>
<table id="tablaGenerica" class="tablaC table-striped hover cell-border"
cellspacing="0" width="100%" >
<thead>
<tr>
<th></th>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
<th>Username</th>
</tr>
</thead>
</table>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.