I am trying to display the data datatables , Tapo there is a problem , please help , for another dicode datatables can run successfully , but in this code do not want the road ?
Uncaught TypeError: Cannot read property 'mData' of undefined
This JS
<script src="<?php echo base_url('assets/js/jquery.dataTables.min.js') ?>" type="text/javascript"></script>
<script src="<?php echo base_url('assets/js/dataTables.bootstrap.min.js') ?>" type="text/javascript"></script>
<script>
$(document).ready(function() {
$('#files').DataTable();
});
table class="table table-striped table-condensed" id="files">
<thead>
<tr>
<th>File Name</th>
<th>Upload By</th>
<th>Upload Date</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
foreach($files as $f => $file){
foreach($permission as $p => $key){
if($key['id_files'] == $file['file_id'] ||$this->user->is_teacher || $this->user->is_superadmin ){
echo '<tr>';
echo '<td>'.$file['file_name'].'</td>';
echo '<td>'.$file['upload_by'].'</td>';
echo '<td>'.date("d-M-Y",strtotime($file['upload_dt'])).'</td>';
echo '<td>';
if($this->user->is_teacher || $this->user->is_superadmin){
echo '<i class="fa fa-user"></i> Manage ';
echo '</td>';
echo '<td>';
echo '<i class="fa fa-times"></i> Delete ';
}
echo '</td>';
echo '</tr>';
}
}
}
?>
</tbody>
</table>
Related
can someone tell me what's wrong with my code? been stuck here for hours... it always says that "DataTables warning: table id=datatable - Requested unknown parameter '1' for row 0."
here's my code:
<table id="datatable" class="table table-bordered table-striped dataTable">
<thead>
<tr>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
<?php echo $this->session->flashdata('message'); ?>
<?php $offset = $this->uri->segment(3, 0) + 1; ?>
<?php foreach ($query->result() as $row): ?>
<tr>
<td><?php echo $row->manufacturer_name; ?></td>
<?php echo "<form method='post' action='asset_management/updateForm'>";?>
<input type="hidden" name="manufacturer_id" value="<?php echo $row->manufacturer_id;?>"/>
<?php echo form_open('asset_management/updateForm');
echo form_submit('p_submit', 'Update', "class='btn btn-warning btn-xs'"); ?>
<?php echo form_close(); ?>
</form>
<a class="btn btn-danger btn-xs" onclick="javascript:deleteConfirm('<?php echo site_url('asset_management/deletemanu/' . $row->manufacturer_id); ?>');" deleteConfirm href="#">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></th>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Thank you so much!
no. of table heading may not matches with no. of td in the table.
It shows the mentioned error.
visit https://www.datatables.net/
In my application, i have upload image and fill some fields. These values and upload image path also to be saved in database. I don't know to how to retrieve image from folder. My code is,
The Controller part is
function getdatatableajax()
{
$this->load->library('datatables');
$this->datatables
->select("products.id as id, pathinfo, products.name as pname, price, measurement, tax_rates.name")// measurement,tax_rates.name
->from("products")
->join('tax_rates', 'tax_rates.id=products.tax_rate', 'left')
->group_by('products.id')
->add_column("Actions",
"<center>
<div class='btn-group'>
<a class=\"tip btn btn-primary btn-xs\" title='".$this->lang->line("edit_product")."' href='index.php?module=products&view=edit&id=$1'>
<i class=\"fa fa-edit\"></i></a>
<a class=\"tip btn btn-danger btn-xs\" title='".$this->lang->line("delete_product")."' href='index.php?module=products&view=delete&id=$1' onClick=\"return confirm('". $this->lang->line('alert_x_product') ."')\">
<i class=\"fa fa-trash-o\"></i></a>
</div></center>", "id")
->unset_column('id');
echo $this->datatables->generate();
}
The model part is
public function getAllProducts()
{
$q = $this->db->get('products');
if($q->num_rows() > 0) {
foreach (($q->result()) as $row) {
$data[] = $row;
}
return $data;
}
}
The View part is
<table id="fileData" cellpadding=0 cellspacing=10 class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th><?php echo $this->lang->line("Image"); ?></th>
<th><?php echo $this->lang->line("name"); ?></th>
<th><?php echo $this->lang->line("price"); ?></th>
<th><?php echo $this->lang->line("Measurement"); ?></th>
<th><?php echo $this->lang->line("tax_rate"); ?></th>
<th style="width:45px;"><?php echo $this->lang->line("actions"); ?></th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7" class="dataTables_empty"><?php echo $this->lang->line('loading_data_from_server'); ?></td>
</tr>
</tbody>
<tfoot>
<tr>
<th><?php echo $this->lang->line("Image"); ?></th>
<th><?php echo $this->lang->line("name"); ?></th>
<th><?php echo $this->lang->line("price"); ?></th>
<th><?php echo $this->lang->line("Measurement"); ?></th>
<th><?php echo $this->lang->line("tax_rate"); ?></th>
<th style="width:45px;"><?php echo $this->lang->line("actions"); ?></th>
</tr>
</tfoot>
</table>
From where are add image retrieval code.?
Use This :-
<img src="<?php echo base_url('images/1.jpg'); ?>" />
Check this Post for more details
I have a foreach inside a table that loads a file with a row <tr>.
That problem is that all the variables come null and I've already tried to send the variable with the load as you can see in the next code line but no success:
$this->load->view('pedidos/tarefas/tarefa_table', $task);
This is my table:
<table>
<thead>
<tr>
<th>ID</th>
<th>Utilizador</th>
<th>Entidade</th>
<th>Descrição</th>
<th>Data Limite</th>
<th>Estado</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
<?php
foreach ($tasks as $task) {
$this->load->view('pedidos/tarefas/tarefa_table', $task);
}
?>
</tbody>
</table>
This is the file I'm including in the load->view:
tarefa_table.php
<tr class="odd gradeX">
<td><?php print_r($task->id); ?></td>
<td><?php echo substr($task->user->name, 0, 20); if(intval(strlen($task->user->name)>=20))echo ".."; ?></td>
<td><?php echo substr($task->entidade->name, 0, 20); if(intval(strlen($task->entidade->name)>=20))echo ".."; ?></td>
<td><?php echo substr($task->descricao, 0, 30); if(intval(strlen($task->descricao)>=30))echo ".."; ?></td>
<td style="<?php
if ($task->status_id <= 2 || $task->status_id >= 6) {
if (date('Y-m-d', strtotime($task->data_fim)) == date('Y-m-d')) {
echo "color: orange";
} elseif (date('Y-m-d', strtotime($task->data_fim)) < date('Y-m-d')) {
echo "color: red";
}else{
echo "color:#274156";
}
} ?>"><?php echo date('d-m-Y', strtotime($task->data_fim)) ?>
</td>
<td><?php
if($task->status_id <= 2 && date('Y-m-d', strtotime($task->data_fim)) < date('Y-m-d')){
echo "Atraso";
}else{
switch ($task->status_id) {
case 1: echo "Ativo"; break;
case 2: echo "Atraso"; break;
case 3: echo "Pendente"; break;
case 4: echo "Concluído"; break;
case 5: echo "Cancelado"; break;
case 6: echo "Ativo"; break;
case 7: echo "Atraso"; break;
default: echo "Não Definido"; break;
}}?>
</td>
<td class="center">
<a href="<?php echo base_url() . 'pedidos/view_task/' . $task->id ?>" title="Ver" class="tip">
<button class="btn btn-link btn-mini"><span class="icon16 icomoon-icon-eye"></button>
</a>
<a href="<?php echo base_url() . 'pedidos/edit_task/' . $task->id ?>" title="Editar" class="tip">
<button class="btn btn-link btn-mini"><span class="icon16 icomoon-icon-pencil-5"></button>
</a>
<!--<a href="<?php //echo base_url() . 'pedidos/deletetask/' . $task->id ?>" class="confirm-delete tip" title="Apagar">
<button class="btn btn-link btn-mini"><span class="icon16 typ-icon-trashcan red"></button>
</a>-->
</td>
</tr>
why not load a view in controller , loop through your data and append in your variable like
$tablecontent and just echo it in your first view
//controller
function your_fucntion(){
$tablecontent="";
foreach ($tasks as $task) {
$tablecontent.=$this->load->view('pedidos/tarefas/tarefa_table', $task,true);
}
$data['tablecontent']=$tablecontent;
$this->load->view('your view path', $data);
}
//view
<table>
<thead>
<tr>
<th>ID</th>
<th>Utilizador</th>
<th>Entidade</th>
<th>Descrição</th>
<th>Data Limite</th>
<th>Estado</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
<?php
echo $tablecontent;
?>
</tbody>
</table>
i have error when i update row to database.
my problem is not update the row and call me when i upload pic with update the file upload not define in index.
my controller :
public function addedit(){
$events = new events_model();
$prodID = $this->input->post('hID');
$text = $this->input->post('ev_text');
$pic = $this->do_upload('ev_pic');
$submit = $this->input->post('submit');
if($submit){
if(!empty($prodID)){
$this->data['events'] = $events->UpdatePost($prodID, $text , $pic );
$this->data['pagetitle'] = "Show Info";
$this->data['success']= "Update Done";
}else{
$this->data['success'] = "Add Done";
}
$this->data['status'] = "1";
}else{
$this->data['status'] = "0";
$this->data['errors'] = "Error";
}
$this->template->build('admin/events/add',$this->data);
}
and model :
function UpdatePost($prodID, $text , $pic ) {
if ($pic == ""){
$vales = array('ev_id' => $prodID , 'ev_text' => $text);
}else{
$vales = array('ev_id' => $prodID , 'ev_text' => $text , 'ev_pic' => $pic);
}
$query = $this->db->update($this->table_name, $vales) or die (mysql_error());
$result = array();
$result["process"] = "ok";
echo "1";
}
and view :
<div class="widget-body">
<table class="data-table" action="./administrator/categories/delete/"><!-- Table Conversion: See Section E in custom.js -->
<thead>
<tr>
<th class="sorting no-background" rowspan="1" colspan="1" style="width: 35px;"><input type="checkbox" id="checkall" /></th>
<th class="sorting" rowspan="1" colspan="1" style="width: 343px;">Tittle</th>
<th class="sorting" rowspan="1" colspan="1" style="width: 100px;">Date</th>
<th class="sorting no-background" rowspan="1" colspan="1" style="width: 70px;">#</th>
</tr>
</thead>
<tbody>
<?php $ctr = 0; ?>
<?php foreach ($events as $n): ?>
<tr>
<td><input class="checkrow" type="checkbox" value="<?php echo $n->ev_id; ?>" /></td>
<td class=" sorting_1"><?= $n->ev_text; ?></td>
<td class="center"><?= $n->ev_date; ?></td>
<td>
<span>Edit</span>
<span>Del</span>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
<div id="table-extra">
<div id="table-action">
<input action="./administrator/<?php echo $this->uri->segment(2)."/deleteitems" ?>" class="btn-theme table-button btn-hover-black DeleteItems" id="submit" type="button" value="Delete" />
</div>
<div class="paginate">
<ul>
<?= $this->pagination->create_links(); ?>
</ul>
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
where problem in my code , and i wont to update success.
you don't load models like this $events = new events_model(); in CI, you should do it like this :
$this->load->model('Model_name');
$this->Model_name->function();
ref : http://ellislab.com/codeigniter/user-guide/general/models.html#loading
I am trying to fetch data from my database and when I display it I want to show serial numbers (Just like a list) , example:
**Serial Number** Name Country
1. John USA
2. Srijon UK
I have tried something with PHP Loops, but I couldn't make it work. Would you please kindly help me? please note that by serial numbers I don't mean values retrieved from database.
Thanks in Advance :)
Here's my Model
//Function To Create All Batch List
function batch_list($perPage,$uri) {
$this->db->select('*');
$this->db->from('batch');
$this->db->join('teacher', 'batch.batchinstructor = teacher.teacherid');
$this->db->order_by('batchid','DESC');
$getData = $this->db->get('', $perPage, $uri);
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
//End of Function To Create All Batch List
Here's mY Controller
function index(){
$this->load->library('pagination');
$config['base_url'] = base_url().'batchlist/index';
$config['total_rows'] = $this->db->get('batch')->num_rows();
$config['per_page'] = 20;
$config['num_links'] = 20;
$config['full_tag_open'] = '<div class="pagination" align="center">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$this->load->model('mod_batchlist');
$data['records']= $this->mod_batchlist->batch_list($config['per_page']
,$this->uri->segment(3));
$data['main_content']='view_batchlist';
$this->load->view('includes/template',$data);
}
Here's My View
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>Batch Name</th>
<th>Class</th>
<th>Batch Instructor</th>
<th>Edit/Delete</th>
</tr>
</thead>
<tbody>
<?php foreach ($records as $row){ ?>
<tr>
<td><?php echo $row['batchname'];?> </td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <img src="<?php echo base_url(); ?> support/images/icons/edit.png" alt="Edit" />
<img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" />
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
<?php if(count($records) > 0) { ?>
<table id="table1" class="gtable sortable">
<thead>
<tr>
<th>Serial</th>
<th>Batch Name</th>
<th>Class</th>
<th>Batch Instructor</th>
<th>Edit/Delete</th>
</tr>
</thead>
<tbody>
<?php $i = $this->uri->segment(3); foreach ($records as $row){ $i++; ?>
<tr>
<td><?php echo $i; ?>.</td>
<td><?php echo $row['batchname'];?> </td>
<td><?php echo $row['class'];?></td>
<td><?php echo $row['teachername'];?></td>
<td> <img src="<?php echo base_url(); ?> support/images/icons/edit.png" alt="Edit" />
<img src="<?php echo base_url(); ?>support/images/icons/cross.png" alt="Delete" />
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
<div class="tablefooter clearfix">
<div class="pagination">
<?php echo $this->pagination->create_links(); ?>
</div>
</div>
In my case the fourth and fifth parameters where page number and rows per page respectively
ie: example.com/category/page/1/10
first page with 10 rows per page.
so in this case just use this before the loop
$i = $this->uri->segment(4)? (
$this->uri->segment(4) + $this->uri->segment(5)? $this->uri->segment(5):0
)
:0;
and from inside the loop just increment the value of i.
foreach ($result_obj as $key => $value)
{
$i++;
...
}
Try this..work like this..1,2,3,4,5
$i = 0
while($condition)
{
echo '<td>'.$i++.'</td>';
}