Foros del Web » Programando para Internet » Jquery »

html datatables

Estas en el tema de html datatables en el foro de Jquery en Foros del Web. hola gente, estoy teniendo un problemilla con el datatables jquery y codeigniter, tengo mi html que es este: en mi php tengo esto: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); ...
  #1 (permalink)  
Antiguo 31/01/2015, 16:32
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
html datatables

hola gente,
estoy teniendo un problemilla con el datatables jquery y codeigniter, tengo mi html que es este:
en mi php tengo esto:
Código PHP:
Ver original
  1. $tabla = $this->Players->playerAll();
  2.        $tabla->add_column('edit', '<a href="jugadores/editar/$1"><i class="glyphicon glyphicon-edit" title="Editar"></i></a>
  3.                                    <a href="#jugadores/borrar/$1" class="del" id="delete"><i class="glyphicon glyphicon-trash" title="Editar"></i></a>
  4.                                    <a id="view" href="jugadores/ver/$1"><i class="glyphicon glyphicon-eye-open" title="Ver info"></i></a>', 'u.id');
  5.  
  6.        $results = $tabla->generate('json');

El cual genera las filas (en la columna acciones agrega los links ) de la tabla html que tiene el siguiente código:
Código HTML:
Ver original
  1. <ol class="breadcrumb bc-3">
  2.     <li>
  3.     <a href="<?php echo base_url('admin');?>"><i class="entypo-home"></i>Inicio</a>
  4.     </li>
  5.     <li class="active">
  6.         <strong>Jugadores</strong>
  7.     </li>
  8. </ol>
  9.  
  10. <h2>Listado de Jugadores</h2>
  11. <br />
  12. <?php
  13. if(alert())
  14. {?>
  15. <div class="row">
  16.     <div class="col-sm-12">
  17.         <?php echo alert();?>    
  18.     </div>
  19. </div>
  20. <?php
  21. }
  22. ?>
  23. <table class="table table-bordered datatable" id="table-1">
  24.     <thead>
  25.         <tr>
  26.             <th>#Id</th>
  27.             <th>Username</th>
  28.             <th>Email</th>
  29.             <th>City</th>
  30.             <th>Activo</th>
  31.             <th>Balance</th>
  32.             <th>Acciones</th>
  33.         </tr>
  34.     </thead>
  35.     <tbody>
  36.        
  37.     </tbody>
  38.     <tfoot>
  39.         <tr>
  40.             <th>#Id</th>
  41.             <th>Username</th>
  42.             <th>Email</th>
  43.             <th>City</th>
  44.             <th>Activo</th>
  45.             <th>Balance</th>
  46.             <th>Acciones</th>
  47.         </tr>
  48.     </tfoot>

dentro de esa vista tengo este codigo js:
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.     $(function() {
  3.   console.log('hola');
  4.     $("#delete").click(function(e) {
  5.             console.log('entro');
  6.             return false;
  7.             e.preventDefault();
  8.             var url = $(".delete").attr('href');
  9.             $('#modal-4').modal('show', {backdrop: 'statuc'});
  10.  
  11.         });  
  12. });
  13.     jQuery(document).ready(function($)
  14.     {
  15.  
  16.         $("#table-1").dataTable({
  17.             "sPaginationType": "bootstrap",
  18.             "iDisplayLength": 5,
  19.             "aLengthMenu": [[5,10, 25, 50, -1], [5,10, 25, 50, "Todos"]],
  20.             "bStateSave": true,
  21.             "bProcessing": true,
  22.             "bServerSide": true,
  23.             "sAjaxSource": '<?php echo base_url(); ?>admin/jugadores/list_all',
  24.             "fnInitComplete": function () {
  25.             },
  26.             'fnServerData': function (sSource, aoData, fnCallback) {
  27.                 $.ajax
  28.                 ({
  29.                     'dataType': 'json',
  30.                     'type': 'POST',
  31.                     'url': sSource,
  32.                     'data': aoData,
  33.                     'success': fnCallback
  34.                 });
  35.             }
  36.         }
  37.         );
  38.        
  39.         $(".dataTables_wrapper select").select2({
  40.             minimumResultsForSearch: -1
  41.         });
  42.     });
  43. </script>

Lo que no me esta funcinando es que cuando hago click en el link para borrar deberia mostrar el modal (mas alla del return false que hay ahora) y no muestra nada. En la consola me muestra "hola" por ende el jquery lo toma bien, pero no me muestra "entro", y no entiendo porque me hace eso. Será porque a las filas las carga por json?
Espero que me puedan dar una mano....
Desde ya muchas gracias!
  #2 (permalink)  
Antiguo 02/02/2015, 12:26
(Desactivado)
 
Fecha de Ingreso: abril-2013
Ubicación: rosario
Mensajes: 248
Antigüedad: 11 años
Puntos: 17
Respuesta: html datatables

claro, es xq las filas las cargas por ajax, por lo tanto el dom ya se cargo y jquery en esa instancia no lo reconoce, pero utilizando jQuery.on , no tendrias problemas.

si tu version de jQuery es mayor o igual a 1.7, sino tenes que utilizar .live
$("#delete").on("click",function(e) {
console.log('entro');
return false;
e.preventDefault();
var url = $(".delete").attr('href');
$('#modal-4').modal('show', {backdrop: 'statuc'});

});
  #3 (permalink)  
Antiguo 07/02/2015, 20:20
Avatar de destor77  
Fecha de Ingreso: noviembre-2004
Ubicación: Gálvez, Santa Fe, Argentina
Mensajes: 2.654
Antigüedad: 19 años, 5 meses
Puntos: 43
Respuesta: html datatables

Cita:
Iniciado por diurno10 Ver Mensaje
claro, es xq las filas las cargas por ajax, por lo tanto el dom ya se cargo y jquery en esa instancia no lo reconoce, pero utilizando jQuery.on , no tendrias problemas.

si tu version de jQuery es mayor o igual a 1.7, sino tenes que utilizar .live
$("#delete").on("click",function(e) {
console.log('entro');
return false;
e.preventDefault();
var url = $(".delete").attr('href');
$('#modal-4').modal('show', {backdrop: 'statuc'});

});
Hola diurno10,
intente como me dijiste poniendo asi:
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.     jQuery(document).ready(function($)
  3.     {
  4.         $("#table-1").dataTable({
  5.             "sPaginationType": "bootstrap",
  6.             "iDisplayLength": 5,
  7.             "aLengthMenu": [[5,10, 25, 50, -1], [5,10, 25, 50, "Todos"]],
  8.             "bStateSave": true,
  9.             "bProcessing": true,
  10.             "bServerSide": true,
  11.             "sAjaxSource": '<?php echo base_url(); ?>panel/premios/list_all',
  12.             "fnInitComplete": function () {
  13.             },
  14.             'fnServerData': function (sSource, aoData, fnCallback) {
  15.                 $.ajax
  16.                 ({
  17.                     'dataType': 'json',
  18.                     'type': 'POST',
  19.                     'url': sSource,
  20.                     'data': aoData,
  21.                     'success': fnCallback
  22.                 });
  23.             }
  24.         }
  25.         );
  26.        
  27.         $(".dataTables_wrapper select").select2({
  28.             minimumResultsForSearch: -1
  29.         });
  30.  
  31.         $(".del").on("click",function(e) {
  32.             console.log('entro');
  33.             return false;
  34.             e.preventDefault();
  35.             var url = $(".del").attr('href');
  36.             $('#modal-4').modal('show', {backdrop: 'statuc'});
  37.  
  38.         });  
  39.     });
  40. </script>
pero cuando hago click en el link se ejecute directamente no toma el return false estoy haciendo algo mal?

Etiquetas: ajax, datatables, html, javascript, js, php, select
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:22.