Welcome Guest, Not a member yet? Register   Sign In
Populate table with selected dropdown
#1

Hey guys i'm new and i need how to populate a table using a select dropdown.


I know how populate a table.

PHP Code:
<select class="form-control">

                <option></option>
                <option>02/07/2015</option>
                <option>05/08/2015</option>
                <option>05/08/2015</option>
                <option>05/08/2015</option>
            </select>

            <table class="table table-hover tabela" data-toggle="table">
                <thead>
                    <tr>
                        <th data-field="Chamada">Chamada</th>
                        <th data-field="Duração">Duração</th>
                        <th data-field="Visualizar">Visualização</th>
                    </tr>
                </thead>
                <?php foreach ($historicos as $historico) { ?>
                    <tbody>
                        <tr>
                            <td>
                                <?php echo $historico->data_chamada?>
                            </td>
                            <td>
                                <?php echo $historico->duracao_chamada?>
                            </td>
                            <td>
                                <button class="btn btn-primary" name="vizualizar" value="<?php echo $historico->codigo ?>" data-book-id="<?php echo $historico->codigo ?>" data-target="#form-modal" data-toggle="modal">Visualizar</button>
                            </td>
                        </tr>
                    </tbody>
                    <?php ?>
            </table> 
I need fill dropdown and on change populate table.
Reply
#2

CI has a form helper. Load it with $this->load->helper('form').
Make an array of the "options" you want in the dropdown, like so:

PHP Code:
$dates = array(
  '' => '(select a date)',
  '07/02/2015' => '07/02/2015',
  '05/08/2015' => '05/08/2015',
  '06/08/2015' => '06/08/2015'
);

echo 
form_dropdown('selectdate',$dates,NULL,'id="selectdate"'); 
Then, after the closing php tag, put the following script:
Code:
<script>

$(document).ready(function(){
  $('#selectdate').change(function(){
    newdate = $(this).val();
    document.location = "<?= base_url();?>yourcontroller/yourmethod/"+newdate;
  });
});

</script>

The script requires Jquery, so load that first.
Reply
#3

Works!! Ty!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB