I have enabled the "Calculate average" setting for my columns. And I'm using the shortcode to display the average value in my page. How can I round this value to a whole number? I don't want to show the 2 decimal places.
You can use the filter wpdatatables_filter_float_cell
It will, however, be used on the whole table, not only on that shortcode.
Also, you can change it directly in the template file: wp-content/plugins/wpdatatables/templates/frontend/aggregate_functions.inc.php on line 7 you will find this:
If you go for the filter option, you will need to create a function in your functions.php file, yes. Unfortunately, I can't help you with that, as it is custom code, and is not included in the provided support for the plugin.
I can show some examples of usage of other filters:
function updateValuesBeforeSave($formData,$tableID){
//Helper method that load columns config data from DB
$columnsData = \WDTConfigController::loadColumnsFromDB($tableID);
foreach ($columnsData as $column){
if ($column->orig_header == 'name_of_the_orig_header_for_your_column') {
$formData[$column->orig_header] = 1;//we set 1 but you will replace here what ever you need
}
}
return $formData;
}
add_filter('wpdatatables_filter_formdata_before_save','updateValuesBeforeSave', 2, 10);
I hope that helps.
There's always the other way, changing the line of code in wp-content/plugins/wpdatatables/templates/frontend/aggregate_functions.inc.php on line 7
But I discovered I can achieve this by setting the "Decimal Places" to "0" in the settings here: wpDataTables > Settings > Main Settings > Decimal Places.
Hi,
I have enabled the "Calculate average" setting for my columns. And I'm using the shortcode to display the average value in my page. How can I round this value to a whole number? I don't want to show the 2 decimal places.
Thanks
Ian
Hello Ian
At the moment it cannot be done, but I have forwarded your question to one of our developers, and as soon as he responds I'll let you know.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi again Ian
You can use the filter wpdatatables_filter_float_cell
It will, however, be used on the whole table, not only on that shortcode.
Also, you can change it directly in the template file: wp-content/plugins/wpdatatables/templates/frontend/aggregate_functions.inc.php on line 7 you will find this:
So, just replace it with this:
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Thanks
So if I use the filter, it will round all the numbers in the table to a whole number? If so, that’s fine.
How do I use the filter? Do I need to write a function in the functions.php file?
Can you help me get started?
Thanks
Hi again Ian
That's right, it will not show the decimals.
If you go for the filter option, you will need to create a function in your functions.php file, yes. Unfortunately, I can't help you with that, as it is custom code, and is not included in the provided support for the plugin.
I can show some examples of usage of other filters:
Or:
I hope that helps.
There's always the other way, changing the line of code in wp-content/plugins/wpdatatables/templates/frontend/aggregate_functions.inc.php on line 7
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi,
I tried changing the line 7 in the aggregate_functions.inc.php file but it didn't change the "Average" number format. It still has 2 decimal places.
Alright, Ian
I forwarded the ticket to one of our developers, and I'll get back to you as soon as he responds.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Hi again Ian
For the table, you should change this for serverside tables:
In file wp-content/plugins/wpdatatables/assets/js/wpdatatables/wpdatatables.js on line 615 you'll find this:
Replace it with this:
For non-server-side tables, in the same file:
wp-content/plugins/wpdatatables/assets/js/wpdatatables/wpdatatables.js on line 683 you'll see this:
And replace it with this:
After that, go to wpDataTables settings/Custom JS and CSS and disable "Use minified wpDataTables Javascript", and it should work.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables
Thanks, I’ll try that.
Will I lose this customisation every time the plugin is updated?
Is there anyway to maintain the change after updating the plugin?
Hi,
Those changes didn't work either.
But I discovered I can achieve this by setting the "Decimal Places" to "0" in the settings here: wpDataTables > Settings > Main Settings > Decimal Places.
Thanks
Hi again Ian
I'm glad to hear this option works for you.
It's even better maybe, because the changes I advised would revert after updates, so you would need to do it again.
Kind Regards,
Aleksandar Vuković
[email protected]
Rate my support
wpDataTables: FAQ | Facebook | Twitter | Instagram | Front-end and back-end demo | Docs
Amelia: FAQ | Facebook | Twitter | Instagram | Amelia demo sites | Docs | Discord Community
You can try wpDataTables add-ons before purchasing on these sandbox sites:
Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables