Access td onclick and do some functionality.
Access td onclick and do some functionality.
Hello Everyone,
Thanks for sharing all your knowledge about datatables. It helped me to understand its details.
I have a quick question:
I am trying to access a cell of a datatable. I can access a row and delete it using:
$("#example td").live('click', function(event) {
var row = $(this).closest("tr").get(0);
oTable.fnDeleteRow( row );
});
Above code gives me a row when I click on that.
JavaScript Debugger: http://live.datatables.net/uzahod/2/edit#javascript,html
Can you please tell me, how can I click on a single cell of datatable row and then do further functionality. I have a delete image in that cell. Once someone clicks on that delete image and in that row, then the current row will get deleted. Similarly, I have an edit button in another cell - on that cell on clickevent, I am planing to write a functionality to edit other cells values from the same row.
I am looking for some code as above which will allow me to select onclick even once particular cell is clicked. My generated databale is here:
Some String Value
2012-07-03 22:20:00.0
Some String Value2
2012-07-03 22:22:10.0
Some String Value3
2012-07-03 18:21:00.0
Also, I am not sure, how can I assign "id" to any "" present for rename, delete and download. I tried this, but this "id" gets assigned to image and also the same id gets assigned to all rows.
var editImage = '';
$('td:eq(2)', nRow).html(editImage);
var deleteImage = '';
$('td:eq(3)', nRow).html(deleteImage);
var downloadImage = '';
$('td:eq(4)', nRow).html(downloadImage);
Please help!
Thanks!
Thanks for sharing all your knowledge about datatables. It helped me to understand its details.
I have a quick question:
I am trying to access a cell of a datatable. I can access a row and delete it using:
$("#example td").live('click', function(event) {
var row = $(this).closest("tr").get(0);
oTable.fnDeleteRow( row );
});
Above code gives me a row when I click on that.
JavaScript Debugger: http://live.datatables.net/uzahod/2/edit#javascript,html
Can you please tell me, how can I click on a single cell of datatable row and then do further functionality. I have a delete image in that cell. Once someone clicks on that delete image and in that row, then the current row will get deleted. Similarly, I have an edit button in another cell - on that cell on clickevent, I am planing to write a functionality to edit other cells values from the same row.
I am looking for some code as above which will allow me to select onclick even once particular cell is clicked. My generated databale is here:
Some String Value
2012-07-03 22:20:00.0
Some String Value2
2012-07-03 22:22:10.0
Some String Value3
2012-07-03 18:21:00.0
Also, I am not sure, how can I assign "id" to any "" present for rename, delete and download. I tried this, but this "id" gets assigned to image and also the same id gets assigned to all rows.
var editImage = '';
$('td:eq(2)', nRow).html(editImage);
var deleteImage = '';
$('td:eq(3)', nRow).html(deleteImage);
var downloadImage = '';
$('td:eq(4)', nRow).html(downloadImage);
Please help!
Thanks!
This discussion has been closed.
Replies
$('#example.display tbody tr#0.odd td img').live('click', function(){
alert("I am clicked");
});
But now issue is: "tr#0" I am checking now, if above block can be generalized and can be used for all images present for all datatable rows.
Thanks!
$('#example.display tbody tr td img#delete').live('click', function(){
alert("I am clicked");
});
Ok at this point of time, this way I can make the block generalized. I will post if I need anything.
Thanks Everyone!
if ($(this).find('#delete').length > 0) {
$('#myTable').fnDeleteRow(this.parentNode);
}
});[/code]
That block looks great. However I am getting error:
$("#example").fnDeleteRow is not a function
[code]var oTable = $("#example").dataTable();
oTable.on('click', 'td', function(event) {
if ($(this).find('#delete').length > 0) {
oTable.fnDeleteRow(this.parentNode);
}
});[/code]
Thanks!
Here is the code:
[code]
$('#example.display tbody tr td img#delete').live('click', function(){
console.log("Delete clicked");
var oTable = $('#example').dataTable();
var nRow = $(this).closest("tr").get(0);
var aData = oTable.fnGetData(nRow);
("#DeleteConfirmationModalWindow").html(''+'Are you sure you wish to delete order:'+'
'+aData[0]+'?'+'');
$("#DeleteConfirmationModalWindow").dialog('open');
$("#DeleteConfirmationModalWindow").dialog({
title: "Delete Confirmation",
autoOpen: false,
dialogClass: "DeleteConfirmationModalWindow",
closeOnEscape: false,
draggable: false,
width: 400,
height: 200,
modal: true,
buttons: {
"Yes, I'm sure": function() {
$( this ).dialog( "close" );
console.log("Delete");
deleteDatabaseRow(oTable, nRow);
oTable.fnDeleteRow(nRow);
},
Cancel: function() {
$( this ).dialog( "close" );
console.log("No delete");
}
},
resizable: false,
open: function() {
$('body').css('overflow','hidden');
},
close: function() {
$('body').css('overflow','auto');
}
});
});
[/code]
Thanks!
Thanks!