Datatables Editor - Nested

Datatables Editor - Nested

tiago.fernandestiago.fernandes Posts: 13Questions: 4Answers: 0
edited June 2023 in Editor

I've been editing the Nested editing table in order to understand if it can do what I need, but i'm having no luck finding out.

I have a table with a list of customers.

table Customers:
fields: id, CustomerName
row: 455, 'JOHN DOE'

I would like to add to this customer some invoice numbers and date
table Invoices:
fields: id, date, CustomerID
row: 1, 2023-06-26, 455
row: 2, 2023-06-26, 455

If there's no invoices of a customer, the nested will be empty but available to add new lines
Using this logic, is it possible to use the Nested editing?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Answer ✓

    You probably want the parent / child editing example instead. With that you can have a different set of data in the child table for each parent row (which I think it what you are looking for).

    Allan

  • tiago.fernandestiago.fernandes Posts: 13Questions: 4Answers: 0

    that's exactly right, thank you allan

  • tiago.fernandestiago.fernandes Posts: 13Questions: 4Answers: 0
    edited July 2023

    While still on this topic, I'm having a little problem and I can't figure how to solve.

    Regarding the parent / child editing example I noticed when I'm creating a new Site I can't associate users right away - The entry has to be submitted into the database and then after that I'll go the newly create Site and associate Users.

    I need a workaround for this so my idea was after saving the new Site, close and immediatly reopen the new entry with child Users available. Because the child Users ishidden - and for a good reason.

    I tried something like this but it doesn't reopen the new RowId

    siteEditor.on('create', function (e, json, data, action) {
      //alert('A new row with ID ' + data.DT_RowId + ' has been created!');
      //alert('A new row with ID ' + data.ordem_nacional + ' has been created!');
      siteEditor.close();
      siteEditor.edit(data.DT_RowId);
    });
    

    Could someone tell me if there's a better way to do this?

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Right - you can't assign a user to a new site, since the new site doesn't have an ID until it is created. That id is needed to write into the database for the schema I've used there.

    If you invert it, you can do something like this, but that might not be ideal for you.

    Instead, what you could do is immediately edit a new site row when it is created as you've tried to do. I think you would actually need to use:

    siteEditor.edit('#' + data.DT_RowId);
    

    i.e. add the # to make it a DOM id selector. Otherwise Editor / DataTables will likely see a number and that is a data index selector in DataTables.

    Allan

Sign In or Register to comment.