Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
Implement Individual column searching using JS in DTedit

In my datatable, I would like to implement individual column searching shown in this page:

https://datatables.net/examples/api/multi_filter.html

I am using DTedit R package, an extension to DT, and it doesn't have the convenient filter argument. So, I am trying to use the datatable.options argument inside dtedit to implement individual column searching.

In dtedit, I can incorporate JS code with the following code:

jsc <- `Some JS code`

dtedit(input,
       output,
       name = "input_table",
       thedata = design,
       ...,
       datatable.options = list(initComplete = JS(jsc))
)

My JS skills are non existent and I need help on figuring out how to use the following JS code in my dtedit

$(document).ready(function() {
    // Setup - add a text input to each footer cell
    $('#example tfoot th').each( function () {
        var title = $(this).text();
        $(this).html( '<input type="text" placeholder="Search '+title+'" />' );
    } );
 
    // DataTable
    var table = $('#example').DataTable({
        initComplete: function () {
            // Apply the search
            this.api().columns().every( function () {
                var that = this;
 
                $( 'input', this.footer() ).on( 'keyup change clear', function () {
                    if ( that.search() !== this.value ) {
                        that
                            .search( this.value )
                            .draw();
                    }
                } );
            } );
        }
    });
 
} );
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here is how I would do with the DT package:

initComplete <- "
function(settings) {
  var table = settings.oInstance.api();
  var ncol = table.columns().count();
  var append = function (i) {
    var column = table.column(i);
    var colname = column.header().textContent;
    var $input = $(
      '<input type=\\\"text\\\" placeholder=\\\"Search ' + colname + '\\\" />'
    );
    $(column.footer()).append($input);
    $input.on('keyup change clear', function () {
      if (column.search() !== this.value) {
        column.search(this.value).draw();
      }
    });
  };
  for (var i = 1; i < ncol; i++) {
    append(i);
  }
}
"

dat <- iris
sketch <- htmltools::withTags(table(
  class = 'display',
  thead(
    tr(
      lapply(c("", names(dat)), th)
    )
  ),
  tfoot(
    tr(
      lapply(rep("", 1+ncol(dat)), th)
    )
  )
))

datatable(
  dat,
  container = sketch,
  options = list(
    initComplete = JS(initComplete),
    columnDefs = list(
      list(targets = "_all", className = "dt-center")
    )
  )
)

enter image description here

I am not familiar with DTedit. But I took a look at the doc and it seems that it doesn't accept the container option. And unfortunately, it's not possible to add a footer to a datatable with JavaScript.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda