Update a row with an object

Update a row with an object

scullytrscullytr Posts: 12Questions: 0Answers: 0
edited January 2012 in DataTables 1.8
Hi, I'm trying to update a row in my dataTable with an unordered object/array that's structured like so:

[code]
var record = {
'field1': 'value1',
'field3': 'value1',
'field2': 'value1',
'field7': 'value1',
'field4': 'value1',
'field6': 'value1',
'field5': 'value1'
}
[/code]

I'm having trouble figuring out how to update the correct row-column with the correct data (e.g. the value of 'filed1' updates the row-column titled 'field1'). The number of elements in the object equals the number of columns in the row.

Thank you in advance for your help!

-Tim.

Replies

  • scullytrscullytr Posts: 12Questions: 0Answers: 0
    I realize that my question is a bit vague. Apologies.

    I know that I should use fnUpdate, and have an inkling that setting mDataProp is involved, but I'm having a hard time understanding how exactly to implement what I'm trying to achieve.
  • scullytrscullytr Posts: 12Questions: 0Answers: 0
    edited January 2012
    Here's an example of what I tried (and failed):

    I initialize dataTables with
    [code]
    var oTable = $('#example').dataTable( {
    "sAjaxSource": "sources/deep.txt",
    "aoColumns": [
    { "mDataProp": "engine" },
    { "mDataProp": "browser" },
    { "mDataProp": "inner" },
    { "mDataProp": "platform0" },
    { "mDataProp": "platform1" }
    ]
    } );
    [/code]

    and then I do some other stuff, resulting in an object like this
    [code]
    var record = {
    'platform1':'test',
    'inner':'blah',
    'browser':'this',
    'platform0':'that',
    'engine':'the other'
    }
    [/code]

    and then try to update row 1 with
    [code]
    oTable.fnUpdate(record, 1);
    [/code]

    and as I stated above, this doesn't work. :-/
  • scullytrscullytr Posts: 12Questions: 0Answers: 0
    Ha! The best developer's debugging tool: talking through the problem.

    Apparently mDataProp values are case sensitive, and one of my mDataProp values didn't match one of my object's properties exactly.

    Long-story-short, I got it to work.

    Thanks for "listening"! ;-)
This discussion has been closed.