0

I have a table that needs to be changed in mobile view. I hide some columns with jquery for smaller devices but i also need to get content in column 2 to jump into column 1 for mobile devices.

Example table:

Desktop: content col1 | content col 2

Mobile: content col1 |content is now in col 1 and this empty col 2 must be hidden content col2 |

(Its a bootstrap page)

user2986959
  • 135
  • 2
  • 10
  • can you add a class to column, and within your css, hide this class through media query ? take a look at this: http://stackoverflow.com/questions/11796297/div-show-hide-media-query – user2346536 Aug 28 '14 at 07:55
  • How about creating a [bootply](http://bootply.com) or fiddle with your code? – Carol Skelly Aug 28 '14 at 13:34
  • 1
    Good idea @Skelly here it is: [Bootply example](http://www.bootply.com/KyRGD2YfZ3) – user2986959 Aug 28 '14 at 18:10

2 Answers2

0

Perform once on page load (not on resize!):

// if mobile device
$('#column1').append($('#column2').html());
$('#column2').remove();
Alex Salauyou
  • 14,185
  • 5
  • 45
  • 67
0

Try this:

HTML:

 <div class="col-md-12">
        <div class="row col-md-6">
            <table class="table table-striped table-condensed">
                <thead>
                    <tr>
                        <th>th is 0</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>cell is row 0, column 0</td>
                    </tr>
                    <tr>
                        <td>cell is row 1, column 0</td>
                    </tr>
                </tbody>
            </table>


            <div id="content1">
            </div>
        </div>
        <div id="col2" class="row col-md-6">
            <table class="table table-striped table-condensed">
                <thead>
                    <tr>
                        <th>th is 1</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>cell is row 0, column 1</td>
                    </tr>
                    <tr>
                        <td>cell is row 1, column 1</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

SCRIPT:

$(window).resize(function () {
            Check();
        });
        $(document).ready(function () {
            Check();
        });


        function Check() {
            var contenbody = $('body');
            var ScreenWidth = screen.width;
            var clientWidth = contenbody[0].clientWidth;
            if ((ScreenWidth < 1200) || (clientWidth < 990)) {
                var data = $("#col2").html();
                $("#col2").hide();
                $("#content1").show();
                $("#content1").empty();
                $("#content1").append(data);
            } else {
                $("#col2").show();
                $("#content1").hide();
            }
        }
Suganth G
  • 5,136
  • 3
  • 25
  • 44
  • Actually this is the case:
    th is 0th is 1
    cell is row 0, column 0cell is row 0, column 1
    cell is row 1, column 0cell is row 1, column 1
    – user2986959 Aug 28 '14 at 10:35
  • Thanks, but it looks strange when i use the code at this example: http://www.bootply.com/render/KyRGD2YfZ3 – user2986959 Aug 29 '14 at 06:43