add format number in datatables

This commit is contained in:
amazuecos
2025-02-09 00:25:52 +01:00
parent 21a4e5b8bd
commit f532c79b27
17 changed files with 361 additions and 132 deletions

View File

@ -1,5 +1,4 @@
export function getToken()
{
export function getToken() {
const scriptUrl = new URL(import.meta.url);
const params = new URLSearchParams(scriptUrl.search);
@ -10,3 +9,67 @@ export function getToken()
export function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
export const initAutonumeric = () => {
$(document).on('draw.dt', (event) => {
$("span.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (!autoNumericInstance) {
new AutoNumeric(this, {
digitGroupSeparator: ".",
decimalCharacter: ",",
allowDecimalPadding : 'floats',
decimalPlaces: 2,
unformatOnSubmit: true,
});
}
})
// $(':input[type="number"]').each(function(){
// $(this).attr('type','text')
// let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
// if (!autoNumericInstance) {
// new AutoNumeric(this, {
// digitGroupSeparator: ".",
// decimalCharacter: ",",
// allowDecimalPadding : 'floats',
// decimalPlaces: 2,
// unformatOnSubmit: true,
// });
// }
// })
})
// editor.on('open', (event) => {
// $("input.autonumeric").each(function () {
// let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
// if (autoNumericInstance) {
// autoNumericInstance.remove()
// }
// new AutoNumeric(this, {
// decimalCharacter: ",",
// digitGroupSeparator: ".",
// allowDecimalPadding : 'floats',
// decimalPlaces: 2,
// unformatOnSubmit: true,
// });
// })
// })
// editor.on('preSubmit', (e, d, type) => {
// if (d.data) {
// Object.keys(d.data).forEach(function (key) {
// // Find all elements with class .autonumeric
// $("input.autonumeric").each(function () {
// let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
// if (autoNumericInstance) {
// // Get raw value and update the corresponding field
// let rawValue = autoNumericInstance.getNumericString();
// d.data[key][this.name] = rawValue; // Ensure the correct name attribute is used
// }
// });
// });
// }
// })
}

View File

@ -0,0 +1,4 @@
import { initAutonumeric } from "../common/common.js";
initAutonumeric()

View File

@ -91,10 +91,10 @@ class MaquinasList {
{ 'data': 'id' },
{ 'data': 'nombre' },
{ 'data': 'tipo' },
{ 'data': 'ancho_impresion' },
{ 'data': 'alto_impresion' },
{ 'data': 'min' },
{ 'data': 'max' }
{ 'data': 'ancho_impresion',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'alto_impresion',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'min',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'max',render : (d) => `<span class="autonumeric">${d}</span>` }
];
const actions = ['edit', 'delete'];