Single Editor for two different DataTables on same page

Single Editor for two different DataTables on same page

Loren MaxwellLoren Maxwell Posts: 406Questions: 99Answers: 10

I have two DataTables on the same page that query the same MySQL database table on the backend (they are just filtered differently, such as "Employees in North America" and "Employees in Europe").

Is it possible to use the same Editor for both DataTables?

This question has an accepted answers - jump to answer

Answers

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

    Currently no - sorry. There can be multiple Editor instances for a single DataTable, but currently not multiple tables for a single Editor instance. You'd need to make two Editor instances.

    Allan

  • Loren MaxwellLoren Maxwell Posts: 406Questions: 99Answers: 10
    edited October 1

    Thanks, @allan.

    Based on that, here's my solution in case anyone else is looking for something similar:

    // Specify everything except the table
    const editor_config = {
       blah blah blah
    }
    
    // Create an instance for each table
    new DataTable.Editor(
        $.extend(
            editor_config,
            {table: '#employees-from-north-america'}
        )
    )
    new DataTable.Editor(
        $.extend(
            editor_config,
            {table: '#employees-from-europe'}
        )
    )
    

    This allows me to update editor_config only once and the changes are reflected in both editor instances.

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

    Perfect!

    Thanks for sharing that with us.

    Allan

Sign In or Register to comment.