![Check out Enfold](https://kriesi.at/wp-content/themes/kriesi/images/banner-enfold.jpg)
-
AuthorPosts
-
June 22, 2022 at 3:20 pm #1356168
Hi,
Would it be possible to make the header row sortable? See link for example table.
June 23, 2022 at 7:02 am #1356236Hi bonsaimedia,
Yes, it’s possible however, you’ll need to use a child theme first, if you have already have a child theme, skip this step:
You can download and find instructions for it here: https://kriesi.at/documentation/enfold/child-theme/
Make sure to follow the 4 steps under Install a child theme from your WordPress dashboard.Once you have installed and activated the child theme, do the following steps:
1. Add this code in your child theme’s functions.php file (if you already have a child theme, and already had this code do not add it):/** * Add filter to add or replace Enfold ALB shortcodes with new folder contents * * Note that the shortcodes must be in the same format as those in * enfold/config-templatebuilder/avia-shortcodes * * @link http://kriesi.at/documentation/enfold/add-new-or-replace-advanced-layout-builder-elements-from-child-theme/ * * @param array $paths * @return array */ function avia_include_shortcode_template( $paths ) { if( ! is_array( $paths ) ) { $paths = array(); } $template_url = get_stylesheet_directory(); array_unshift( $paths, $template_url . '/shortcodes/' ); return $paths; } add_filter( 'avia_load_shortcodes', 'avia_include_shortcode_template', 15, 1 );
2. Go to wp-content/enfold/config-templatebuilder/avia-shortcodes/ and copy the table folder, then go to the child theme and create a new folder and name it shortcodes and paste the table folder inside it. Inside the table folder, edit table.php and go to line 486 (this is the code on that line):
'avia-data-table',
below it, add this code:
'sortable',
3. Download this file https://www.kryogenix.org/code/browser/sorttable/sorttable.js and in your child theme, create another folder called js, inside it upload the file you just downloaded.
4. Then in your child theme’s functions.php, add this code:
function add_sorttablejs() { wp_enqueue_script( 'kryogenix-sorttable', get_stylesheet_directory_uri().'/js/sorttable.js', array('jquery'), 2, true ); } add_action( 'wp_enqueue_scripts', 'add_sorttablejs', 100 );
Hope this helps.
If you need assistance, just let us know.Best regards,
NikkoJune 23, 2022 at 8:48 am #1356253Hi Nikko,
Thanks for your reply. Yes, we always use childs (offcourcse ;-)).
I will try this!Best regards
June 23, 2022 at 12:49 pm #1356283Hi bonsaimedia,
You’re welcome :)
Just let us know how it goes.Best regards,
NikkoJuly 22, 2024 at 4:23 am #1462635Hello, I would like to use this function but not on every table of the website. How can we find a way to edit css to apply to some table only?
Regards,
July 22, 2024 at 8:33 am #1462647Hi,
Thank you for the inquiry.
Edit the table where you need to apply the sort script, and apply the sortable class name in the Advanced > Developer Settings > Custom CSS Class field. Also, please note that the script will only work when Styling > Table Styling > Table Purpose is set to the second option (tabular data). Let us know how it goes.
Best regards,
IsmaelJuly 23, 2024 at 7:17 am #1462741I think the childtheme table.php is not needed as we can trigger this by giving the data table the custom class: sortable
I have tested this and there should be no problems for standard tables.
______________Unfortunately, it looks different for tables that are to be sorted by date. As long as you use standard english date formats you are probably on the safe side. Unfortunately, in Germany we like to use the dot as a separator and the month names are of course different.
So e.g. 16. Mai 1962 etc. is then not sorted correctly.here is my snippet to give to each td under a “Datum” ( my trigger heading word )
see solution on the next posting
However, this does not have the desired result either, because here too, for example, local date format entries are not taken into account. The result is that a NaN is returned for e.g. Mai / Dez etc or 16.05.2001.
Or in other words – how do we get a date field to have a sorttable_customkey attribute in the form yyyymmdd ?
and that with a given local date formate like 16. Mai 2001July 23, 2024 at 10:51 am #1462755Hi,
I think the childtheme table.php is not needed as we can trigger this by giving the data table the custom class: sortable
Yes, editing or overriding the table.php file in the child theme is not necessary. Thank you for the info.
Best regards,
IsmaelJuly 23, 2024 at 3:50 pm #1462777i solved it with the help of moment.js script ( with locale settings ):
function fix_for_sorttable(){ ?> <script> window.addEventListener("DOMContentLoaded", function () { (function($){ $('.avia-table.sortable').each(function(){ // this is the heading of the column with dates - you had to adjust to your needs var dateTableIndex = $(this).find('thead th:contains("Dat")').index(); var dateChildNumber = parseInt(dateTableIndex)+1; $(this).find('tbody td:nth-of-type('+dateChildNumber+')').addClass('date'); }); $(".date").each(function(idx) { // change the locale setting to your needed language - spcifications may occur like de_at - for austria moment.locale('de'); var datum = $(this).text(), // this is the code for my used german date format like : 16. Mai 1962 datum_formated = moment( datum , 'DD. MMMM YYYY').format('YYYY-MM-DD'); $(this).attr("sorttable_customkey", datum_formated); }); })(jQuery); }); </script> <?php } add_action('wp_footer', 'fix_for_sorttable');
the format YYYY-MM-DD is sortable
see: https://webers-testseite.de/sortable-table/July 24, 2024 at 6:11 am #1462817July 24, 2024 at 7:14 am #1462823This is only needed if you got date columns with uncommon format. Like Dots ( 10. 12. etc. Jan. Feb. ) or fullnames of the month.
I guess a normal format like 24-07-2024 could be handled without that way. -
AuthorPosts
- You must be logged in to reply to this topic.