Editor datasource from a Javascript variable
Editor datasource from a Javascript variable
dbrody2004
Posts: 7Questions: 3Answers: 0
Couldn't find an example using a Javascript array as a datasource for Editor? Is this possible or is DOM and ajax only supported?
This discussion has been closed.
Answers
https://datatables.net/manual/data/#Javascript
https://datatables.net/examples/data_sources/js_array.html
Should work with Editor as well.
More on Javascript and the standalone Editor:
https://editor.datatables.net/manual/standalone#Setting-values
Tried with the following code but there is no data in the table and there are no buttons either.
you need to use markdown because your code is illegible this way. Please post a test case as well as per the forum rules.
There is no
data
property for Editor - I think you meant to put that into DataTables which does have adata
option.When you do that it sort of semi-works: http://live.datatables.net/xekakode/1/edit .
The problem now is that you have your data source as arrays, but you are telling DataTables and Editor to expect an object by using
columns.data
andfields.name
as strings. See the manual for more information about the difference between the two (generally I suggest using objects).Allan
Thanks. That helped and now it is working: http://live.datatables.net/dacedili/1/edit
After editing values in the table is the only way to get the dataset is to use the API and iterate through the rows? The editor does not modify the original javascript data object. The idea here is that the form would have a Save button which went clicked would push a json data array back to the server consisting of the whole modified table.
To get the data for all the table, you could just do
rows().data().toArray()
- possibly with aJSON.stringify()
,Colin