Two column dropdown

Two column dropdown

GMGrayingGMGraying Posts: 12Questions: 6Answers: 1

There are no complete examples showing how to have one Select column that drives the data that will be shown in the next Select column. I have looked at the Unique() documentation, however, being new at this, I have no idea how to use it or where to even put it in the code. I can do this with php and SQL but with a lot more code, so I would prefer to use datatables editor, but I have spent days and days trying to figure it out with no luck. I've seen this question numerous times in the forum, however, no one has ever provided a complete answer or example of how to do it.

Answers

  • allanallan Posts: 63,352Questions: 1Answers: 10,443 Site admin

    What you can do is use the dependent() method - attach that to the parent select and instruct it to make an Ajax request to the server to get the list of options when called (which you do simply by giving it the URL to make the Ajax request to):

    editor.dependent( 'myField', '/api/secondFieldOptions' );
    

    Then you need your script at the server-side (/api/secondFieldOptions in the above) to respond with JSON that will give the options for the second field:

    {
      "options": {
        "secondField": [
          { "label": "1", "value: "1" },
          ...
        ]
      }
    }
    

    Regards,
    Allan

  • GMGrayingGMGraying Posts: 12Questions: 6Answers: 1

    Let me try this and get back to you. Thank you for your response.

  • GMGrayingGMGraying Posts: 12Questions: 6Answers: 1

    Thank you for the response, however, my values would be coming from the database so, I still don't understand listing them as indicated. Since I'm new, would it just be better for me to pay for the support?

  • allanallan Posts: 63,352Questions: 1Answers: 10,443 Site admin

    I could certainly put an example together for you under the support option if you like.

    What do you have the server returning at the moment for the request to get the values?

    Allan

This discussion has been closed.