getting error Uncaught TypeError: Cannot read property 'node when trying fnGetPosition()
getting error Uncaught TypeError: Cannot read property 'node when trying fnGetPosition()
petitsinge
Posts: 11Questions: 1Answers: 0
I've been struggling with this one during he whole day.
I have a table with data in it as well as an image that when clicked will delete the row on which it appears.
I'm filling up the table programatically with data the user provide in a textArea "csv using tab character".
With my table i know i could just do a $("#trID").remove() but then the line background color doesn't follow the odd/even line number anymore.
This is why i would like to use the fnDeleteRow function.
[code]
function copyImportToF24() {
var importTxtArea, rows, cols, testString, recordCount;
importTxtArea = $(importF24).val();
rows = importTxtArea.split(/\n/);
for ( var i in rows) {
cols = rows[i].split(/\t/);
if (cols.length > 2) {
recordCount = parseInt($("#rowIdCount").val()) + 1;
$("#rowIdCount").val(recordCount);
var row = ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+"'> ";";
oTable.fnAddTr($(row)[0]);
[/code]
The div deteteRow shows a small icon.
[code]
function deleteRow(){
var row = $(this).closest("tr").get(0);
oTable.fnDeleteRow(oTable.fnGetPosition(row));
}
[/code]
THanks for your help.
I have a table with data in it as well as an image that when clicked will delete the row on which it appears.
I'm filling up the table programatically with data the user provide in a textArea "csv using tab character".
With my table i know i could just do a $("#trID").remove() but then the line background color doesn't follow the odd/even line number anymore.
This is why i would like to use the fnDeleteRow function.
[code]
function copyImportToF24() {
var importTxtArea, rows, cols, testString, recordCount;
importTxtArea = $(importF24).val();
rows = importTxtArea.split(/\n/);
for ( var i in rows) {
cols = rows[i].split(/\t/);
if (cols.length > 2) {
recordCount = parseInt($("#rowIdCount").val()) + 1;
$("#rowIdCount").val(recordCount);
var row = ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+ ""
+"'> ";";
oTable.fnAddTr($(row)[0]);
[/code]
The div deteteRow shows a small icon.
[code]
function deleteRow(){
var row = $(this).closest("tr").get(0);
oTable.fnDeleteRow(oTable.fnGetPosition(row));
}
[/code]
THanks for your help.
This discussion has been closed.
Replies
Allan
Thank you for your answer.
I would like to link to a testcase on jsfiddle.net but how will i import the jquery datatable css and java files?
Thank
PetitSinge
http://jsfiddle.net/3W6hh/
function deleteRow(){
var row = $(this).closest("tr").get(0);
oTable.fnDeleteRow(oTable.fnGetPosition(row));
}
[/code]
That looks like it should work to me. In fairness you could just do:
[code]
oTable.fnDeleteRow( $(this).closest("tr").get(0) );
[/code]
I don't see what would be wrong with that.
Allan
i did a console.log(row)
and it returns *undefined*
To me, i must be doing something wrong but what?
to use the fnAddTr I need to use the pluging right, its not included into jquery.dataTables.?
I created a new js file that i put in the same directory as the jquery.dataTables.js
I copied the code the plugin into the file and that's it right?
> to use the fnAddTr I need to use the pluging right, its not included into jquery.dataTables.?
Correct.
Allan
Here is the link to my project on the live system.
http://live.datatables.net/Amec/1/
I feel that when i create the new row in the table it doesn't add an index or something to the datatable.
Thank you very much for your help.
Yan
I would very strongly recommend against using DOM0 functions and use jQuery events instead:
http://live.datatables.net/Amec/2/edit
Allan
I'm sure a simple debug showed you the error, I'm still fearly new to the whole web programming "about 6 months into it" and have to jungle between javascript / jquery, html and css, ajax / json, spring ...
Again thanks again for you help.