Skip to content

Instantly share code, notes, and snippets.

@eddychilakiller
Last active November 29, 2024 08:20
Show Gist options
  • Save eddychilakiller/4e6f593aab1f357c4255f23c876a427c to your computer and use it in GitHub Desktop.
Save eddychilakiller/4e6f593aab1f357c4255f23c876a427c to your computer and use it in GitHub Desktop.
Data table
$(document).ready(function() {
var table = $('#example').DataTable( {
ajax: "data/data.json",
lengthMenu: [ 20, 50 ],
pagingType: "full_numbers",
initComplete: function() {
$('.dataTables_filter input').unbind();
var input = $('.dataTables_filter input').unbind(),
self = this.api(),
$searchButton = $('<button>')
.text('search')
.click(function() {
self.search(input.val()).draw();
}),
$clearButton = $('<button>')
.text('clear')
.click(function() {
input.val('');
$searchButton.click();
})
$('.dataTables_filter').append($searchButton, $clearButton);
$('.dataTables_filter input').bind('keyup', function(e){
var code = e.keyCode || e.which;
if (code == 13) {
table.search(this.value).draw();
}
}).bind("input",function(e){
if(this.value.length > 3 || e.keyCode == 13) {
dtable.search(this.value).draw();
}
if(this.value == "") {
dtable.search("").draw();
}
return;
});
},
columns: [
{ data: "title" },
{ data: "field_numero_de_expediente" },
{ data: "field_d11sp11a_doc" },
{
data: "field_d11sp11a_doc_1",
render: function(data, type, row) {
console.log(row);
if (type === 'display') {
return '<div class="media"><a href="' + row.field_d11sp11a_doc + '" target="_blank" class="d-inline-block pdf"><span class="d-table-cell align-middle pr-2 media-left list-icons"><i class="icons-vdos icon-pdf"></i></span><span class="d-table-cell align-middle pr-2">' + data + '</span></a></div>';
}
return data;
}
},
],
order: [[1 , 'asc']],
language: {
"processing": "Procesando...",
"lengthMenu": "Mostrar _MENU_ registros",
"zeroRecords": "No se encontraron resultados",
"emptyTable": "Ningún dato disponible en esta tabla",
"info": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
"infoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
"infoFiltered": "(filtrado de un total de _MAX_ registros)",
"search": "Buscar:",
"infoThousands": ",",
"loadingRecords": "Cargando...",
"paginate": {
"first": "Primero",
"last": "Último",
"next": "Siguiente",
"previous": "Anterior"
},
"aria": {
"sortAscending": ": Activar para ordenar la columna de manera ascendente",
"sortDescending": ": Activar para ordenar la columna de manera descendente"
},
"buttons": {
"copy": "Copiar",
"colvis": "Visibilidad",
"collection": "Colección",
"colvisRestore": "Restaurar visibilidad",
"copyKeys": "Presione ctrl o u2318 + C para copiar los datos de la tabla al portapapeles del sistema. <br \/> <br \/> Para cancelar, haga clic en este mensaje o presione escape.",
"copySuccess": {
"1": "Copiada 1 fila al portapapeles",
"_": "Copiadas %d fila al portapapeles"
},
"copyTitle": "Copiar al portapapeles",
"csv": "CSV",
"excel": "Excel",
"pageLength": {
"-1": "Mostrar todas las filas",
"1": "Mostrar 1 fila",
"_": "Mostrar %d filas"
},
"pdf": "PDF",
"print": "Imprimir"
},
"autoFill": {
"cancel": "Cancelar",
"fill": "Rellene todas las celdas con <i>%d<\/i>",
"fillHorizontal": "Rellenar celdas horizontalmente",
"fillVertical": "Rellenar celdas verticalmentemente"
},
"decimal": ",",
"searchBuilder": {
"add": "Añadir condición",
"button": {
"0": "Constructor de búsqueda",
"_": "Constructor de búsqueda (%d)"
},
"clearAll": "Borrar todo",
"condition": "Condición",
"conditions": {
"date": {
"after": "Despues",
"before": "Antes",
"between": "Entre",
"empty": "Vacío",
"equals": "Igual a",
"not": "No",
"notBetween": "No entre",
"notEmpty": "No Vacio"
},
"moment": {
"after": "Despues",
"before": "Antes",
"between": "Entre",
"empty": "Vacío",
"equals": "Igual a",
"not": "No",
"notBetween": "No entre",
"notEmpty": "No vacio"
},
"number": {
"between": "Entre",
"empty": "Vacio",
"equals": "Igual a",
"gt": "Mayor a",
"gte": "Mayor o igual a",
"lt": "Menor que",
"lte": "Menor o igual que",
"not": "No",
"notBetween": "No entre",
"notEmpty": "No vacío"
},
"string": {
"contains": "Contiene",
"empty": "Vacío",
"endsWith": "Termina en",
"equals": "Igual a",
"not": "No",
"notEmpty": "No Vacio",
"startsWith": "Empieza con"
}
},
"data": "Data",
"deleteTitle": "Eliminar regla de filtrado",
"leftTitle": "Criterios anulados",
"logicAnd": "Y",
"logicOr": "O",
"rightTitle": "Criterios de sangría",
"title": {
"0": "Constructor de búsqueda",
"_": "Constructor de búsqueda (%d)"
},
"value": "Valor"
},
"searchPanes": {
"clearMessage": "Borrar todo",
"collapse": {
"0": "Paneles de búsqueda",
"_": "Paneles de búsqueda (%d)"
},
"count": "{total}",
"countFiltered": "{shown} ({total})",
"emptyPanes": "Sin paneles de búsqueda",
"loadMessage": "Cargando paneles de búsqueda",
"title": "Filtros Activos - %d"
},
"select": {
"1": "%d fila seleccionada",
"_": "%d filas seleccionadas",
"cells": {
"1": "1 celda seleccionada",
"_": "$d celdas seleccionadas"
},
"columns": {
"1": "1 columna seleccionada",
"_": "%d columnas seleccionadas"
}
},
"thousands": "."
},
/*
rowGroup: {
dataSrc: [ 'title', 'field_numero_de_expediente' ]
}, */
columnDefs: [{
targets: [ 2 ],
visible: false
}]
});
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment