Editor field: datatables without ajax

Editor field: datatables without ajax

dudidudi Posts: 1Questions: 1Answers: 0
edited September 2023 in Free community support

https://editor.datatables.net/examples/datatables/index.html

In the documentation i have the ajax option, but i have a nested json like this:
[{ first_name: '...', children: [{ name: '' , ...} ] } ]

const editor = new DataTable.Editor({
    data:: '../php/join.php', <-- this is not what i need, i need to access the children field in the row
    fields: [
        {
            label: 'First name:',
            name: 'first_name'
        },
      
   
        {
            label: 'Children:',
            name: 'children',
            type: 'datatable',
            config: {
                columns: [
                    {
                        title: 'Name',
                        data: 'name'
                    }
                ]
            }
        }
    ],
    table: '#example'
});

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    There isn't a data option for Editor. Line 2 of your code there won't do anything (plus there is a syntax error :)).

    Do you mean you want to load the list of options from the data object for the row? If so, do you have a separate value for which items in the list are selected?

    Or is it something more like this that you are working with? If so, you can use field().update() to modify the data in the DataTable field. Call that in initEdit - for example:

    editor.on('initEdit', function () {
      var rowData = table.row({selected: true}).data();
    
      editor.field('children').update(rowData.children);
    });
    

    Allan

Sign In or Register to comment.