console log shows doubling of callback firing on each detection
console log shows doubling of callback firing on each detection
i have a table representing a fretboard. when i click on a cell i determine its coordinates and send them to a a server via web socket
the callback does a fnUpdateRow with new data sent back from the server on the web socket. the first click produced one console record, the second 2, the third 4, the 4th 8 etc until im unresponsive.
i am very new to this stuff so is there a way to prevent this with my current implementation or should i be using an entirely different technique
fnRowCallback: function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$('td', nRow).on('click', function() {
var aPos = oTable.fnGetPosition( this );
console.log(aPos, aData);
send({cbk:'updtRow', idx:aPos, row:aData, dat:'markNote[req]'});
});
}
} );
function updtRow(d){
oTable.fnUpdate(d.dat,d.row);
}
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "C"…}
steel.html:40
[5, 4, 4]
Object {F0: "B", F1: "C", F2: "C#", F3: "D", F4: "D#"…}
steel.html:40
[5, 4, 4]
Object {F0: "B", F1: "C", F2: "C#", F3: "D", F4: "D#"…}
steel.html:40
[7, 3, 3]
Object {F0: "F#", F1: "G", F2: "G#", F3: "A", F4: "A#"…}
steel.html:40
[7, 3, 3]
Object {F0: "F#", F1: "G", F2: "G#", F3: "A", F4: "A#"…}
steel.html:40
[7, 3, 3]
Object {F0: "F#", F1: "G", F2: "G#", F3: "A", F4: "A#"…}
steel.html:40
[7, 3, 3]
Object {F0: "F#", F1: "G", F2: "G#", F3: "A", F4: "A#"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "C"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
the callback does a fnUpdateRow with new data sent back from the server on the web socket. the first click produced one console record, the second 2, the third 4, the 4th 8 etc until im unresponsive.
i am very new to this stuff so is there a way to prevent this with my current implementation or should i be using an entirely different technique
fnRowCallback: function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
$('td', nRow).on('click', function() {
var aPos = oTable.fnGetPosition( this );
console.log(aPos, aData);
send({cbk:'updtRow', idx:aPos, row:aData, dat:'markNote[req]'});
});
}
} );
function updtRow(d){
oTable.fnUpdate(d.dat,d.row);
}
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "C"…}
steel.html:40
[5, 4, 4]
Object {F0: "B", F1: "C", F2: "C#", F3: "D", F4: "D#"…}
steel.html:40
[5, 4, 4]
Object {F0: "B", F1: "C", F2: "C#", F3: "D", F4: "D#"…}
steel.html:40
[7, 3, 3]
Object {F0: "F#", F1: "G", F2: "G#", F3: "A", F4: "A#"…}
steel.html:40
[7, 3, 3]
Object {F0: "F#", F1: "G", F2: "G#", F3: "A", F4: "A#"…}
steel.html:40
[7, 3, 3]
Object {F0: "F#", F1: "G", F2: "G#", F3: "A", F4: "A#"…}
steel.html:40
[7, 3, 3]
Object {F0: "F#", F1: "G", F2: "G#", F3: "A", F4: "A#"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "C"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
[2, 3, 3]
Object {F0: "G#", F1: "A", F2: "A#", F3: "B", F4: "B"…}
steel.html:40
This discussion has been closed.
Replies
Allan
how can i also get the column index?
$('#fretboard').delegate('tr', 'click', function(event) {
var aPos = oTable.fnGetPosition(this);
var aData = oTable.fnGetData(aPos);
console.log(aPos, aData);
// send({cbk:'updtRow', idx:aPos, row:aData, dat:'markNote[req]'});
});
[code]
$('#fretboard tbody').on( 'td', 'click', function (e) {
var pos = table.fnGetPosition( this );
...
} );
[/code]
Then fnGetPosition is passed in the `td` element and thus will return an array of information, such as the column index and row index.
Allan
event.returnValue is deprecated. Please use the standard event.preventDefault() instead. jquery-latest.js:5374
maybe i could purchase some support time from you to get past this hump
Allan
here is a link to my first datatables project so i think a donation is in order
https://docs.google.com/file/d/0Bw6v1jJR2jE_MlRpSTVSM29YaU0/edit?usp=sharing
Thanks for the link to your video - it looks great. Are you using web-sockets to update in realtime?
Allan
So if you use:
[code]
$('#fretboard tbody').on('click', 'tr', function(event) {
var aPos = oTable.fnGetPosition(this);
var aData = oTable.fnGetData(aPos[0]);
console.log(aPos, aData);
});
[/code]
What do you get? It should be that the console will print an array of index information (three elements in the array, row index, column index and visible column index), and then the data for the row that was clicked upon based on the 'tr' element.
Is it just the data you want? If so you can simplify and use:
[code]
$('#fretboard tbody').on('click', 'tr', function(event) {
var data = oTable.fnGetData( this );
console.log(data);
});
[/code]
since fnGetData will accept `tr` elements as well as index position.
Regards,
Allan
event.returnValue is deprecated. Please use the standard event.preventDefault() instead. jquery-latest.js:5374
and then nothing for any further clicks
your first example is what i need to work
I've just put together a little example showing how a click on the `td` element can be used to get the position and the data for the cell that is clicked upon. The live example is here: http://live.datatables.net/ukasip/edit#javascript,html
and this is the code used:
[code]
var table = $('#fretboard').dataTable();
$('#fretboard tbody').on('click', 'td', function(event) {
var pos = table.fnGetPosition(this);
var data = table.fnGetData(pos[0]);
console.log( 'Data for the cell clicked on: '+data[ pos[1] ] );
});
[/code]
This assumes are are using arrays as the data source for each row of course. Are you?
Regards,
Allan
i am assuming you have this working on a very isolated small example
can you tell me what version of jquery this works with for you?
i have the exact same problem with this code after changing var table to my var oTable
event.returnValue is deprecated. Please use the standard event.preventDefault() instead. jquery-latest.js:5374
and then nothing
i think i will have to get you the link to proceed any further. enjoy the holidays first tho
It is working in the example I linked to above ( http://live.datatables.net/ukasip/edit#javascript,html ). Click the "Render" button on the top left to see the example actually running. It is a small example, but it should show the principle. It will work with jQuery 1.7+. This is it with the very latest jQuery: http://live.datatables.net/ukasip/2/edit
Regards,
Allan