How to create a dropdown list with the option from phpmyadmin in the datatables editable column

How to create a dropdown list with the option from phpmyadmin in the datatables editable column

AAWafiyAAWafiy Posts: 3Questions: 1Answers: 0

Hi, I am currently working on a search function that fetch the data and show it in a table that i created using datatables.net template. From the edit option and i would like to create a dropdown list that fetch the data from a table in the database and show it as an option in the datatable editable column.

The current javascript is as below : -

<script type="text/javascript" language="javascript" >
$(document).ready(function(){

 var dataTable = $('#sample_data').DataTable({
  "processing" : true,
  "serverSide" : true,
  "order" : [],
  "ajax" : {
   url:"fetch.php",
   type:"POST"
  }
 });

 $('#sample_data').on('draw.dt', function(){
  $('#sample_data').Tabledit({
   url:'action.php',
   dataType:'json',
   columns:{
    identifier : [0, 'serial_number'],
    editable:[[1, 'asset_number'], [2, 'category', '{"1":"Male","2":"Female"}'], [3, 'brand'],[4, 'model'], [5, 'year'], [6, 'price'],[7, 'status'], [8, 'vendor'], [9, 'invoice_no'],
   [10, 'DO_no'], [11, 'memo_no'], [12, 'PO_no'],[13, 'User_now'], [14, 'user'], [15, 'department']]
    
    
   },
   restoreButton:false,
   onSuccess:function(data, textStatus, jqXHR)
   {
    if(data.action == 'delete')
    {
     $('#' + data.id).remove();
     $('#sample_data').DataTable().ajax.reload();
    }
   }
  });
 });
  
}); 
</script>

from the code above it only can display a dropdown list that is typed in such as : -

[2, 'category', '{"1":"Male","2":"Female"}']

I would want to fetch data from table in the database and show it in a drop down list

I have created a php code to fetch data from table in database as an example : -

<select id="category" name="category">
  <option disabled selected>-- Select Category --</option>
       
      <?php
          
             $records = mysqli_query($link, "SELECT DISTINCT ID,type From category");  // Use select query here 

              while($data = mysqli_fetch_array($records))
                   {
           echo "<option value = '$data[ID]'>".$data[ID]."-".$data[type]."</option>"; // displaying data in option menu
                   }   
          ?>  
           
     </select>

Hope you guys can help me. Thank you in advance

Answers

This discussion has been closed.