1

1. Summary

I don't find, how I can shrink a table, if it really needed:

    if a table not fully displayed and horizontal scrollbar appear.


2. Limitation

I have a static site. It would be nice any solutions for JavaScript include JQuery, Bootstrap or another libraries; but not solutions for dynamic sites.


3. Example

Table on Repl.it:

index.html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8"/>
        <title>
            Document
        </title>
        <script src="//cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js" defer></script>
        <!-- https://fooplugins.com/footable-jquery/documentation/ -->
        <!-- http://fooplugins.github.io/FooTable/docs/examples/basic/single-header.html -->
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-footable/3.1.6/footable.min.js" defer></script>
        <script src="footable.js" defer></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-footable/3.1.6/footable.core.standalone.min.css"/>
    </head>
    <body>
        <div class="justtable">
            <table class="table">
                <thead>
                    <tr>
                        <th>
                            No.
                        </th>
                        <th data-breakpoints="x-small">
                            Name
                        </th>
                        <th data-breakpoints="x-small">
                            Town
                        </th>
                        <th data-breakpoints="x-small">
                            Quality of work
                        </th>
                        <th data-breakpoints="x-small">
                            Characteristics
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>
                            1
                        </td>
                        <td>
                            Kira
                        </td>
                        <td>
                            Velikiy Novgorod
                        </td>
                        <td>
                            Great
                        </td>
                        <td>
                            You're one in a million, You're once in a lifetime, You made me discover one of the stars above us, You're one in a million
                        </td>
                    </tr>
                    <tr>
                        <td>
                            2
                        </td>
                        <td>
                            Sasha
                        </td>
                        <td>
                            Kazan
                        </td>
                        <td>
                            Amazing
                        </td>
                        <td>
                            Sometimes, Love can hit You everyday, Sometimes, You can fall for everyone you see, But only One can really make me stay, The sign, the one in the sky, has said to me
                        </td>
                    </tr>
                    <tr>
                        <td>
                            3
                        </td>
                        <td>
                            Nervov
                        </td>
                        <td>
                            Saint-Petersburg
                        </td>
                        <td>
                            Beautiful
                        </td>
                        <td>
                            I always will remember how I felt that day, A feeling indescribable to me, yeah, I always knew there was an answer for my prayer, And You, You're the One, the One for me
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </body>
</html>

footable.js:

jQuery(function($) {
    $('.table').footable({
        "breakpoints": {
            "x-small": 200,
            "small": 300
        }
    });
});

4. Details

  1. I have a table:

    Non-expanded

  2. I open a table on a mobile device with small screen → not all table display, I see horizontal scrollbar:

    Horizontal scrollbar

  3. But some plugins can shrink a table for small screens:

    Responsive


5. Responsive plugins algorithm

For breakpoint == 800px:

if screen size > breakpoint

    table not shrink

else:

    table shrink

5.1. Problem of plugins algorithm

If small breakpoint value:

    not all table display as in 4.2 item of this question.

else big breakpoint value:

    small tables shrink on big screens. This is inconvenient for users.


6. Expected behavior

If full table display on screen:

    table not shrink

else not full table display as in 4.2 item of this question:

    table shrink

Can I get similar behavior?


7. Not helped

7.1. table-layout: fixed

As in this answer:

table {
    table-layout: fixed;
}

Behavior on small screens:

Small screens

Problems:

  1. Words go beyond cells and screen
  2. Small cells size

7.2. Plugins as FooTable

I try some plugins for responsive tables creating. I get behavior as in 5.1.1 item of this answer. Fixed px breakpoint used in these plugins:

7.3. Plugins as DataTable

I try some plugins, that hide, not shrink on small screens data of tables.

Example:

For RWD-Table-Patterns demo:

  • Big screen — 8 rows:

RWD-Big-screen-table

  • Small screen — 2 rows display fully, 1 — partially:

RWD-Small-screen-table

I have this behavior for these plugins:


8. Do not offer

  1. Yes, I know about overflow-x: auto. This is not entirely on the topic of this question.
Саша Черных
  • 2,561
  • 4
  • 25
  • 71
  • Are you looking for something like this: https://css-tricks.com/examples/ResponsiveTables/responsive.php? – Jonathan Rys May 10 '18 at 13:40
  • @JonathanRys, **answer**: yes, but without exactly breakpoints (media-queries). I've open source of page by your link → possibly, table have behavior, similar as in my example. See 3, 5 and 7.2 items of my question for more details. Thanks. – Саша Черных May 10 '18 at 13:48
  • Why don't you want to use media queries? And is a table the best way to display your data in the first place? Tables are notoriously difficult to make responsive so if you can come up with a better way to visualize the data (like note-cards) that might be an even better solution. – Jonathan Rys May 10 '18 at 13:54
  • @JonathanRys, `Why don't you want to use media queries?` — please, read 3—6 items of my question. For example, try [**my example**](https://sasharesponsivewithoutbreakpoints-footable--kristinita.repl.co/) with media queries in screens with 301—380px width. Thanks. – Саша Черных May 10 '18 at 14:02
  • Using the media query in the link I posted originally https://css-tricks.com/responsive-data-tables/ seems to make it work >= 250px. What is the smallest screen size you're supporting? – Jonathan Rys May 10 '18 at 14:34
  • By "shrink a table" do you mean collapse? Because that can be achieved with media queries as well. – Jonathan Rys May 10 '18 at 14:36

0 Answers0