Populate Option list in Editor Form

Populate Option list in Editor Form

mm789000mm789000 Posts: 25Questions: 2Answers: 0

Hi,

I want to populate an option list in Editor form with a query base on row data field.

How can i do ?

Regards

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Just to confirm my understanding - you want to change the options of a select input based on another value in the row? The dependent() method will help you with that. Have a look at this blog post which discusses this sort of thing.

    Allan

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    Just read the options from the server using a suitable event handler. I would use the "init" event handler: At that time you will have your row data available.

    Then on "open" of your Editor you can populate the options of your field using
    this: https://editor.datatables.net/reference/api/field().update()

    Alternatively you can read the options only when opening the Editor. Here is an example from my coding. It doesn't use "field().update()" because that doesn't work with a selectize field. Hence I clear the field and reinsert it into Editor with the options loaded from the server.

    editor
        .on ( 'initEdit', function ( e ) {
            $.ajax({
                type: "POST",
                url: 'actions.php?action=getCtrGovdeptOptions',
                data: {
                    ctr_id: table.row({selected: true}).data().ctr.id;
                },
                dataType: "json",
                success: function (opts) {   
                    editor.clear( "ctr_govdept[].id" ); 
                    editor.add( {
                        label: 'Department selection',
                        name: "ctr_govdept[].id", 
                        type: "selectize",
                        options: opts,
                        opts: {
                            create: false,
                            maxItems: null,
                            openOnFocus: true,
                            allowEmptyOption: false,
                        }
                    }, "ctr.ctr_partner" );
                }
            });
    
  • mm789000mm789000 Posts: 25Questions: 2Answers: 0

    Thanks !

Sign In or Register to comment.