Small Screen Data-table View

****************************Jquery***********************************
$(document).ready(function () {
        var headertext = [],
    headers = document.querySelectorAll("#customDataTable th"),
    tablerows = document.querySelectorAll("#customDataTable th"),
    tablebody = document.querySelector("#customDataTable tbody");

        for (var i = 0i < headers.lengthi++) {
            var current = headers[i];
            headertext.push(current.textContent.replace(/\r?\n|\r/""));
        }
        for (var i = 0rowrow = tablebody.rows[i]; i++) {
            for (var j = 0colcol = row.cells[j]; j++) {
                col.setAttribute("data-th"headertext[j]);
            }
        }    
});

**********************CSS*******************************************

@media screen and (max-width640px) {
    table#customDataTable caption {
        background-imagenone;
    }

    table#customDataTable thead {
        displaynone;
    }

    table#customDataTable tbody td {
        displayblock;
        padding.6rem;
    }

    table#customDataTable tbody tr td:first-child {
        background#666;
        color#fff;
    }

        table#customDataTable tbody tr td:first-child a {
            color#fff;
        }

        table#customDataTable tbody tr td:first-child:before {
            colorrgb(225,181,71);
        }

    table#customDataTable tbody td:before {
        contentattr(data-th);
        font-weightbold;
        displayinline-block;
        width10rem;
    }

    table#customDataTable tr th:last-childtable#customDataTable tr td:last-child {
        max-width100% !important;
        min-width100px !important;
        width100% !important;
    }
}

Multipal Table 

function Call 

smallTable("Table ID Name");

function smallTable(id) {
            var headertext = [],
                headers = document.querySelectorAll("#" + id +" th"),
                tablerows = document.querySelectorAll("#" + id +" th"),
                tablebody = document.querySelector("#" + id +" tbody");

            for (var i = 0i < headers.lengthi++) {
                var current = headers[i];
                headertext.push(current.textContent.replace(/\r?\n|\r/""));
            }
            for (var i = 0rowrow = tablebody.rows[i]; i++) {
                for (var j = 0colcol = row.cells[j]; j++) {
                    col.setAttribute("data-th"headertext[j]);
                }
            }
        }

Comments

Popular posts from this blog

Scroll After Fixed Navigation

Bootstrap CSS Customize with SCSS CSS