Datatables select inputs columns filter shows only 10 results when using server side processing

Datatables select inputs columns filter shows only 10 results when using server side processing

andrebandreb Posts: 2Questions: 1Answers: 0
edited December 2017 in DataTables

Hi,
I'm trying add select inputs filters on each column, i'm able do add the filters but the select options only shows me the initial 10 results of the first page.
My code

var table = $('#df_form_proprietarios_intervencionar_intervencionados').DataTable( {
dom: 'Bfrtip',
ajax: {url:'df_form_proprietarios_intervencionar.php', type:'POST'},
"scrollX": true,
serverSide: true,
processing: true,
"deferRender": true,
keys: true,
"pageLength": 10,
initComplete: function () {
    this.api().columns().every( function () {
        var column = this;
        var select = $('<select><option value=""></option></select>')
            .appendTo( $(column.footer()).empty() )
            .on( 'change', function () {
                var val = $.fn.dataTable.util.escapeRegex(
                    $(this).val()
                );
                 
                column
                    .search( val ? '^'+val+'$' : '', true, false )
                    .draw();
            } );
                 
        column.data().unique().sort().each( function ( d, j ) {
            select.append( '<option value="'+d+'">'+d+'</option>' )
        } );
    } );
},
language: {
    url: '//cdn.datatables.net/plug-ins/1.10.16/i18n/Portuguese.json'
},
columns: [
    {
        "data":"id"
    },  
    {
        "data": "linha"
    },
    {
        "data": "predio"
    },
    {
        "data": "aglomerado"
    },
    {
        "data": "nome_proprietario"
    },
    {
        "data": "morada_proprietario"
    },
    {
        "data": "contactos_proprietario"
    },
    {
        "data": "nome_representante"
    },
    {
        "data": "morada_representante"
    },
    {
        "data": "contactos_representante"
    },
    {
        "data": "localizacao_concelho"
    },
    {
        "data": "localizacao_freguesia"
    },
    {
        "data": "localizacao_localidade"
    },
    {
        "data": "vao"
    },
    {
        "data": "x"
    },
    {
        "data": "y"
    },
    {
        "data": "leg_brg"
    },
    {
        "data": "area_por_leg_m2"
    },
    {
        "data": "area_total_proprietrio_m2"
    },
    {
        "data": "indemnizacao_total_proprietario"
    },
    {
        "data": "n_da_carta"
    },
    {
        "data": "data_numeracao"
    },
    {
        "data": "carta_devolvida"
    },
    {
        "data": "motivo_devolucao_ctt"
    },
    {
        "data": "motivo_real_devolucao"
    },
    {
        "data": "data_entrega_ctt"
    },
    {
        "data": "discordancias_por_escrito"
    },
    {
        "data": "assinatura_do_acordo"
    },
    {
        "data": "observacoes_reuniao"
    },
    {
        "data": "reflorestacao"
    },
    {
        "data": "observacoes_reflorestacao"
    },
    {
        "data": "n_intervencao"
    },
    {
        "data": "data_da_intervencao"
    },
    {
        "data": "valor_real_da_indemnizacao"
    },
    {
        "data": "n_rc"
    },
    {
        "data": "data_lib_proc_prej"
    },
    {
        "data": "valor_da_intervencao_pse"
    },
    {
        "data": "observacoes_pse"
    },
    {
        "data": "area_corte_total_pse"
    },
    {
        "data": "destruicao_de_cepos"
    },
    {
        "data": "destrocamento_da_rama"
    },
    {
        "data": "gestao_de_combustivel"
    },
    {
        "data": "metros"
    },
    {
        "data": "dap_5"
    },
    {
        "data": "dap_10"
    },
    {
        "data": "dap_15"
    },
    {
        "data": "dap_20"
    },
    {
        "data": "dap_25"
    },
    {
        "data": "dap_30"
    },
    {
        "data": "dap_35"
    },
    {
        "data": "dap_40"
    },
    {
        "data": "dap_45"
    },
    {
        "data": "dap_50"
    },
    {
        "data": "criado_por"
    },
    {
        "data": "criado_por_id"
    },
    {
        "data": "data_criacao"
    },
    {
        "data": "criado_por_empresa"
    },
    {
        "data": "actualizado_por"
    },
    {
        "data": "actualizado_por_id"
    },
    {
        "data": "data_actualizacao"
    },
    {
        "data": "actualizado_por_empresa"
    }
],
select: true,
lengthChange: false,
buttons: [
    { extend: 'create', editor: editor },
    { extend: 'edit',   editor: editor },
    { extend: 'remove',   editor: editor },
    { extend: 'excel', text: 'Exportar Excel', filename: 'SGIF - Ciclo de Registos e Intervenções' },
]
} );

Can you help me?

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    You are using server-side processing and since you are building the filters on the client-side, with only the client-side information available, that explains why only those results on the first page are shown.

    You'd need to modify your server-side script to have it return the options that should be available for each column and then use that to populate the list of options in initComplete.

    Allan

  • andrebandreb Posts: 2Questions: 1Answers: 0

    Hi,
    My server side script came from your generator
    https://editor.datatables.net/generator/index
    Do you have any example or give me the guidelines to do it?
    Best regards

This discussion has been closed.