getting error Uncaught TypeError: Cannot read property 'node when trying fnGetPosition()

getting error Uncaught TypeError: Cannot read property 'node when trying fnGetPosition()

petitsingepetitsinge Posts: 11Questions: 1Answers: 0
edited January 2014 in General
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.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Please link to a test case showing the problem: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    Allan
  • petitsingepetitsinge Posts: 11Questions: 1Answers: 0
    Hello 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
  • petitsingepetitsinge Posts: 11Questions: 1Answers: 0
    I did my best to include only the right part of code that were necessary.

    http://jsfiddle.net/3W6hh/
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    [code]
    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
  • petitsingepetitsinge Posts: 11Questions: 1Answers: 0
    Hello Allan, I split it in two operation because it wasn't working.

    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?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    What is `this` in the context of your `deleteRow` function? It really would be very helpful to see a test case showing the problem. Try using http://live.datatables.net which includes DataTables.

    > to use the fnAddTr I need to use the pluging right, its not included into jquery.dataTables.?

    Correct.

    Allan
  • ashiersashiers Posts: 101Questions: 8Answers: 7
    Noticed you are on the Java platform. Were you aware of a library of classes that support DataTables on the Java platform? Check it out. http://jed-datatables.ca/jed/
  • petitsingepetitsinge Posts: 11Questions: 1Answers: 0
    Hello 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
  • petitsingepetitsinge Posts: 11Questions: 1Answers: 0
    Anyone can help?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    As I suspected, `this` in your function was not the button that was clicked on, but rather the DOM window. So the `tr` element you were getting was undefined - a single line of debug confirms that.

    I would very strongly recommend against using DOM0 functions and use jQuery events instead:
    http://live.datatables.net/Amec/2/edit

    Allan
  • petitsingepetitsinge Posts: 11Questions: 1Answers: 0
    Thank you so much for your help 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.
This discussion has been closed.