Retrieval of a div.attribute from a clicked cell
Retrieval of a div.attribute from a clicked cell
Many thanks for any hint - most probably it's a piece of cake but I don't see it at the moment.
I have setup a table via datatable. In some cells I have to include some uuid for referencing in a mysql-database. Clicking in the cell with the uuid given should "return":
1) the uuid and
2) the cell position (e.g. to delete or manipulate that row/cell afterwards).
Here is the code capable of returning the position (2):
[code]
var oTable = $('table').dataTable({})
oTable.fnAddData(['Some clickable text', 'B5'])
oTable.$('td').bind('click', function () {
alert('Clicked....');
var pos = oTable.fnGetPosition(this);
var posx = pos[0];
var posy = pos[1];
var dataofpos = oTable.fnGetData(posx, posy);
alert('Position: ' + pos);
alert('Data: ' + dataofpos);
var uuid = $(dataofpos).attr('myattr'); //BIG QUESTION!
alert('uuid: ' + uuid);
})
[/code]
And how can I apply the binding only to the cell with the div? As soon as I use
[code]oTable.$('td .clickme').bind('click',function(){})[/code]
nothing is working at all. I even tried to get the parent from the this - but this does not help.
Any hint welcome!
I have setup a table via datatable. In some cells I have to include some uuid for referencing in a mysql-database. Clicking in the cell with the uuid given should "return":
1) the uuid and
2) the cell position (e.g. to delete or manipulate that row/cell afterwards).
Here is the code capable of returning the position (2):
[code]
var oTable = $('table').dataTable({})
oTable.fnAddData(['Some clickable text', 'B5'])
oTable.$('td').bind('click', function () {
alert('Clicked....');
var pos = oTable.fnGetPosition(this);
var posx = pos[0];
var posy = pos[1];
var dataofpos = oTable.fnGetData(posx, posy);
alert('Position: ' + pos);
alert('Data: ' + dataofpos);
var uuid = $(dataofpos).attr('myattr'); //BIG QUESTION!
alert('uuid: ' + uuid);
})
[/code]
And how can I apply the binding only to the cell with the div? As soon as I use
[code]oTable.$('td .clickme').bind('click',function(){})[/code]
nothing is working at all. I even tried to get the parent from the this - but this does not help.
Any hint welcome!
This discussion has been closed.
Replies
[code]
oTable = $('table').dataTable({})
oTable.fnAddData(['Some clickable text','B5'])
oTable.$('td').bind('click',function(){
var pos=oTable.fnGetPosition(this);
var posx=pos[0];
var posy=pos[1];
var dataofpos=oTable.fnGetData(posx,posy);
alert( 'Position: ' + pos );
alert( 'Data: ' + dataofpos);
var uuid=$(dataofpos).attr('myattr');
alert( 'uuid: '+uuid);
})
[/code]
I tried using the general selector and then moving up in hierarchy with .parents() BUT THIS DOES NOT WORK - no clue why!
[code]oTable = $('table').dataTable({})
oTable.fnAddData(['Some clickable text', 'B5'])
$('.clickme').bind('click', function () {
var pos = oTable.fnGetPosition($(this).parent().parent());
var posx = pos[0];
var posy = pos[1];
var dataofpos = oTable.fnGetData(posx, posy);
alert('Position: ' + pos);
alert('Data: ' + dataofpos);
var uuid = $(dataofpos).attr('myattr');
alert('uuid: ' + uuid);
})[/code]