-1

I'm use table JSon. But I have encode it from php to Json. So I just call file pin.php from tables. example my HTML tables:

HTML:

<table
    data-url="../../tables/pin.php"  
    data-row-style="rowStyle" 
    data-toggle="table" 
    data-show-refresh="true" 
    data-show-toggle="true" 
    data-show-columns="true" 
    data-search="true" 
    data-select-item-name="toolbar1" 
    data-pagination="true" 
    data-sort-name="name" 
    data-sort-order="desc">
    <thead>
        <tr>
            <th data-field="id_pin" data-sortable="true" data-align="center">ID PIN</th>
            <th data-field="no_meja" data-sortable="true" data-align="center">Nomor Meja</th>
            <th data-field="status" data-sortable="true" data-align="center">Status</th>
            <th data-field="action" data-sortable="true" data-align="center">Input Pemesanan</th>
        </tr>
    </thead>
        <tr>
        </tr>
</table>

Script table :

<script>
    $(function () {
        $('#hover, #striped, #condensed').click(function () {
            var classes = 'table';

            if ($('#hover').prop('checked')) {
            classes += ' table-hover';
            }
            if ($('#condensed').prop('checked')) {
            classes += ' table-condensed';
            }
        $('#table-style').bootstrapTable('destroy')
            .bootstrapTable({
            classes: classes,
            striped: $('#striped').prop('checked')
            });
        });
});

function rowStyle(row, index) {
    var classes = ['info', 'info', 'info', 'info', 'info'];

    if (index % 2 === 0 && index / 2 < classes.length) {
        return {
            classes: classes[index / 2]
        };
    }
return {};
}
</script>

Question: I want this table is auto refresh. please help me this one.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Dragon Chs
  • 1
  • 3
  • 11
  • I've removed the PHP from the question, as it's totally irrelevant. But I must point out that you're using an unmaintained, insecure, and deprecated database API. Put this code live and I could easily dump your entire database in about 30 seconds. Alternatives like PDO have been available for more than ten years. Use them. See http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – miken32 Feb 20 '17 at 04:53

1 Answers1

1

It looks like you're using Bootstrap Tables. According to the documentation, you can refresh the table, so just set a timer to do it periodically:

(function(){
    function refreshTable() {$('#table-style').bootstrapTable('refresh', {silent: true});}
    setInterval(refreshTable, 5000);
})()
miken32
  • 42,008
  • 16
  • 111
  • 154