Editor fields from dom
Editor fields from dom
Hi,
i have a dom loaded dataTable and i want to apply editor on top of this.
I know the column headers i want to use, but how can i get the editor to know the fields?
in the dataTables initialisation i don't provide the columns option. As the table format can change based on some session parameters.
How can i create the fields editor config from the dataTables column headers?
Is there a way?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
https://jsfiddle.net/csL0bue1/
this is a simple example of how i start dataTables.
now i want to add editor on top of this, to edit column edit1 and edit2
What I would recommend is to use the
columns.data
option with your DataTable to have DataTables read the DOM information into objects rather than arrays (which it does by default). Documentation about that is available here.That way you can then use
fields.name
like you would with an Ajax sourced table to reference both the data point and the name of the field to send to the server. Example available here.Allan
the problem is that i can not fill the columns option of the dataTables intialisation, as i don't know the columns ....
The table is generated by a php script, and the columns is a dynamic set based on the preferences of the user.
So i only know the columns at the moment the page is fully loaded,
The other option, in that case, is to use
fields.name
andfields.data
. By default, if you don't setfields.data
directly (which none of the examples do), it will automatically use the value offields.name
.The difference between the two:
fields.name
: The name of the parameter that is submitted to the serverfields.data
: The data point used to read the field's value from the table's data source.Since it is an array that DataTables reads DOM sourced tables into, you can set
fields.data
to be an integer (i.e.0
to get column index 0).So if you are programmatically creating this, you can use array indexes.
Of course, when it is then submitted to the server you then need to either be able to set a name, or decode an array index at the server-side to know which field in the table it is that is being edited.
Allan
thanks let me try this out
To bad, but i can't get this working
i build the array for the fields option, but then nothing happens, the edit form stays empty
Can you give me a link to an updated Fiddle?
Allan
can we have the editor inside jsfiddle?
i never succeeded in doing so
I'm afraid not at the moment (I need to make that possible!). You can however do it at http://live.datatables.net .
Allan
cool, i have one here:
http://live.datatables.net/bofikiyi/4/
on live.datatables my code seems to work, but on my enviroment i get an error
https://snag.gy/wsQNtM.jpg
ok, i figured it out, seems to work.
Thanks a lot