how I show that information at my view?

how I show that information at my view?

sobral00sobral00 Posts: 6Questions: 2Answers: 0

var table = $('#example').DataTable();
var info = table.page.info();

$('#tableInfo').html(
'Currently showing page '+(info.page+1)+' of '+info.pages+' pages.'
);

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Is that code not working for you? Looks like it does here:
    http://live.datatables.net/yuwakiba/1/edit

    Kevin

  • sobral00sobral00 Posts: 6Questions: 2Answers: 0

    take a look, when u change the page, the info page 1 of 6 stay the same

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    You can use the draw event to update the info, like this:
    http://live.datatables.net/yuwakiba/2/edit

    Kevin

  • sobral00sobral00 Posts: 6Questions: 2Answers: 0
    edited July 2020

    I tried to use that draw event at my script, but I couldn't, can you help me please?
    my script:

    $(document).ready(function () {

            var table = $('#minhatabela').DataTable({
    
                "language": {
                    "sEmptyTable": "Nenhum registro encontrado",
                    "sInfo": "Total de _TOTAL_ registros",
                    "sInfoEmpty": "Mostrando 0 até 0 de 0 registros",
                    "sInfoFiltered": "(Filtrados de _MAX_ registros)",
                    "sInfoPostFix": "",
                    "sInfoThousands": ".",
                    "sLengthMenu": "Exibir _MENU_ registros por página",
                    "sLoadingRecords": "Carregando...",
                    "sProcessing": "Processando...",
                    "sZeroRecords": "Nenhum registro encontrado",
                    "sSearch": "Pesquisar",
                    "oPaginate": {
                        "sNext": "Próximo",
                        "sPrevious": "Anterior",
                        "sFirst": "Primeiro",
                        "sLast": "Último"
                    },
                    "oAria": {
                        "sSortAscending": ": Ordenar colunas de forma ascendente",
                        "sSortDescending": ": Ordenar colunas de forma descendente"
                    },
                    "select": {
                        "rows": {
                            "_": "Selecionado %d linhas",
                            "0": "Nenhuma linha selecionada",
                            "1": "Selecionado 1 linha"
                        }
                    },
                    "buttons": {
                        "copy": "Copiar para a área de transferência",
                        "copyTitle": "Cópia bem sucedida",
                        "copySuccess": {
                            "1": "Uma linha copiada com sucesso",
                            "_": "%d linhas copiadas com sucesso"
                        }
                    }
                },
                "processing": true,
                "serverSide": true,
                "searching": false,
                "ajax": {
                    "url": "/api/SubGrupoController",
                    "method": "POST"
                },
                "columns": [
                    { "data": "cid_sgrupoproduto" },
                    { "data": "cnome_sgrupoproduto" },
                    { "data": "ndesconto", render: $.fn.dataTable.render.number('.', ',', 2) },
                    { "data": "tdata_usu" }
    
                ],
                "aoColumnDefs": [
                    { className: "text-center", "targets": [3] },
                    { className: "text-right", "targets": [2] },
                    {
                        "aTargets": [3]
                        , "sType": "date"
                        , "mRender": function (d, type, full) {
                            d = new Date(d);
                            month = '' + (d.getMonth() + 1),
                                day = '' + d.getDate(),
                                year = d.getFullYear();
    
                            if (month.length < 2)
                                month = '0' + month;
                            if (day.length < 2)
                                day = '0' + day;
    
                            return [day, month, year].join('-');
                        }
                    }
                ],
                "ordering": true,
                "paging": true,
                "pagingType": "simple_numbers",
                "pageLength": 10,
    
                "dom": "<'up'li>t<'row'<'col-md-5'p>>"
    
            });
    
            var info = table.page.info();
    
            $('#tableinfo').html(
                'Pág ' + (info.page + 1) + ' de ' + info.pages
            ); //this doesn't work
    
        })(jQuery);
    
  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    I tried to use that draw event at my script, but I couldn't, can you help me please?

    Doesn't look like you added the draw event to your code. The example I provided shows exactly how to use it:
    http://live.datatables.net/yuwakiba/2/edit

    Kevin

This discussion has been closed.