Multiple endpoints in dependent() method

Multiple endpoints in dependent() method

scturnbullscturnbull Posts: 2Questions: 1Answers: 0
edited February 2022 in Editor

Hi All,

I'm new to DataTables/Editor so apologies if I'm asking the obvious however, I cannot see any examples where different endpoints are called dependent on the value of a dropdown. All I've seen to date are the following examples.

editor.dependent( 'options', function ( val ) {
        return val === 'Simple' ?
            { hide: ['position', 'office', 'extn', 'start_date', 'salary'] } :
            { show: ['position', 'office', 'extn', 'start_date', 'salary'] };
    } );

editor.dependent( 'continent', '/api/countries' );

Therefore, is it possible? I’ve tried adding a case statement and returning a string but to no avail.

This question has an accepted answers - jump to answer

Answers

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

    Yes - you'd need to use a function (e.g. the first of the two examples you posted) and in there do a conditional check on the value and then make the corresponding Ajax request - e.g.:

    editor.dependent( 'options', function ( val, data, callback ) {
      if (val === '1') {
        $.ajax( ... );
      }
      else {
        $.ajax( ... );
      }
    } );
    

    In the success callback for each Ajax call, make sure you call the callback() function with the data you want to update, as described in dependent().

    Allan

  • scturnbullscturnbull Posts: 2Questions: 1Answers: 0

    Thanks Allan, Works like a charm!

Sign In or Register to comment.