help with click handler

help with click handler

roommroomm Posts: 1Questions: 0Answers: 0
edited March 2012 in General
im using datatable with json source.i'm trying to add a click handler to select a simple row but i can't do it.
the datatable loads fine but the handler didn' work.
i had to files, one with the html an other with the javascript.



this is the html file:
[code]



Test




@import "css/demo_page.css";
@import "css/demo_table.css";
@import "css/jquery.dataTables.css";









Delete selected row







Name


mail






Loading...








[/code]

and this is the javascript file :

[code]
var sity;
$(document).ready(function()
{

/* Add a click handler to the rows - this could be used as a callback */
$("#test tbody tr").click( function(e)
{

if ( $(this).hasClass('row_selected') )
{
$(this).removeClass('row_selected');
}
else {
sity.$('tr.row_selected').removeClass('row_selected');
$(this).addClass('row_selected');
}
});
/* Add a click handler for the delete row */
$('#delete').click( function()
{
var anSelected = fnGetSelected( sity );
alert(anSelected[0]);
sity.fnDeleteRow( anSelected[0] );
}
);
/* Cargar la datatable Principal */
sity = $('#test').dataTable
({
'iCookieDuration': 60,
'bStateSave' : true,
'bServerSide' : true,
'bAutoWidth' : false,
'sPaginationType': 'full_numbers',
'sAjaxSource' : 'index.php/home/read',
'aoColumns' :
[
/* "bSearchable": false, "bVisible": false,*/

{ 'sName' : 'name' },
{ 'sName' : 'email' }
],
'fnServerData': function(sSource, aoData, fnCallback)
{
$.ajax
({
'dataType': 'json',
'type' : 'POST',
'url' : sSource,
'data' : aoData,
'success' : fnCallback
});
}
});
}
);

function fnGetSelected( oTableLocal )
{
return oTableLocal.$('tr.row_selected');
}
[/code]



what's wrong?? thanks for all!
This discussion has been closed.