Editor fields from dom

Editor fields from dom

MaikelMaikel Posts: 75Questions: 18Answers: 1

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:

Answers

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    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

  • allanallan Posts: 61,849Questions: 1Answers: 10,134 Site admin

    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

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    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,

  • allanallan Posts: 61,849Questions: 1Answers: 10,134 Site admin
    Answer ✓

    The other option, in that case, is to use fields.name and fields.data. By default, if you don't set fields.data directly (which none of the examples do), it will automatically use the value of fields.name.

    The difference between the two:

    • fields.name: The name of the parameter that is submitted to the server
    • fields.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

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    thanks let me try this out

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    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

  • allanallan Posts: 61,849Questions: 1Answers: 10,134 Site admin

    Can you give me a link to an updated Fiddle?

    Allan

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    can we have the editor inside jsfiddle?
    i never succeeded in doing so

  • allanallan Posts: 61,849Questions: 1Answers: 10,134 Site admin

    I'm afraid not at the moment (I need to make that possible!). You can however do it at http://live.datatables.net .

    Allan

  • MaikelMaikel Posts: 75Questions: 18Answers: 1

    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

  • MaikelMaikel Posts: 75Questions: 18Answers: 1
    Answer ✓

    ok, i figured it out, seems to work.

    Thanks a lot

This discussion has been closed.