Select2 with parent/child tables

Select2 with parent/child tables

kthorngrenkthorngren Posts: 21,563Questions: 26Answers: 4,995

I have parent/child tables working using the example:
https://datatables.net/examples/advanced_init/column_render.html

But Select2 complicates things a bit. The first issue is inline editing a multi-select select2 field. Once I click inside the field the select handler is called. I added a check to validate the data object exits in the handler:

    table.on( 'select', function () {
        sort_table.ajax.reload();
        if (table.row( { selected: true } ).data()) {  //if data() does not exist then editing a select2 field
            $('.cmd').text(table.row( { selected: true } ).data().main.name + ' Commands');
            sort_editor
                .field( 'DT_RowId' )
                .def( table.row( { selected: true } ).data().main.pkid );
            }
    } );

Not sure if this is the best method but it works. I'm running into another issue which I haven't solved yet and looking for some pointers. I'm selecting theparent row with the first column checkbox.

        select: {
            style: 'single',
            selector: 'td:first-child'
        },

Problem desc: I select a row and the child table is loaded. While selected I edit the multi-select select2 field and click another column in the selected row to complete the edits. The update for that field is sent to the server and all is good. But the child table is not triggered to update. I can reselect that row and it displays properly. Is there a way I can trigger an update of the child table?

The also happens if I use the Editor window instead of inline editing.

Kevin

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,563Questions: 26Answers: 4,995

    I found that the behavior is different than described above. I will post back with the results of further testing. Please disregard the question for now.

    Kevin

  • kthorngrenkthorngren Posts: 21,563Questions: 26Answers: 4,995

    Everything is actually working correctly, I think. I'm not clear on why some of the columns trigger the select handler and others don't. If I can't figure it out I will post a test case.

    Kevin

  • kthorngrenkthorngren Posts: 21,563Questions: 26Answers: 4,995
    Answer ✓

    Found the source of my confusion. Didn't scroll all the way down the blog to learn about submitSuccess to update the tables at the right times.

    Kevin

  • allanallan Posts: 63,839Questions: 1Answers: 10,518 Site admin

    Awesome - thanks for posting back. Great to hear you've got it sorted out.

    And thanks for your sterling work in the other threads as well! You are a proper DataTables pro :smile:.

    Allan

  • kthorngrenkthorngren Posts: 21,563Questions: 26Answers: 4,995

    Thanks! Don't know about the pro part but helping out does further my DT and JS skills. Also introduces me to new features that enhance my projects.

    Kevin

This discussion has been closed.