Diferencia entre revisiones de «Datagrid Simple y jquery»
De KumbiaPHP Framework Wiki
Línea 4: | Línea 4: | ||
<source lang="php"> | <source lang="php"> | ||
− | $this-> | + | <?php |
− | + | class ClienteController extends ApplicationController { | |
− | + | ||
− | + | public function page(){ | |
− | + | // Paso el resultado de la consulta que sera mostrada en el datagrid | |
+ | $this->result = Load::model('cliente')->find(); | ||
+ | |||
+ | /* paso un array con los campos que quiero mostrar en la datagrid | ||
+ | * El key de cada campo del ser el nombre a mostrarse en el tr de la tabla | ||
+ | * El value el campo de la tabla | ||
+ | */ | ||
+ | $this->campos = array('Codigo' => 'id', | ||
+ | 'Nombre' => 'nombre', | ||
+ | 'Telefono' => 'telefono', | ||
+ | 'Direccion' => 'direccion')); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | // Se maneja todo desde la vista | ||
</source> | </source> | ||
− | + | /app/view/cliente/page.phtml | |
=== En la vista === | === En la vista === | ||
<source lang="php"> | <source lang="php"> | ||
− | View::partial('datagrid/ajax', | + | View::partial('datagrid/ajax'false,array('Model'=>$result, 'Campos'=>$campos)); |
− | |||
− | |||
</source> | </source> | ||
Línea 22: | Línea 34: | ||
/app/view/partials/datagrid/ajax.phtml | /app/view/partials/datagrid/ajax.phtml | ||
− | |||
− | |||
<source lang="php"> | <source lang="php"> | ||
Línea 30: | Línea 40: | ||
<link type="text/css" rel="stylesheet" href="http://www.datatables.net/release-datatables/media/css/demo_page.css" /> | <link type="text/css" rel="stylesheet" href="http://www.datatables.net/release-datatables/media/css/demo_page.css" /> | ||
<link type="text/css" rel="stylesheet" href="http://www.datatables.net/release-datatables/media/css/demo_table.css" /> | <link type="text/css" rel="stylesheet" href="http://www.datatables.net/release-datatables/media/css/demo_table.css" /> | ||
− | + | <div id="datagrid"> | |
− | + | <table border="1px" class="simple">" | |
− | + | <thead><tr> | |
− | + | <?php foreach( $Campos as $titulo => $valor): ?> | |
− | + | <th> <?php echo $titulo >?</th> | |
− | + | <?php endforeach; ?> | |
− | + | </tr></thead> | |
− | + | <tbody> | |
− | + | <?php foreach( $Model as $model): | |
− | + | echo tr_color_class( 'tr_primary', 'tr_secondary' ); | |
− | + | foreach($Campos as $campos): ?> | |
− | + | <td><?php echo $model->$campos ?></td> | |
− | endforeach; | + | <?php endforeach; ?> |
− | + | </tr> | |
− | + | <?php endforeach; ?> | |
− | + | </tbody></table> | |
− | + | </div> | |
− | |||
<script> | <script> | ||
$(document).ready(function() { | $(document).ready(function() { |
Revisión del 00:22 21 ago 2009
Partials para crear de forma simple un datagrid con php y algo de jquery
En el controlador
<?php
class ClienteController extends ApplicationController {
public function page(){
// Paso el resultado de la consulta que sera mostrada en el datagrid
$this->result = Load::model('cliente')->find();
/* paso un array con los campos que quiero mostrar en la datagrid
* El key de cada campo del ser el nombre a mostrarse en el tr de la tabla
* El value el campo de la tabla
*/
$this->campos = array('Codigo' => 'id',
'Nombre' => 'nombre',
'Telefono' => 'telefono',
'Direccion' => 'direccion'));
}
}
// Se maneja todo desde la vista
/app/view/cliente/page.phtml
En la vista
View::partial('datagrid/ajax'false,array('Model'=>$result, 'Campos'=>$campos));
Partials
/app/view/partials/datagrid/ajax.phtml
<script type="text/javascript" src="http://www.datatables.net/release-datatables/media/js/jquery.js"></script>
<script type="text/javascript" src="http://www.datatables.net/release-datatables/media/js/jquery.dataTables.js"></script>
<link type="text/css" rel="stylesheet" href="http://www.datatables.net/release-datatables/media/css/demo_page.css" />
<link type="text/css" rel="stylesheet" href="http://www.datatables.net/release-datatables/media/css/demo_table.css" />
<div id="datagrid">
<table border="1px" class="simple">"
<thead><tr>
<?php foreach( $Campos as $titulo => $valor): ?>
<th> <?php echo $titulo >?</th>
<?php endforeach; ?>
</tr></thead>
<tbody>
<?php foreach( $Model as $model):
echo tr_color_class( 'tr_primary', 'tr_secondary' );
foreach($Campos as $campos): ?>
<td><?php echo $model->$campos ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody></table>
</div>
<script>
$(document).ready(function() {
$('#datagrid').dataTable();
} );
</script>
la pagina del autor del script para jquery es http://www.datatables.net/