I have a problem with my code.
I am currently loading my list of accounts through a database and generating a table with Codeigniters library, table.
$this->load->library('table');
$this->db->select('firstname, lastname, accountname, registerdate, birthdate, email');
$this->db->from('accounts');
$query = $this->db->get();
$template = array('table_open' => '<table class="table table-striped table-hover">');
$headings = array( 'Fornavn', 'Efternavn', 'Brugernavn', 'Registeringsdato', 'Fødselsdag', 'Email');
$this->table->set_template($template);
$this->table->set_heading($headings);
return $this->table->generate($query);
I would like a modal to open when clicking on the table row. My only headtwister is how I pass any data, like userid, to the modal opened? I can change the table template to open a modal but I cannot figure out how to pass the data. Since the data should be an id which changes from row to row, if you catch my drift.
I hope theres some smart brain out there who can help me!
Best regards
OrKarstoft
2
Answers
Initialize some
id
for'table-open'
. Then use jQuery on view side, when table is ready to insert attribute. Try this://controller
//view
You will need to do this in the view with javascript!
Basic concept:
data-
tags on the<tr>
‘s or DOM traversal to collect the row’s data that you want to send to the modal.I put together a jsFiddle for you to illustrate all the parts. Working Example
To add the extra tags into your rows using the codeigniter table library, you are going to have to change the way you generate the table a little bit.
Codeigniter add_row() Documentation