-
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.August 2, 2024 at 6:36 am #1463589Dear Staff and members, thank you for the further explanations. I’ve managed to make my tables sortable by adding “sortable” class.
However, I’ve been dying for weeks trying to make each table self scrollable. For some reason, the header turns funny, or the body don’t match, or others weird things happens.
Please, refer to this link, first or 2nd tables is what I would like to reach. https://colorlib.com/etc/tb/Table_Fixed_Header/index.html
Any way to get such result? I’ve been trying many ways, but could never get into it, even with chatGPT supporting me.
Let’s take a table class named “fancy-table” + “sortable” as example. With 4 columns and each with custom width in %. Let’s say: 10% 20% 20% 50%.
Thank you in advance to anyone being able to solve this. Would be a huge help for me but probably for others. And perhaps a feature for future enfold versions. At least on documentation
August 2, 2024 at 9:55 am #1463608on my example page there is now both code for sortable and “fixed” table header with tbody scroll.
https://webers-testseite.de/sortable-table/
on the bottom of that page there is the example table styled layouted by Grid Layout !
this had to be only for wider screens – on responsive case all tables are ugly;August 2, 2024 at 11:10 am #1463617I see you around for years in this forum. Your contribution is awesome! Thank you very much! I’m going now to try with your code.
On your first example, there is a little “box” on the top of the scroll section. From my tests, if you set custom width for columns, that little box turns funny and take a totally random shape and size. Perhaps I did something wrong…
I’m looking to get exactly the same result as the examples I sent in here: https://colorlib.com/etc/tb/Table_Fixed_Header/index.html
But perhaps this is impossible without changing the way Enfold generates tables. From what I know, it takes a custom class at some section that enfold doesn’t automatically generates. And it’s way too hard for me to figure out how to solve that trough JS.Thank you again, will make some new tests based on your page.
Regards,August 2, 2024 at 11:41 am #1463622I just made some tests and as expected it doesn’t work. How can I share some link in private with you?
Regards,
August 2, 2024 at 12:18 pm #1463627therefor use the grid layout on that. My solution is pure css – the problem is:
if you do not have scrollbar besides heading row – and only body scrolls – then the column width are not synchronized ( that it the reason for the above flex layout – with a pseudo-container after.
having the scrollbar besides the whole table makes it much easier.August 2, 2024 at 12:19 pm #1463629send me an email – info under my nick
August 4, 2024 at 5:23 pm #1463771OK – but it looks good to me
What do you like to change on that?But apart from that, I think the days of tables are outdated. You can see from the examples of Enfold demos that responsive implementation will always remain problematic. This is always particularly noticeable with large tables like yours. Smaller tables up to 4 columns still work somehow, but after that it only remains clear on large screens.
On your example page ( https://colorlib.com/etc/tb/Table_Fixed_Header/index.html ) you can see that responsiveness is not implemented at all and that you have to scroll horizontally.
August 4, 2024 at 6:07 pm #1463777I would like to copy the same style as those in the example. Which means a proper shadow behind the table. For that I think I must reduce the % of the table but I don’t know where exactly.
Also the header should have rounded borders, and the table should have different color every each line to make it more readable.
And is there a chance to delete the lines that divide the columns?In short, reproduce what’s on the example, but in my own table, that it’s into a scrollable div, itself into a tab subpage.
I can make a jpg with a clear example of what I aim to, if needed.
August 4, 2024 at 6:20 pm #1463779then I would definitely recommend that no subheadings be accompanied by even the change of column widths.
August 4, 2024 at 6:37 pm #1463782 -
AuthorPosts
- You must be logged in to reply to this topic.