Loop through a table

Loop through a table

andrewcandrewc Posts: 4Questions: 0Answers: 0
edited October 2010 in General
Firstly thanks for creating a very useful tool! I have found it easy to use and powerful.

The one thing I am having a problem with is looping through all the rows of a table. I have a table with one input field I need to loop through the table and see if the field has been populated if so do something with the value.

I would have thought there would be a straight forward way to do this however I can't seem to find it. Essentially I want to do the follow

FOR EACH Row IN Table
FOR EACH Field IN Row
IF FieldID = "NewCost" THEN
Do Something
END IF
END FOR
END FOR

Could someone give me an idea on how to do this? I feel like i'm missing something really obvious but I can't quite figure it out

Replies

  • andrewcandrewc Posts: 4Questions: 0Answers: 0
    In case anyone else gets stuck like me I figured this out and its as simple as you'd expect.

    [code]
    // Get your dataTable and put it into a variable
    var oTable = $('#MyTable').dataTable();

    // Loops through the table returning each row
    $.each(oTable.fnGetNodes(), function(index, value) {
    // Fields called as follows
    var NewCost = $(".NewCost", value).val();
    }
    [/code]

    Simple! :)
This discussion has been closed.