[fixed] fnGetPosition : nNode is undefined
[fixed] fnGetPosition : nNode is undefined
Hi !
First, thanks for this great plugin. I've used it some times, and it always worked properly.
But I have a question :
When I add a new row with the function fnAddData, everything is ok.
But when I need to update or delete this new row, I have to catch the row position with fnGetPosition().
It works with the rows loaded with the page but not after using fnAddData.
I tried some functions found in the forum, like :
[code]
function deleteTableRows ()
{
var nTr = this;
while ( nTr )
{
if ( nTr.nodeName == "TR" )
break;
nTr = nTr.parentNode;
}
var iPos = oTable.fnGetPosition( nTr );
fnDeleteRow( iPos );
}
[/code]
or
[code]
var row = $(this).closest("tr").get(0);
oTable.fnDeleteRow(oTable.fnGetPosition(row));
[/code]
But everytime, there's the same error : "nNode is undefined".
I'm a beginner in jQuery, and it would be great if I could solve this !
Thanks,
Joseph
First, thanks for this great plugin. I've used it some times, and it always worked properly.
But I have a question :
When I add a new row with the function fnAddData, everything is ok.
But when I need to update or delete this new row, I have to catch the row position with fnGetPosition().
It works with the rows loaded with the page but not after using fnAddData.
I tried some functions found in the forum, like :
[code]
function deleteTableRows ()
{
var nTr = this;
while ( nTr )
{
if ( nTr.nodeName == "TR" )
break;
nTr = nTr.parentNode;
}
var iPos = oTable.fnGetPosition( nTr );
fnDeleteRow( iPos );
}
[/code]
or
[code]
var row = $(this).closest("tr").get(0);
oTable.fnDeleteRow(oTable.fnGetPosition(row));
[/code]
But everytime, there's the same error : "nNode is undefined".
I'm a beginner in jQuery, and it would be great if I could solve this !
Thanks,
Joseph
This discussion has been closed.
Replies
This is a mix of sample codes from the API (example add row, and fnGetPosition)
It works only for the first row (not added by fnAddData).
[code]
/* Global variable for the DataTables object */
var oTable;
/* Global var for counter */
var giCount = 2;
$(document).ready(function() {
$('#example tbody td').click( function () {
/* Get the position of the current data from the node */
var aPos = oTable.fnGetPosition( this );
/* Get the data array for this row */
var aData = oTable.fnGetData( aPos[0] );
/* Update the data array and return the value */
aData[ aPos[1] ] = 'clicked';
this.innerHTML = 'clicked';
} );
/* Init DataTables */
oTable = $('#example').dataTable();
} );
function fnClickAddRow() {
oTable.fnAddData( [
giCount+".1",
giCount+".2",
giCount+".3",
giCount+".4" ] );
giCount++;
}
[/code]
Does anyone have an idea ?
Use the return value of fnAddDAta which is the row index and use fnUpdate to fill the row index in the functions Update / Delete, like this
[code]
var row = oTable.fnAddData( ['cell1', 'cell2', 'cell3', '', ''], true );
oTable.fnUpdate( '', row, 3 );
oTable.fnUpdate( '', row, 4 );
[/code]
Maybe you have a better answer, so I would be happy to know it ! :)
[code]
//Call to the function
Delete
function deleteTableRows(){
$("#example tbody").click(function(event) {
nTr = event.target.parentNode;
while ( nTr ){
if ( nTr.nodeName == "TR" ) break;
nTr = nTr.parentNode;
}
var iPos= oTable.fnGetPosition(nTr);
oTable.fnDeleteRow(iPos);
});
}
[/code]
It works fine for deleting added row ...
Joseph
[code]
$(document).ready(function() {
$(".removeButtonManager").live("click", function(event) {
var row = $(this).closest("tr").get(0);
managerTable.fnDeleteRow(managerTable.fnGetPosition(row));
});
});
[/code]
I' ve just tried your solution, and it works perfectly.
For the moment, I have this function to get the row position
[code]
//iPos is a global variable
$(".delete_lpr").live("click", function(event) {
var nTr = $(this).closest("tr").get(0);
iPos = tableau_lpr.fnGetPosition(nTr);
});
[/code]
and this one to delete the row
[code]
//I have to separe the two, because I need the data id
function delete_lpr(id){
if(confirm('Voulez-vous effacer cette ligne de produit ('+iPos+') ?'))tableau_lpr.fnDeleteRow(iPos);
}
[/code]
Here is the call
[code]
[/code]
It seems $(".delete_lpr").live("click", function(event) is called before delete_lpr('+lpr_id+'), and it works ...
If you have a cleaner solution, I'm interested !
Joseph