jQuery datatable sAjaxSource - Show error while searching

Asked

Viewed 171 times

1

At great cost, I was able to find an ajax code for loading the tables. It was necessary, because there are more than 5 thousand records.

Error appearing while searching:

Datatables Warning (table id = 'schedule table'): Datatables Warning: JSON data from server could not be Parsed. This is caused by a JSON formatting error.

Could anyone help how to solve this? see my code:

<script src="assets/js/jquery.dataTables.js"></script>
<script src="assets/js/jquery.dataTables.bootstrap.js"></script>
<script type="text/javascript">
            jQuery(function($) {
                var oTable1 = $('#tabela-agenda').dataTable({
                    "bProcessing": true,
                    "bServerSide": true,
                    "sAjaxSource": "cadastroCarregaRegistros.php",
                    "aaSorting": [[ 0, "desc" ]],
                    "bAutoWidth" : false,
                    aoColumnDefs: [
                        {"aTargets": [ 0 ], "bSearchable": true, "bVisible": false },
                        { 
                            "aTargets": [ 1 ],
                            "bSortable": false, 
                            "mRender": function ( url, type, full ) { 
                                return '<img src="/images/fotos/' + url + '" height="50" alt=""/>';
                            }
                        },
                        {"aTargets": [ 2 ] },
                        {"aTargets": [ 3 ] },
                        {"aTargets": [ 4 ] },
                        {"aTargets": [ 5 ] },
                        {
                            "aTargets": [ 6 ],
                            "bSortable": false, 
                            "mRender": function ( status, type, full ) { 
                            switch (status) {
                                    case "N":
                                        return '<span class="label label-warning">Aguardando aprovação</span>';
                                        break;
                                    case "A":
                                        return '<span class="label label-success">Ativo</span>';
                                        break;
                                    case "V":
                                        return '<span class="label label-danger">Vencido</span>';
                                        break;
                                    case "B":
                                        return '<span class="label label-inverse">Banido</span>';
                                        break;
                                    case "F":
                                        return '<span class="label label-purple">Falta Pagar</span>';
                                        break;
                                    case "S":
                                        return '<span class="label label-grey">Suspenso</span>';
                                        break;
                                }
                            }

                        },
                        {
                            "aTargets": [ 7 ],
                            "bSortable": false,
                            "mData": 0,
                            "mData": 1,
                            "mData": 2,
                            "sWidth": "100px", 
                            "sClass": "center",
                            "mRender": function ( data, type, val  ) {
                                if (!val[2]){
                                    return  '<a class="blue" href="cadastroPerfil.php?id=' +  val[0] + '&i=2a" title="Perfil"> <i class="icon-zoom-in bigger-130"></i></a>          <a class="green" href="cadastroEditar.php?id=' + val[0] + '&i=2a" onclick="return hs.htmlExpand(this, {objectType: \'iframe\', width: 800, height:400 } )" title="Editar"> <i class="icon-pencil bigger-130"></i> </a>          <a class="red delete-event" href="cadastroApagar.php?id=' + val[0] + '&foto=' + val[1] + '&i=2a" title="Apagar" data-title="Apagar" data-content="Deseja apagar esse membro?"> <i class="icon-trash bigger-130"></i></a></div>'
                                }else{
                                    return  '<a class="purple" href="carteirinha.php?badge=' +  val[2] + ' " onclick="return hs.htmlExpand(this, {objectType: \'iframe\', width: 800, height:400 } )" title="Carteirinha"> <i class="icon-print bigger-130"></i> </a>           <a class="blue" href="cadastroPerfil.php?id=' +  val[0] + '&i=2a" title="Perfil"> <i class="icon-zoom-in bigger-130"></i></a>           <a class="green" href="cadastroEditar.php?id=' + val[0] + '&i=2a" onclick="return hs.htmlExpand(this, {objectType: \'iframe\', width: 800, height:400 } )" title="Editar"> <i class="icon-pencil bigger-130"></i> </a>          <a class="red delete-event" href="cadastroApagar.php?id=' + val[0] + '&foto=' + val[1] + '&i=2a" title="Apagar" data-title="Apagar" data-content="Deseja apagar esse membro?"> <i class="icon-trash bigger-130"></i></a></div>'
                                }

                            },
                            "bSortable": false
                        }
                    ]
                });


                $('table th input:checkbox').on('click', function() {
                    var that = this;
                    $(this).closest('table').find('tr > td:first-child input:checkbox')
                            .each(function() {
                        this.checked = that.checked;
                        $(this).closest('tr').toggleClass('selected');
                    });

                });


                $('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
                function tooltip_placement(context, source) {
                    var $source = $(source);
                    var $parent = $source.closest('table')
                    var off1 = $parent.offset();
                    var w1 = $parent.width();

                    var off2 = $source.offset();
                    var w2 = $source.width();

                    if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2))
                        return 'right';
                    return 'left';
                }
            })
</script>
  • Thanks, but it didn’t help, there’s another tip?

  • Which programming language you use?

  • Doing using the PHP

  • Since it’s the right way to do @Marconi, I took an example on the internet and tried to incorporate my need, so I don’t know the right way to do it. I’d appreciate it if you could help.

  • @Marconi am in chat

  • Vixe excludes me sends the link here.

  • http://chat.stackexchange.com/rooms/31379/discussion-between-marconi-and-tiago

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.