DataTables presenting with a card view - Page 2

DataTables presenting with a card view

2»

Replies

  • hm123hm123 Posts: 80Questions: 23Answers: 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: 19,125Questions: 26Answers: 4,534

    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: 19,125Questions: 26Answers: 4,534

    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: 19,125Questions: 26Answers: 4,534
    edited January 2021

    @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 2021

    @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: 19,125Questions: 26Answers: 4,534
    edited January 2021

    @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 2021

    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', 
    
  • DA84DA84 Posts: 3Questions: 1Answers: 0

    Hi,

    very new to CSS/styling. How can I make this the default view?

  • Loren MaxwellLoren Maxwell Posts: 365Questions: 88Answers: 9

    @DA84, just includes the cards class in your table from the start.

  • sakissakis Posts: 1Questions: 0Answers: 0

    Hi everyone,
    congratulations on a great job of presenting data in card view. It really works great!
    I will add some code to improve the project as well.

    How can make the card view in center position?

    Just add into the buttons action function this code $("tbody").toggleClass("row").toggleClass("justify-content-center");

    var table = $('#register').DataTable({
                    dom: 'fBti',
                    pageLength: -1,
                    buttons: [
                        {
                            text: '<i class="fa fa-id-badge fa-fw fa-lg" aria-hidden="true"></i>',
                            className: 'animated bounce',
                            action: function () {
                                // Add
                                $("tbody").toggleClass("row").toggleClass("justify-content-center");
    
                                $("#register").toggleClass("cards");
                                $("#register thead").toggle();
                                $("#card-toggle .fa").toggleClass("fa-table");
                                $("#card-toggle .fa").toggleClass("fa-id-badge");
    

    If you have added class cards in table to make card view the default mode, you have also to add manually the above classes to tbody

    <tbody class="row justify-content-center">
    </tbody>
    

    https://live.datatables.net/mirazamo/1/edit

    Enjoy, thanks!

  • allanallan Posts: 59,793Questions: 1Answers: 9,680 Site admin

    Clever solution with the Bootstrap classes - like it!

    Allan

Sign In or Register to comment.