DataTables presenting with a card view - Page 2

DataTables presenting with a card view

2»

Replies

  • hm123hm123 Posts: 75Questions: 20Answers: 1

    @gyrocode yes that css rule does work, thank you.

    But only with exportOptions { columns: [':visible'], rows: [':visible']} in the code instead of exportOptions: { rows: [':visible']}, which you seem to have given in the example, as it still copies hidden columns to the clipboard.

    I've also implemented a rough fix for the hidden thead that takes up space

    example: https://jsfiddle.net/suwznyaf/

  • bfarkasbfarkas Posts: 181Questions: 48Answers: 0

    This is awesome, and so simple in the scheme of things. Is there an easy way to control which view is shown on page load? i.e. have the table load in card view?

  • kthorngrenkthorngren Posts: 13,577Questions: 25Answers: 3,193

    Looks like you will need to add the calls cards to the table tag. The rowCallback converts to card mode if the table has the class cards.

    Kevin

  • mr.eddymamr.eddyma Posts: 1Questions: 0Answers: 0

    The example is very useful! How can make the card view in center position? Besides, how can set the card view as default mode when the page is loaded? Thanks!

  • kthorngrenkthorngren Posts: 13,577Questions: 25Answers: 3,193

    How can make the card view in center position?

    Remove the float: left from this CSS:

    .cards tbody tr {
       float: left;
       ....
    

    how can set the card view as default mode when the page is loaded?

    Add the class cards to the table tag.

    Kevin

  • gegeongegeon Posts: 3Questions: 0Answers: 0

    Hi everyone, thank you for this topic it's so helpful !!
    However, I am stuck on one thing:
    How can I get the amount of columns to adapt window's width ?
    It sounds simple but unless I refresh the page, my table width doesn't adapt.
    Just like here:
    https://ghsfha.org/datatables_cards_button.html

    But in this example, it works:
    https://web.archive.org/web/20170605170544/azguys.com/datatables/index.html

    What am I missing?

    Thanks you!

  • kthorngrenkthorngren Posts: 13,577Questions: 25Answers: 3,193
    edited January 30

    @gegeon The table looks like this:

    <table id="register" class="table table-sm table-hover" cellspacing="0">
    

    Try adding style="width:100%" as shown in this example.

    Kevin

  • gegeongegeon Posts: 3Questions: 0Answers: 0
    edited January 31

    @kthorngren
    Thanks for the prompt reply. I tried but it doesn't work, I tried adding this 100% width to every possible div and to the table but it just doesn't want to react to window resizing.

    Would any of those prevent the inline style from working?

            dom: 'tp',
            processing: true,
            displayLength: 30,
            scrollX: false,
            scrollY:2000,
            scrollCollapse: true,
            info: false,
            lengthChange: false,
            deferRender: true,
            autoWidth: false,
    
  • kthorngrenkthorngren Posts: 13,577Questions: 25Answers: 3,193
    edited January 31

    @gegeon Your example wasn't updated so I moved your code here:
    http://live.datatables.net/kesehabo/1/edit

    Added style="width:100%" to the table tag and it resizes with the web page. However there is a point where the web page width won't display all the columns so the table overflows. You can use scrollX or the Responsive extension for this.

    Kevin

  • gegeongegeon Posts: 3Questions: 0Answers: 0

    Thank you @kthorngren !!
    The above example wasn't actually my code, just a similar example, but you made me notice that I was using a previous version of css/js datatables files.
    I updated them and now it works fine =)

  • galadrianngaladriann Posts: 1Questions: 0Answers: 0
    edited April 5

    Hi All,
    Thanks to all for your great tips.. I was able to create my "simple recipe" page where I keep all my recipes :smile:
    I wanted to keep the paging so I changed the datable setup like this, in case anyone may be interested, also moved the search field to the left as I find it more convenient.

     var table = $('#register').DataTable({
                "lengthMenu": [[12, 24, 48, 96], [ 12, 24, 48, 96]], 
                dom: '<"left_filter "f><"right_length "l>rt<"bottom"lp><"clear">',
                // pageLength: -1,
                select: 'single', 
    
Sign In or Register to comment.