Commit 1055284d by Billy Larru

arreglando datatable

parent b9f72db6
...@@ -15,7 +15,7 @@ const ajaxModal = axios.create({ ...@@ -15,7 +15,7 @@ const ajaxModal = axios.create({
baseURL: `http://localhost:7070/Asistencia/vistas/modals/` baseURL: `http://localhost:7070/Asistencia/vistas/modals/`
}); });
//<editor-fold>
//<editor-fold> MODULO DE POLICIAS //<editor-fold> MODULO DE POLICIAS
const URI_TIPOROL_POLICIA = "tipoRolPolicias"; const URI_TIPOROL_POLICIA = "tipoRolPolicias";
const URI_FRECUENCIA_ROL_POLICIA = "frecuenciaRolPolicias"; const URI_FRECUENCIA_ROL_POLICIA = "frecuenciaRolPolicias";
...@@ -35,7 +35,6 @@ const URI_POLICIA_PROYECTADO_COMPARATIVO = "proyectadoComparativo"; ...@@ -35,7 +35,6 @@ const URI_POLICIA_PROYECTADO_COMPARATIVO = "proyectadoComparativo";
//</editor-fold> //</editor-fold>
$.extend($.fn.dataTable.defaults, { $.extend($.fn.dataTable.defaults, {
bSort: false, bSort: false,
bFilter: false, bFilter: false,
...@@ -296,31 +295,48 @@ function primeraLetraMayuscula(str) { ...@@ -296,31 +295,48 @@ function primeraLetraMayuscula(str) {
const makeDatatable = (jsonForDatatable = { const makeDatatable = (
data: [], wrapName = ``,
columns: [], forDatatable = {
columnDefs: [], data: [],
wrapsNameDatatable: ``, columns: [],
classNameForDatatable: ``, footerFilter: false,
footerFilter: false, footer: false
highlighting: true },
}) => { className = ``,
let data = jsonForDatatable.data; ) => {
let columns = jsonForDatatable.columns; if (!wrapName) {
let columnDefs = jsonForDatatable.columns; return {
let wrapsNameDatatable = jsonForDatatable.wrapsNameDatatable message: `{wrapName} is empty`,
let nameDatatable = `${wrapsNameDatatable}-datatable` status: false
let classNameForDatatable = jsonForDatatable.classNameForDatatable }
}
debugger;
if (forDatatable.data.length <= 0) {
return {
message: `{data} is empty`,
status: false
}
}
if (forDatatable.columns.length <= 0) {
return {
message: `{columns} is empty`,
status: false
}
}
let highlighting = jsonForDatatable.highlighting let nameDatatable = `${wrapName}-datatable`;
let footerFilter = jsonForDatatable.footerFilter
// table
let table_head = ` let table_head = `
<table id="${nameDatatable}" class="${classNameForDatatable} table-hover" cellspacing="0" width="100%">`; <table id="${nameDatatable}" class="table table-hover ${className}" cellspacing="0" width="100%">`;
// headers
let table_head_th = ` let table_head_th = `
<thead> <thead>
<tr>`; <tr>`;
columns.forEach((obj) => { forDatatable.columns.forEach((obj) => {
let title = `undefined`; let title = `undefined`;
if (obj.title) { if (obj.title) {
title = obj.title; title = obj.title;
...@@ -334,12 +350,13 @@ data: [], ...@@ -334,12 +350,13 @@ data: [],
</tr> </tr>
</thead>` </thead>`
// footers
let table_foot_th = ``; let table_foot_th = ``;
if (footerFilter) { if (forDatatable.footer) {
table_foot_th = ` table_foot_th = `
<tfoot> <tfoot>
<tr>`; <tr>`;
columns.forEach((obj) => { forDatatable.columns.forEach((obj) => {
let title = `undefined`; let title = `undefined`;
if (obj.title) { if (obj.title) {
title = obj.title; title = obj.title;
...@@ -355,11 +372,13 @@ data: [], ...@@ -355,11 +372,13 @@ data: [],
` `
} }
// table
let table_foot = `</table>` let table_foot = `</table>`
$(`#${wrapsNameDatatable}`).empty().append(`${table_head}${table_head_th}${table_foot_th}${table_foot}`); $(`#${wrapName}`).empty().append(`${table_head}${table_head_th}${table_foot_th}${table_foot}`);
if (footerFilter) {
// Setup - add a text input to each footer cell if (forDatatable.footerFilter) {
// Setup - add a text input to each footer cell
$(`#${nameDatatable} tfoot th`).each(function () { $(`#${nameDatatable} tfoot th`).each(function () {
var title = $(this).text(); var title = $(this).text();
$(this).html(`<input type="text" class="form-control" placeholder="${title}" />`); $(this).html(`<input type="text" class="form-control" placeholder="${title}" />`);
...@@ -367,18 +386,12 @@ data: [], ...@@ -367,18 +386,12 @@ data: [],
} }
$(`#${nameDatatable}`) $(`#${nameDatatable}`)
.DataTable({ .DataTable(forDatatable);
data,
columns, if (forDatatable.footerFilter) {
columnDefs, // DataTable
fixedColumns: {
leftColumns: 1,
rightColumns: 1
}
});
if (footerFilter) {
// DataTable
let table = $(`#${nameDatatable}`).DataTable(); let table = $(`#${nameDatatable}`).DataTable();
// Apply the search // Apply the search
table.columns().every(function () { table.columns().every(function () {
var that = this; var that = this;
...@@ -390,22 +403,13 @@ data: [], ...@@ -390,22 +403,13 @@ data: [],
} }
}); });
}); });
$(`#${wrapsNameDatatable} .dataTables_scrollBody`).appendTo(`#${wrapsNameDatatable} .dataTables_scroll`);
}
if (highlighting) { $(`#${wrapName} .dataTables_scrollBody`).appendTo(`#${wrapName} .dataTables_scroll`);
let table = $(`#${nameDatatable}`).DataTable();
$(`#${nameDatatable} tbody`)
.on('mouseenter', 'td', function () {
let colIdx = table.cell(this).index().column;
$(table.cells().nodes()).removeClass('highlight');
$(table.column(colIdx).nodes()).addClass('highlight');
});
} }
return Promise.resolve({ return Promise.resolve({
datatable: $(`#${nameDatatable}`), datatable: $(`#${nameDatatable}`),
container: $(`#${wrapsNameDatatable}`) container: $(`#${wrapName}`)
}); });
} }
......
...@@ -132,18 +132,16 @@ function verReporte(objParams = {}) { ...@@ -132,18 +132,16 @@ function verReporte(objParams = {}) {
let wrapsNameDatatable = `divDatatable`; let wrapsNameDatatable = `divDatatable`;
let classNameForDatatable = `display table table-bordered`; let classNameForDatatable = `display table table-bordered`;
let footer = false;
makeDatatable( makeDatatable(wrapsNameDatatable,
{ {
data: response.data, data: response.data,
columns, columns,
columnDefs, columnDefs,
wrapsNameDatatable,
classNameForDatatable, },
footer classNameForDatatable
} )
)
} }
); );
} }
......
...@@ -65,7 +65,6 @@ ...@@ -65,7 +65,6 @@
<%@include file="templates/footer-body.jsp"%> <%@include file="templates/footer-body.jsp"%>
<!--js de la pagina--> <!--js de la pagina-->
<script src="../plantilla/assets/js/plugins/tables/datatables/datatables.min.js" type="text/javascript"></script>
<script src="../plantilla/assets/js/plugins/ui/moment/moment.min.js" type="text/javascript"></script> <script src="../plantilla/assets/js/plugins/ui/moment/moment.min.js" type="text/javascript"></script>
<script src="../plantilla/assets/js/plugins/pickers/daterangepicker.js"></script> <script src="../plantilla/assets/js/plugins/pickers/daterangepicker.js"></script>
<script src="../plantilla/assets/js/core/libraries/jquery_ui/widgets.min.js"></script> <script src="../plantilla/assets/js/core/libraries/jquery_ui/widgets.min.js"></script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment