fnGetData() doesn't have changes to content?

fnGetData() doesn't have changes to content?

jaycsjaycs Posts: 14Questions: 0Answers: 0
edited April 2012 in General
I've got a table that gets data by ajax. One of the columns has a some html in it; a couple of radio buttons. I use this to take a users selection and post-back to my application. This allows the user to make radio selections across pages, but when it comes for me to post the results back to the application, I can't get the users selections out of the tables data; the data hasn't updated, despite me being able to see it in the table.

For instance:

The user makes a radio button choice, clicks submit, a custom event handler then calls:

[code]$("#mytable").dataTable().fnGetData()[/code]

This gives me the big old array of data I need, but when I come to dig out the row and cells I need that contain the radio buttons, none of them have been updated with the checked="checked" attribute I would expect to see.

Is fnGetData() only the original ajax data, not the current tables data after modification?

That doesn't sound right, as I can navigate pages of the table and see the right radio button selections, and the table only has one page of data in the dom at any one time, so I know the data I need is somewhere, but not fnGetData()?

Thanks!

Replies

  • igaligal Posts: 2Questions: 0Answers: 0
    hi jaycs ,
    I have the same problem.. have you found a solution?
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    > Is fnGetData() only the original ajax data, not the current tables data after modification?

    More or less yes - DataTables doesn't put any hooks on the table data, so it has no idea that the state has changed. fnGetData always returned the current data that DataTables knows about. If you want to change that data you need to use the API - fnUpdate for example.

    However, you are working with live DOM elements (form controls), so that isn't really want you want - you don't want the texture representation at all - you want the value read straight from the element. For that you can use the $ or fnGetNodes functions. That will get all TR elements and give you them to work with. The $ method is a jQuery 'shortcut' (i.e. it takes into account paging etc), so you could just pass that return throughout serialize() for example: oTable.$('tr').serialize().

    Allan
This discussion has been closed.