Edición de «Datagrid Simple y jquery»
De KumbiaPHP Framework Wiki
Advertencia: no has iniciado sesión. Tu dirección IP se hará pública si haces cualquier edición. Si inicias sesión o creas una cuenta, tus ediciones se atribuirán a tu nombre de usuario, además de otros beneficios.
Puedes deshacer la edición. Antes de deshacer la edición, comprueba la siguiente comparación para verificar que realmente es lo que quieres hacer, y entonces guarda los cambios para así efectuar la reversión.
Revisión actual | Tu texto | ||
Línea 1: | Línea 1: | ||
− | + | Partials para crear de forma simple un datagrid con php y algo de jquery | |
=== En el controlador === | === En el controlador === | ||
− | + | ||
<source lang="php"> | <source lang="php"> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
// Se maneja todo desde la vista | // Se maneja todo desde la vista | ||
</source> | </source> | ||
Línea 27: | Línea 9: | ||
=== En la vista === | === En la vista === | ||
− | |||
<source lang="php"> | <source lang="php"> | ||
− | + | View::partial('datagrid/ajax', //nombre del partial | |
+ | false, | ||
+ | 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 35: | Línea 25: | ||
/app/view/partials/datagrid/ajax.phtml | /app/view/partials/datagrid/ajax.phtml | ||
+ | |||
+ | |||
<source lang="php"> | <source lang="php"> | ||
− | + | ||
− | + | <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" /> | |
− | <table border="1px | + | <?php |
− | <thead><tr> | + | |
− | + | ||
− | <th> | + | echo "<div id=\"datagrid\">"; |
− | + | echo "<table border=\"1px\" class=\"ajax\">"; | |
− | </tr></thead> | + | echo "<thead><tr>"; |
− | + | foreach( $Campos as $titulo => $valor): | |
− | + | echo "<th>" . $titulo . "</th>"; | |
− | + | endforeach; | |
− | + | echo "</tr></thead><tbody>"; | |
− | <td> | + | foreach( $Modelo as $model): |
− | + | echo tr_color_class( 'tr_primary', 'tr_secondary' ); | |
− | </tr> | + | foreach($Campos as $campos): |
− | + | echo "<td>". $model->$campos . "</td>"; | |
− | </tbody></table> | + | endforeach; |
− | + | echo "</tr>"; | |
+ | endforeach; | ||
+ | echo "</tbody></table></div>"; | ||
+ | ?> | ||
+ | |||
<script> | <script> | ||
− | $(function() { | + | $(document).ready(function() { |
− | $('# | + | $('#datagrid').dataTable(); |
} ); | } ); | ||
Línea 68: | Línea 64: | ||
''la pagina del autor del script para jquery es http://www.datatables.net/'' | ''la pagina del autor del script para jquery es http://www.datatables.net/'' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |