Nested Editing - Where is the data loaded from?

Nested Editing - Where is the data loaded from?

jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1
edited January 22 in Editor

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

I currently have two editor instances that work fine. The second editor uses the results of the first as a "select". In order to cut down on the number of editors/screens/modals/popups, I'm looking to use nested to get rid of the need for the separation.

While I have this "working" - specifically, the datatable appears, the editor is populated, the nested table is populated, and editing / new inserts works. However, when loading the page I get the generic:

Requested unknown parameter 'value' for row 0, column 0

The section of code that generates the error seems to be the column definition for the nesting:

columns: [
                    {
                        title: 'Id',
                        data:  'value'
                    },
                    {
                        title: 'Name',
                        data: 'label'
                    }
                    ]

In the ajax of both the standalone editor, as well as the ajax for the nested (same destination), data is returned as id and name. However, when configuring the nest, I had to use value and label.

I'm unsure why, and that's the root of my question.

Where does the data come from that triggers this process? It can't be the ajax call itself, so it must be from the parent table/join? Something is changing the key/value pairs, triggering this required change, and I assume these errors, but I can't seem to nail down where and why.

I'm going to try to put together an example, but I have a feeling (looking at the example data on this website), I wont be able to reproduce it.

This question has an accepted answers - jump to answer

Answers

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    It looks like the data for the nest is pulled from the parent table request, including all join data, which is transformed to the different format (using field Options()).

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

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

    Using the above as another example, I removed the ajax and buttons configuration on my config, and the errors went away.

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    Requested unknown parameter 'value' for row 0, column 0

    The key part in the nested example for this point is:

                optionsPair: {
                    value: 'id'
                },
    

    You need to tell Editor where to take the value of the field from in the data populating the table. In the nested example that is the id property. You might use something else. The Options will use a value / label pair, which the field expects by default. So when using nested editing, you will very likely want to set the optionsPair.value property.

    Allan

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    And ... of course you're right. I had it in use before, but commented it out because I continue to get errors (for other reasons that since were fixed).

    Thank you for the answer!

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    Spoke too soon, on submit of a new record (of the nest):
    Requested unknown parameter 'label' for row 5, column 0.

    Going to dig into that next :D

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    That suggests that the data being returned from a create action (possibly edit as well) is in a different format from what is initialise loaded as the data / options for the table field.

    Allan

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    And that more or less defines my initial question and my confusion. The table is standard id/name, it's transformed to value/label by datatables in Options, to support select lists, and it has to be transformed back for submission.

    On these tables, I'm likely going to just rename the backend database to be value/label, instead, in hope that addresses the fundamental problem.

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    I'm guessing the core issue might be here:

                new Field( 'table.field_id').options(
                    new Options().table('field').value('id').label('name')
                    )
                    .validator(Validate.dbValues())
                    .validator(Validate.notEmpty()),
    

    Is there any chance the php for the nested example could be added to its page? I'm guessing there isn't a translation of data like this for it, considering the results when interrogating the php itself.

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    Actually, that was exactly the issue. After removing the options altogether, all of the errors/problems went away, and the nested example works in my setup.

    The above was definitely causing DT some grief when trying to parse the data.

  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    Trying to figure out how to add validation back in, but minus the validation, it looks real good.

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
  • jacob.steinbergerjacob.steinberger Posts: 86Questions: 18Answers: 1

    Yes and no - previously the validator was defined by Options

    new Options().table('table').value('id').label('name')
    

    This was throwing off the nested feature, so I had to remove it. Then I just had to figure out how to define these things within the dbValues() call, instead of having it defined in options:

                new Field( 'parent_table.id')
                    .validator(Validate.notEmpty())
                    .validator(Validate.dbValues(null, 'id','child_table')),
    

    I think it's all working, including field validation now. Thanks for listening to the ramblings of a user.

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Awesome - good to hear that you've got it working.

    Allan

Sign In or Register to comment.