Editor : DOM sourced table

Editor : DOM sourced table

gravstengravsten Posts: 17Questions: 5Answers: 0

Hi,

Your example "say that Editor will work with any data source that DataTables can use".
https://editor.datatables.net/examples/advanced/htmlTable.html

But how does with work if I want to initialize the table with this ?
data: [["","Genève","Veyrier"],["","Vaud","Morges"]],

Up until now, all my tables were initialized this way, each row being an array of strings.
But with Editor, clicking on a cell raises an error: Unable to automatically determine field from source.

Then I tried to convert the above data, so that each row be an object of keys/values with an id added for good measure:
[{"id":"0","select":"","state":"Genève","city":"Veyrier"},{"id":"1","select":"","state":"Vaud","city":"Morges"}]
But this raises the warning: Requested unknown.

An example of locally provided data (not HTML, just a plain array) would be much appreciated.

Answers

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    In general using objects is much better than arrays. With arrays you will need to use the array index as the fields.name. Also you will need a column containing an ID that the Editor can use to keep track of the row being edited. Use idSrc and point to the index of the array element containing the ID. Here is a simple example:
    https://live.datatables.net/guwafemu/487/edit

    But this raises the warning: Requested unknown.

    Guessing you didn't use columns.data to map the columns to the object. Hard to say without seeing what you tried.

    Kevin

  • gravstengravsten Posts: 17Questions: 5Answers: 0

    Your example made it very clear how to use arrays.
    Thank you very much !

Sign In or Register to comment.