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->opciones = array('Modelo' => Load::model('usuarios')->find(), // Paso el modelo que voy a utilizar |
+ | 'Campos' => array('Codigo' => 'id',// paso un array con los campos que quiero mostrar | ||
+ | 'Nombre' => 'nombre', | ||
+ | 'Telefono' => 'telefono', | ||
+ | 'Direccion' => 'direccion')) | ||
</source> | </source> | ||
Línea 10: | Línea 14: | ||
=== En la vista === | === En la vista === | ||
<source lang="php"> | <source lang="php"> | ||
− | View::partial('datagrid/ajax', | + | View::partial('datagrid/ajax',false, $opciones ) |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Revisión del 22:43 20 ago 2009
Partials para crear de forma simple un datagrid con php y algo de jquery
En el controlador
$this->opciones = array('Modelo' => Load::model('usuarios')->find(), // Paso el modelo que voy a utilizar
'Campos' => array('Codigo' => 'id',// paso un array con los campos que quiero mostrar
'Nombre' => 'nombre',
'Telefono' => 'telefono',
'Direccion' => 'direccion'))
En la vista
View::partial('datagrid/ajax',false, $opciones )
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" />
<?php
echo "<div id=\"datagrid\">";
echo "<table border=\"1px\" class=\"ajax\">";
echo "<thead><tr>";
foreach( $Campos as $titulo => $valor):
echo "<th>" . $titulo . "</th>";
endforeach;
echo "</tr></thead><tbody>";
foreach( $Modelo as $model):
echo tr_color_class( 'tr_primary', 'tr_secondary' );
foreach($Campos as $campos):
echo "<td>". $model->$campos . "</td>";
endforeach;
echo "</tr>";
endforeach;
echo "</tbody></table></div>";
?>
<script>
$(document).ready(function() {
$('#datagrid').dataTable();
} );
</script>
la pagina del autor del script para jquery es http://www.datatables.net/