Server-side searching in column not working?

Server-side searching in column not working?

Javier64Javier64 Posts: 6Questions: 2Answers: 0

Hi, I'm having an issue with my Datatable and searching by column. I have to search values in 2 columns from 2 different inputs, but I'm using server-side processing. So what I did was: set the values in the table from the HTML inputs (when the page loads, they'll be empty, so it'll bring all the records), and the Search button redraws the table, now with the values taken from the text inputs. This somehow doesn't work, even though when I debug the code, the search parameters are set correctly. Here's my code:

JS:

minutaNoPresentada.tablaMinutasNoPresentadas = $("#TablaMinutasNoPresentadas")
        .DataTable(
          {
              ajax: {
                  url: minutaAjax.configuracion.URLSERVICE + "escriturasPresentadas/consultaMinutasNoPresentadas",
                  timeout: minutaAjax.configuracion.TIMEOUT,
                  type: "POST",
                  dataType: "json",
                  data: function ( d ) {
                      d.columns[1].search.value = $('#anioEscritura').val();
                      d.columns[2].search.value = $('#numeroEscritura').val();
                      return JSON.stringify(d);
                   },
                   beforeSend: function (request) {
                       request.setRequestHeader("token", minutaAjax.getToken());
                   },                  
                  contentType: minutaAjax.configuracion.CONTENTTYPE,
                  error: function (xhr, error, thrown) {                
                      
                      minutaAjax.error(xhr, error, thrown);
                      $('#TablaMinutasNoPresentadas_processing').hide();                          
                      
                  }
              },              
              serverSide: true,
              searching: true,
              dom: "ltip",
              processing: true,
              deferRender: true,
              fnServerParams: function (aoData) {

                  aoData.cuit = $('#formPresentar').find('input[name="cuit"]').val();
                  aoData.anio = $('#formPresentar').find('input[name="anio"]').val();   
                  aoData.numero = $('#formPresentar').find('input[name="numero"]').val();           
              },      
              order: [[ 1, "asc" ]],
            columnDefs: columnDefs,
           
        select: {
            style: 'single'
        },
        pagingType: 'full'
    });


$('.filter-button').click(function (e) {
        minutaNoPresentada.tablaMinutasNoPresentadas.draw();
    });

JSP/HTML:

    <div id="formularioPresentar">
        <div class="titulo">
            Consulta de Minutas No Presentadas
        </div>

        <form id="formMinutas" class='filter-form'>
            <input name="token" type="hidden" value="${token}"/>        
            <input type="hidden" name="servicioId" value="${servicio.id}"/>
            <input type="hidden" name="cuit" value="${cuitAutorizado}"/>
            <input type="hidden" name="logon" value="${usuario.logon}"/>
            <div>

                        <label for="anio" class="label">Año Escritura</label>
                        <input placeholder="Año Escritura" type="number" name="anio" id="anioEscritura" class='filter' data-column-index='1'/>
            </div>
            <div>

                <label for="numero" class="label">Nro Escritura</label>
                <input placeholder="Número Escritura" type="number" name="numero" id="numeroEscritura" class='filter' data-column-index='2'/>

            </div>
            <div>
                <input type="reset" value="Reestablecer" id="reestablecer" class="reset-button"/> 
                <input type="button" value="Buscar" class="filter-button"/>
            </div>
        </form>

    </div>

I've already tried different methods like this:

http://jsfiddle.net/yLxowxen/20/

But it doesn't work the same way.

For more information here's the Datatables debugger output:

https://debug.datatables.net/etejik

Any help would be appreciated. Thanks!

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,394Questions: 26Answers: 4,786
    Answer ✓

    With server side processing enabled your server script is expected to handle the searching. What are you using for your server side script?

    Does it support all the parameters sent via server side processing?
    https://datatables.net/manual/server-side

    Kevin

  • Javier64Javier64 Posts: 6Questions: 2Answers: 0

    Thanks, it was just a mistake, I wasn't sending the input values correctly in aoData.

This discussion has been closed.