Iterate over rows, get data from each cell

Iterate over rows, get data from each cell

krokonosterkrokonoster Posts: 10Questions: 0Answers: 0
edited February 2012 in General
I add rows to my datatable as the user enter data (oTable.fnAddData(....). Works fine.

However, upon submit I want to save the records by posting each row (or all??) to a server action method via ajax.

Not sure what is the right api call to get all rows, or iterate over rows and reading data?
(Will keep looking while waiting for an answer)

Replies

  • krokonosterkrokonoster Posts: 10Questions: 0Answers: 0
    edited February 2012
    I tried this (from http://datatables.net/release-datatables/examples/api/form.html)

    [code]
    $('#btnSubmit').click(function (event) {
    var nNodes = oTable.fnGetNodes();
    if (nNodes.length < 1) {
    alert("Please add at least one exception.");
    return;
    }
    var sData = $('input', oTable.fnGetNodes()).serialize();
    alert("The following data would have been submitted to the server: \n\n" + sData);
    return false;
    });
    [/code]

    However, allthough a few rows was added to the table (at runtime), sData is just empty.
  • krokonosterkrokonoster Posts: 10Questions: 0Answers: 0
    uurgh, fiddled more without luck:
    [code]
    var nodes = oTable.fnGetNodes();
    var data = $('input', nodes).serialize();
    alert(nodes.length); // fine..give me # rows in table
    alert("Data is: " + data); // nope. empty
    alert(data.length); // nope. 0
    event.preventDefault();
    [/code]
  • krokonosterkrokonoster Posts: 10Questions: 0Answers: 0
    hmmm, just noticed that 'input' in the code I copied. Obviously I don't have any input elements in my datatable.
This discussion has been closed.