Select input with options provided from database

Select input with options provided from database

willcodewillcode Posts: 4Questions: 4Answers: 0
edited February 2019 in Free community support

Hello there!
I'm creating opne PHP system, currently i'm using datatables (not the editor) to create my tables.
To add, edit and delete content, i'm using ajax request and making it "by hand". I'm testing the editor to make my development faster...
Some of my fields are <select> and his options often was retrieved from database.

This is an example of my current select:

<select id="slEstado" name="slEstado" class="form-control form-control form-control-sm input-sm selectpicker" required="" data-show-subtext="true" data-live-search="true" tabindex="-98">
<option value="">Selecione...</option><option value="AC">AC - Acre </option>
<option value="AL">AL - Alagoas </option>
<option value="AP">AP - Amapá </option>
<option value="AM">AM - Amazonas </option>
<option value="BA">BA - Bahia </option>
<option value="CE">CE - Ceará </option>
<option value="DF">DF - Distrito Federal </option>
<option value="ES">ES - Espírito Santo </option>
<option value="GO">GO - Goiás </option>
<option value="MA">MA - Maranhão </option>
<option value="MT">MT - Mato Grosso </option>
<option value="MS">MS - Mato Grosso do Sul </option>
<option value="MG">MG - Minas Gerais </option>
<option value="PA">PA - Pará </option>
<option value="PB">PB - Paraíba </option>
<option value="PR">PR - Paraná </option>
<option value="PE">PE - Pernambuco </option>
<option value="PI">PI - Piauí </option>
<option value="RJ">RJ - Rio de Janeiro </option>
<option value="RN">RN - Rio Grande do Norte </option>
<option value="RS">RS - Rio Grande do Sul </option>
<option value="RO">RO - Rondônia </option>
<option value="RR">RR - Roraima </option>
<option value="SC">SC - Santa Catarina </option>
<option value="SP">SP - São Paulo </option>
<option value="SE">SE - Sergipe </option>
<option value="TO">TO - Tocantins </option>
</select>

In datatables editor, i need to make same thing. Get the options from database and show it like that, option description with more details and the value that will be stored in DB it's the option value.

Has anyway to do it?

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Do you mean you need to be able to read multiple fields from the table for the label of the option? If so, then yes, that is possible (from the same table) - the Options->label() method can be used with an array of fields to get.

    The one thing that is missing from Editor here at the moment is the ability to do a left join to get the information from another table. That might or might not be an issue depending on your schema.

    Allan

This discussion has been closed.