Tagged: ,

Viewing 21 posts - 1 through 21 (of 21 total)
  • Author
    Posts
  • #1356168

    Hi,

    Would it be possible to make the header row sortable? See link for example table.

    #1356236

    Hi 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,
    Nikko

    #1356253

    Hi Nikko,

    Thanks for your reply. Yes, we always use childs (offcourcse ;-)).
    I will try this!

    Best regards

    #1356283

    Hi bonsaimedia,

    You’re welcome :)
    Just let us know how it goes.

    Best regards,
    Nikko

    #1462635

    Hello, 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,

    #1462647

    Hi,

    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,
    Ismael

    #1462741

    I 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 2001

    #1462755

    Hi,

    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,
    Ismael

    #1462777

    i 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/

    #1462817

    Hi,


    @Guenni007
    : Thank you for the info.

    Best regards,
    Ismael

    #1462823

    This 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.

    #1463589

    Dear 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

    #1463608

    on 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;

    #1463617

    I 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,

    #1463622

    I just made some tests and as expected it doesn’t work. How can I share some link in private with you?

    Regards,

    #1463627

    therefor 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.

    #1463629

    send me an email – info under my nick

    #1463771

    OK – 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.

    #1463777

    I 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.

    #1463779

    then I would definitely recommend that no subheadings be accompanied by even the change of column widths.

    #1463782
Viewing 21 posts - 1 through 21 (of 21 total)
  • You must be logged in to reply to this topic.