Editor with unknown number of common rows

Editor with unknown number of common rows

Karl_SKarl_S Posts: 20Questions: 6Answers: 0

I am using datatables to show registrations for events we hold. For one registration there may be multiple people, each with their own information. I am using an Object to hold my table data:

{id:001, someInfo:'some data',
  registrationInfo:{address:'My Address', paid:200, fees:450},
  people{ 0:{name:'Snoopy', registrationType:'dancer'},
               1:{name:'Schroeder', registrationType:'musician'},
               1:{name:'Sally', registrationType:'youth'}
              }

I would like to show all this in a single editor but the number of people may be 1 or a large group. While everything else is straightforward, how do I set up an editor to show, and edit, the people? I am using Local Table Editing.

Answers

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921
    edited September 2019

    Typically for this type of situation I use a parent/child table as described in this blog:
    https://datatables.net/blog/2016-03-25

    The child table would be used to edit, add or remove the people. This solution works well on the client side. You likely will need to write custom code on the sever side to handle whether the people data is stored as a field in the same table with the other data or if its a separate table.

    This would allow for both selection and editing the people. How you handle it server side is dependent on your data structure and server code.

    Another option would be to use the select2 plugin to allow for choosing one or more people. You would need a separate page or Datatable for editing.

    There are probably other ways to do this. These are solutions I've used depending on what is needed.

    Kevin

  • Karl_SKarl_S Posts: 20Questions: 6Answers: 0

    Thank you, Kevin. While that would work, and I considered using it, I think I am going to use an example you used in the accepted answer to can datatables child row add another table? with the child row using a datatable as you provided an example of here: http://live.datatables.net/nabiyibo/1/edit as the end users seem to prefer this in my case.

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    Glad to have helped even in a round about way :-) So many options with Datatables!

    Kevin

This discussion has been closed.