• Hi,

    I am using the great CFDB plugin. I want to show the columns of a table in a certain order using a datatable, is there any way to do this? I am making a custom shortcode but I wonder if there is some way to use a datatable directly instead of buildin it with html in PHP.

    I am currently doing this which is a little bit cumbersome:

    echo("<table class='cf7-db-table dataTable' style='margin-left: 0px; width: 4364px;'>") ;

    Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    In the shortcode, using “show” you can list the columns you want to see in order.
    [cfdb-datatable form=”your-form-name” show=”column2,column1,column5″]

    If you are doing this in PHP, you can call “do_shortcode”.

    Thread Starter gabig

    (@gabig)

    First of all, thanks Michael. This must be the most stupid question ever asked on the forums. I fell ashamed. I made one test and probably misspelled a column name. Anyway I give you a link and a function that it maybe useful for other cases. It is a jquery code that does the same but it has a big flaw. The columns widths that you change stay the same so the headers and the rows below may not have the same width. What I’ve done is give them an exact width as a workaround.

    
    //switchColum 24 to 1 and 1 to 24
    $('#myid').switchColumns( 1, 24 );
    //switchColum 24 to 1 and 2 to 25
    
    $.fn.switchColumns = function ( col1, col2 ) {
        var $this = this,
            $tr = $this.find('tr');
        $tr.each(function(i, ele){
            var $ele = $(ele),
            $th = $ele.find('th'),
            $tht;
            $tht = $th.eq( col1 ).clone();
            $th.eq( col1 ).html( $th.eq( col2 ).html() );
            $th.eq( col2 ).html( $tht.html() );
     $th.css( {"max-width": "110px", "min-width": "110px"}) ; 
            var $ele = $(ele),
            $td = $ele.find('td'),
            $tdt;
            $tdt = $td.eq( col1 ).clone();
            $td.eq( col1 ).html( $td.eq( col2 ).html() );
            $td.eq( col2 ).html( $tdt.html() );
        });
    };

    Credits go to this thread:https://stackoverflow.com/questions/5464219/change-table-columns-order

    Now I have to create a page that shows the forms of the table in a form when you click on the Submitted column. But that’s another story ??

    Again, many thanks for answering

    • This reply was modified 8 years, 3 months ago by gabig.
    Plugin Author Michael Simpson

    (@msimpson)

    This may be helpful to you for your next step: https://cfdbplugin.com/?page_id=1389

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Order of columns’ is closed to new replies.