How to dynamically populate iopts
How to dynamically populate iopts
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
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());
} );
'''
The
selectfield type has anupdate()method which you can call usingeditor.field( '...' ).update( ... );. That will update the options in the select list. See theselectreference documentation for details and examples.Allan
edit I see you've basically answered your own question as well :-)