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

@ -312,7 +312,8 @@ id = -1;
{name: "id",
"type": "readonly"},
{
name: "tiempo_min"
name: "tiempo_min",
}, {
name: "tiempo_max"
}, {
@ -512,7 +513,12 @@ id = -1;
class :"autonumeric"
}
}, {
name: "precio_min"
name: "precio_min",
attr: {
type: "text",
name : "precio_min",
class :"autonumeric"
}
}, {
name: "paginas_libro_max",
attr: {
@ -521,11 +527,26 @@ id = -1;
class :"autonumeric"
}
}, {
name: "precio_max"
name: "precio_max",
attr: {
type: "text",
name : "precio_min",
class :"autonumeric"
}
}, {
name: "total_min"
name: "total_min",
attr: {
type: "text",
name : "total_min",
class :"autonumeric"
}
}, {
name: "margen"
name: "margen",
attr: {
type: "text",
name : "margen",
class :"autonumeric"
}
}, {
"name": "tirada_encuadernacion_id",
"type": "hidden"
@ -552,7 +573,8 @@ id = -1;
new AutoNumeric(this, {
alwaysAllowDecimalCharacter: true,
decimalCharacter: ",",
decimalPlaces : 0,
decimalPlaces : 2,
allowDecimalPadding : 'floats',
digitGroupSeparator: ".",
unformatOnSubmit : true,
});
@ -628,11 +650,11 @@ decimalPlaces : 0,
},
},
{ 'data': 'paginas_libro_min',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'precio_max' },
{ 'data': 'precio_max',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'paginas_libro_max',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'precio_min' },
{ 'data': 'total_min' },
{ 'data': 'margen' },
{ 'data': 'precio_min',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'total_min',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'margen' ,render : (d) => `<span class="autonumeric">${d}</span>`},
{
data: actionBtns,
className: 'row-edit dt-center'
@ -702,14 +724,7 @@ decimalPlaces : 0,
}
);
} );
theTable.on('draw',() => {
AutoNumeric.multiple("span.autonumeric", {
digitGroupSeparator: ".",
decimalCharacter: ",",
decimalPlaces : 0,
unformatOnSubmit: true
});
})
// Delete row
function remove_lineas(dataId, row){
@ -754,11 +769,26 @@ decimalPlaces : 0,
name: "proveedor_id",
"type": "select"
}, {
name: "tirada_min"
name: "tirada_min",
attr: {
type: "text",
name : "tirada_min",
class :"autonumeric"
}
}, {
name: "tirada_max"
name: "tirada_max",
attr: {
type: "text",
name : "tirada_max",
class :"autonumeric"
}
}, {
name: "importe_fijo"
name: "importe_fijo",
attr: {
type: "text",
name : "importe_fijo",
class :"autonumeric"
}
}, {
"name": "tarifa_encuadernacion_id",
"type": "hidden"
@ -780,7 +810,37 @@ decimalPlaces : 0,
const suppliersList = <?php echo json_encode($proveedores); ?>;
editor2.field( 'proveedor_id' ).update( suppliersList );
editor2.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,
});
})
})
editor2.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
}
});
});
}
})
editor2.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
d.data[0]['tarifa_encuadernacion_id'] = id;
@ -838,9 +898,9 @@ decimalPlaces : 0,
return value['label'];
},
},
{ 'data': 'tirada_min' },
{ 'data': 'tirada_max' },
{ 'data': 'importe_fijo' },
{ 'data': 'tirada_min',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'tirada_max',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'importe_fijo',render : (d) => `<span class="autonumeric">${d}</span>` },
{
data: actionBtns,
className: 'row-edit dt-center'

View File

@ -182,7 +182,12 @@
}, {
name: "cp_final"
}, {
name: "importe_fijo"
name: "importe_fijo",
attr: {
type: "text",
name : "importe_fijo",
class :"autonumeric"
}
}, {
"name": "tarifa_envio_id",
"type": "hidden"
@ -195,7 +200,37 @@
},
]
} );
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
}
});
});
}
})
editor.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
@ -255,7 +290,7 @@
{ 'data': 'nombre' },
{ 'data': 'cp_inicial' },
{ 'data': 'cp_final' },
{ 'data': 'importe_fijo' },
{ 'data': 'importe_fijo',render : (d) => `<span class="autonumeric">${d}</span>` },
{
data: actionBtns,
className: 'row-edit dt-center'
@ -346,18 +381,48 @@ const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
name: "tipo_envio",
"type": "select"
}, {
name: "peso_min"
name: "peso_min",
attr: {
type: "text",
name : "peso_min",
class :"autonumeric"
}
}, {
name: "peso_max"
name: "peso_max",
attr: {
type: "text",
name : "peso_max",
class :"autonumeric"
}
}, {
name: "precio_min"
name: "precio_min",
attr: {
type: "text",
name : "precio_min",
class :"autonumeric"
}
}, {
name: "precio_max"
name: "precio_max",
attr: {
type: "text",
name : "precio_max",
class :"autonumeric"
}
}, {
name: "precio_adicional",
def: 0
def: 0,
attr: {
type: "text",
name : "precio_adicional",
class :"autonumeric"
}
}, {
name: "margen"
name: "margen",
attr: {
type: "text",
name : "margen",
class :"autonumeric"
}
}, {
"name": "tarifa_envio_id",
"type": "hidden"
@ -370,7 +435,37 @@ const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
},
]
} );
editor2.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,
});
})
})
editor2.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
}
});
});
}
})
// Generación de la lista de proveedores (id, nombre)
const suppliersList = <?php echo json_encode($proveedores); ?>;
editor2.field( 'proveedor_id' ).update( suppliersList );
@ -455,12 +550,12 @@ const lastColNr2 = $('#tableOfPrecios').find("tr:first th").length - 1;
return '<?= lang('TarifasEnviosPrecios.palets') ?>';
}
},
{ 'data': 'peso_min' },
{ 'data': 'peso_max' },
{ 'data': 'precio_min' },
{ 'data': 'precio_max' },
{ 'data': 'precio_adicional' },
{ 'data': 'margen' },
{ 'data': 'peso_min',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'peso_max',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'precio_min',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'precio_max',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'precio_adicional',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'margen',render : (d) => `<span class="autonumeric">${d}</span>` },
{
data: actionBtns,
className: 'row-edit dt-center'

View File

@ -33,10 +33,15 @@
<?= esc($item->code) ?>
</td>
<td class="align-middle">
<?= esc($item->precio) ?>
<span class="autonumeric">
<?= esc($item->precio) ?>
</span>
</td>
<td class="align-middle">
<?= esc($item->margen) ?>
<span class="autonumeric">
<?= esc($item->margen) ?>
</span>
</td>
<td class="align-middle">
<?= esc($item->mostrar_en_presupuesto)==1?'<i class="ti ti-check"></i>':"" ?>

View File

@ -122,18 +122,33 @@
class :"autonumeric"
}
}, {
name: "precio_max"
name: "precio_max",
attr: {
type: "text",
name : "tirada_min",
class :"autonumeric"
}
}, {
name: "tirada_max",
attr: {
type: "text",
name : "tirada_max",
class :"autonumeric"
type: "text",
name : "tirada_max",
class :"autonumeric"
}
}, {
name: "precio_min"
name: "precio_min",
attr: {
type: "text",
name : "tirada_min",
class :"autonumeric"
}
}, {
name: "margen"
name: "margen",
attr: {
type: "text",
name : "tirada_min",
class :"autonumeric"
}
}, {
"name": "tarifa_manipulado_id",
"type": "hidden"
@ -147,35 +162,38 @@
]
} );
editor.on('open',(event)=>{
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if(autoNumericInstance){
autoNumericInstance.remove()
editor.on('open', (event) => {
$("input.autonumeric").each(function () {
let autoNumericInstance = AutoNumeric.getAutoNumericElement(this)
if (autoNumericInstance) {
autoNumericInstance.remove()
}
new AutoNumeric(this, {
decimalCharacter: ",",
decimalPlaces : 0,
digitGroupSeparator: ".",
unformatOnSubmit : true,
});
})
}
new AutoNumeric(this, {
decimalCharacter: ",",
digitGroupSeparator: ".",
allowDecimalPadding : 'floats',
decimalPlaces: 2,
unformatOnSubmit: true,
});
})
editor.on( 'preSubmit', function ( e, d, type ) {
})
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)
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.on( 'preSubmit', function ( e, d, type ) {
if ( type === 'create'){
d.data[0]['tarifa_manipulado_id'] = id;
@ -224,10 +242,10 @@
}),
columns: [
{ 'data': 'tirada_min',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'precio_max', },
{ 'data': 'precio_max',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'tirada_max',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'precio_min' },
{ 'data': 'margen' },
{ 'data': 'precio_min',render : (d) => `<span class="autonumeric">${d}</span>` },
{ 'data': 'margen',render : (d) => `<span class="autonumeric">${d}</span>` },
{
data: actionBtns,
className: 'row-edit dt-center'
@ -284,14 +302,7 @@
);
} );
theTable.on('draw',() => {
AutoNumeric.multiple("span.autonumeric", {
digitGroupSeparator: ".",
decimalCharacter: ",",
decimalPlaces : 0,
unformatOnSubmit: true
});
})
// Delete row
$('#tableOfTarifamanipuladolineas').on( 'click', 'tbody span.remove', function (e) {

View File

@ -33,10 +33,14 @@
<?= esc($item->code) ?>
</td>
<td class="align-middle">
<?= esc($item->precio) ?>
<span class="autonumeric">
<?= esc($item->precio) ?>
</span>
</td>
<td class="align-middle">
<?= esc($item->margen) ?>
<span class="autonumeric">
<?= esc($item->margen) ?>
</span>
</td>
<td class="align-middle">
<?= esc($item->mostrar_en_presupuesto)==1?'<i class="ti ti-check"></i>':"" ?>