add autonumeric to number cells of datatables and editorDatatable

This commit is contained in:
amazuecos
2025-02-09 12:40:52 +01:00
parent 816a321e1a
commit 3efec5e6cb
2 changed files with 52 additions and 10 deletions

View File

@ -141,7 +141,11 @@ var editor_lineas = new $.fn.dataTable.Editor( {
fields: [
{
name: "cantidad",
attr: {
type: "text",
name : "cantidad",
class :"autonumeric"
}
}, {
name: "descripcion",
type: "textarea",
@ -152,10 +156,18 @@ var editor_lineas = new $.fn.dataTable.Editor( {
}, {
name: "precio_unidad",
attr: {
type: "text",
name : "precio_unidad",
class :"autonumeric",
style: "min-width: 65px;"
}
}, {
name: "iva",
attr: {
type: "text",
name : "iva",
class :"autonumeric"
}
}, {
name: "pedido_linea_impresion_id",
type: "hidden"
@ -174,7 +186,37 @@ var editor_lineas = new $.fn.dataTable.Editor( {
var old_cantidad = 0;
editor_lineas.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_lineas.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
}
});
});
}
})
editor_lineas.on( 'preEdit', function ( e, json, data, id ) {
old_cantidad = data.cantidad;
@ -239,7 +281,7 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
{data: "pedido_linea_impresion_id"},
{data: "pedido_maquetacion_id"},
{data: "pedido_id"},
{data: "cantidad"},
{data: "cantidad",render : (d) => `<span class="autonumeric">${d}</span>`},
{
data: "descripcion",
render: function (data, type, row, meta) {
@ -324,11 +366,11 @@ var tableLineas = $('#tableOfLineasFactura').DataTable({
}
}
},
{data: "precio_unidad"},
{data: "iva"},
{data: "base"},
{data: "total_iva"},
{data: "total"},
{data: "precio_unidad",render : (d) => `<span class="autonumeric">${d}</span>`},
{data: "iva",render : (d) => `<span class="autonumeric">${d}</span>`},
{data: "base",render : (d) => `<span class="autonumeric">${d}</span>`},
{data: "total_iva",render : (d) => `<span class="autonumeric">${d}</span>`},
{data: "total",render : (d) => `<span class="autonumeric">${d}</span>`},
],
order: [[1, "asc"]],
dom: 't',

View File

@ -160,9 +160,9 @@
{ 'data': 'numero' },
{ 'data': 'fecha_factura_at' },
{ 'data': 'cliente' },
{ 'data': 'base' },
{ 'data': 'total' },
{ 'data': 'pendiente' },
{ 'data': 'base' ,render : (d) => `<span class="autonumeric">${d}</span>`},
{ 'data': 'total',render : (d) => `<span class="autonumeric">${d}</span>`},
{ 'data': 'pendiente',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'creditoAsegurado' ,
render: function(data, type, row, meta) {
switch(data){