Get/Set Table data from id
Get/Set Table data from id
I am using Editor, so each row has an id. I can print out the id as part of the create event, so I have the id, but can't figure out how to pull the row data back (and once i do, will want to set the data in the table for a column). i want to pull the data back outside of the create event once i store the id.
Say my row id was "1234566777"
I have tried both
table.row("#1234566777").data() and table.row("#1234566777").node(), but both come back as undefined. Is there a method to call to get this info?
thanks,
This question has an accepted answers - jump to answer
Answers
Sounds like you need to set the Datatables option
rowId
torowId: 'id'
or whatever the ID object is for the row. See the string ID example of therow-selector
docs.Kevin
sorry, don't understand that. I use string ID for the row id. i get the row id fine -- the question is once I have a valid row ID, how do I pull back the content in that specific row?
Where are you trying to pull it back from? Please post your relevant code with a description of what you are trying to do and where the problem is happening.
Kevin
editor.on( 'create', function ( e, json, data, id ) {
} );
This
id
is derived from the Editor'sidSrc
option.The Datatables
rowId
sets theid
property of thetr
. This is theid
used by using"#" + id
as therow()
selector. Have you definedrowId
in your Datatables config?I created a simple test case showing your above method works:
http://live.datatables.net/guwafemu/248/edit
If its a timing issue maybe use
postCreate
.Kevin
ah ok, thank you for the example. I was missing " rowId: 'name', in my table. I had idSrc in my Editor.
I was able to also then set/update a column in that row I pulled back from the ID, using some code I found here:
My only open question is how do I update the row id value for that row (dtrow)?
Yes, it is a timing issue. This is an example from my own coding using "submitSuccess" which you can use as well if you specify the correct action.
If you just need the id itself you could do:
After selecting a row, e.g. for editing you can use this instead:
The latter prepends a # to the start of the row id.
Not sure what you set this to but likely you will want it the same as your
idSrc
value.Not sure I understand the question. Whatever id you set using
rowId
should automatically be updated, assuming the created data returned from the server has that object property.Kevin
Sorry, what I mean on row ID, is I want to update the value of the rowid attribute for a specific row. so say my row comes back as "1113434343". I have the row and want to update the row id to "XYZ".
I will assume the property for your row id is
id
. Use therow().data()
API to update theid
value. For example:Make sure the id you are updating to is unique on the page.
Kevin
works great, thanks for your help