function row().data()
function row().data()
Karl53
Posts: 72Questions: 29Answers: 0
If I understand DataTables' design correctly, function row().data() seems to return a new instance of the object.
Is there a way to initialize a var to point to the data for direct manipulation? For my purpose, I don't think I need to maintain a copy of the data, update it and then call row().data( d ) to set the data.
Thanks.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
It returns a new API instance, but the data contained in it is the original data given to DataTables.
Can you illustrate what you are trying to do with an example please?
Thanks,
Allan
Hi Allan,
Sure. What I want is a reference to the data that DataTables displays.
This does not do what I expect, i.e. change the displayed value:
This changes displayed value:
From the above, I surmise that
tableData
points to a copy of the data managed by DataTables and is not simply a reference to it. Otherwise, why is the call todata()
in below form, necessary iftableData
is a reference?function row().data( d )
Thanks for your assistance in understanding this.
(Sorry if the above code does not display on separate lines. I used Markdown but in Chrome, it displays in preview on one long line with horizontal scrollbar.)
The first method does not work since DataTables doesn't know that the data has changed - there is no listener on the data. With the advent of ECMAScript 1.7's Object.observe it will be possible to do that natively in browsers, but as far as I know, only Chrome supports it at the moment.
The correct way to update data is to use the
row().data()
orcell().data()
methods (unless you were to use a proxy for Object.observe, which is possible, but not something I've tried yet).Allan