How to dynamically populate iopts

How to dynamically populate iopts

lukeogormanlukeogorman Posts: 2Questions: 1Answers: 1
edited January 2016 in Free community support

Hi,
I have an editable datatable which contains a role column, the role column is to be populated by a drop down list. Different rows need to have different contents in the drop down list. So I want to click on the role cell for a column and trigger a call to my function
getRole() which then returns the particular drop down list for this row. I tried the snippit below however it only gets called on page load. Anyone have any examples of something like this?

   var editor = new $.fn.dataTable.Editor( {
            ajax: requestURL,
            table: "#example",
            idSrc:  'table',
          fields: [
         { label: role,  name: "role" , type: "select",   "ipOpts":getRole() }
    ]
    
    
    function getRole() {
   var rolesArray = $.ajax({
    dataType: "json",
    url: 'ajaxUrl',
    success: function ( json ) {
      editor.field( 'role' ).update( json );
    }
});
}

This question has accepted answers - jump to:

Answers

  • lukeogormanlukeogorman Posts: 2Questions: 1Answers: 1
    Answer ✓

    Here is how to call the getRole function on cell click to dynamically populate the dropdown list

    '''
    $( 'select', editor.node( 'role' )).on( 'change', function () {
    editor.field ('role').update(getRole());
    } );
    '''

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    edited January 2016 Answer ✓

    The select field type has an update() method which you can call using editor.field( '...' ).update( ... );. That will update the options in the select list. See the select reference documentation for details and examples.

    Allan

    edit I see you've basically answered your own question as well :-)

This discussion has been closed.