lundi 18 mai 2015

Resizable columns tables with fixed header

I'm trying to create a table with resizable columns and fixed header. But when I'm trying to drag the header column, table columns change their size, but some gap is created.

For example: initial

What I get after dragging: dragged

My sample:

<script>
$(document).ready(function(){

    $('#tableHeader').colResizable({
        liveDrag: true,
        onDrag: resFun
    });


    function resFun() {
        var c1 = $('#c1').width();
        var c2 = $('#c2').width();
        var c3 = $('#c3').width();

        $('.c1').width(c1);
        $('.c2').width(c2);
        $('.c3').width(c3);

    };

    resFun();
});
</script>

<div style="padding-right: 17px; height: 39px;">
    <table class="table table-bordered" id="tableHeader" style="width: 100%; height: 39px;">
        <tr>
            <th id="c1">first</th>
            <th id="c2">second</th>
            <th id="c3">third</th>
        </tr>
    </table>
</div>
<div style="overflow: auto; height: 200px;">
    <table class="table table-bordered" id="table">
        <tr>
            <td class="c1">col 1</td>
            <td class="c2">col 2</td>
            <td class="c3">col 3</td>
        </tr>
        <tr>
            <td class="c1">col 1</td>
            <td class="c2">col 2</td>
            <td class="c3">col 3</td>
        </tr>
        <tr>
            <td class="c1">col 1</td>
            <td class="c2">col 2</td>
            <td class="c3">col 3</td>
        </tr>
        <tr>
            <td class="c1">col 1</td>
            <td class="c2">col 2</td>
            <td class="c3">col 3</td>
        </tr>
        <tr>
            <td class="c1">col 1</td>
            <td class="c2">col 2</td>
            <td class="c3">col 3</td>
        </tr>
        <tr>
            <td class="c1">col 1</td>
            <td class="c2">col 2</td>
            <td class="c3">col 3</td>
        </tr>
        <tr>
            <td class="c1">col 1</td>
            <td class="c2">col 2</td>
            <td class="c3">col 3</td>
        </tr>
        <tr>
            <td class="c1">col 1</td>
            <td class="c2">col 2</td>
            <td class="c3">col 3</td>
        </tr>
    </table>
</div>




Aucun commentaire:

Enregistrer un commentaire