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"> | ||
Línea 41: | Línea 33: | ||
<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"> | + | <?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): | |
− | <td> | + | echo "<td>". $model->$campos . "</td>"; |
− | + | endforeach; | |
− | + | echo "</tr>"; | |
− | + | endforeach; | |
− | + | echo "</tbody></table></div>"; | |
− | + | ?> | |
+ | |||
<script> | <script> | ||
− | $(function() { | + | $(document).ready(function() { |
− | $('# | + | $('#datagrid').dataTable(); |
} ); | } ); | ||
Línea 68: | Línea 61: | ||
''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/'' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |