【问题标题】:How to sort date datatable on Json如何在 Json 上对日期数据表进行排序
【发布时间】:2017-08-02 07:14:44
【问题描述】:

我有 2 个输入日期

<form id="refresh" method="post" action="income.php">
   <input type="text" id="dari" name="dari" />
   <input type="text" id="sampai" name="sampai" />
   <button type="submit">refresh</button>
</form>

对于 js:

<script>
$(document).ready(function() {
    $('#dari').datepicker({
        autoclose: true,
        format: 'yyyy-mm-dd'
    })
    $('#sampai').datepicker({
        autoclose: true,
        format: 'yyyy-mm-dd'
    })
});
</script>

所以如果我点击按钮,它只是刷新表格,日期会改变。这是我单击按钮时的 ajax,它只是刷新数据表。日期范围也会发生变化,就像我在输入 #dari#sampai 上发布的那样

<script type="text/javascript">
$(document).ready(function() {
    $('#refresh').submit(function() {
        $.ajax({
            type: 'POST',
            url: $(this).attr('action'),
            data: $(this).serialize(),
            dataType: 'json',
            success: function(status) {
                var datanya = JSON.parse(JSON.stringify(status));
                $('#income').bootstrapTable('refresh', {
                    url: '../../tables/income.php'
                });
            }
        })
        return false;
    });
})
</script>

添加整个代码income.php

<?php
header('content-type:application/json');

include '../connetion.php';
    $select=mysql_query("select nama_menu, qty, price, disc, tgl_transaksi from tb_transaksi where tgl_transaksi BETWEEN '$_POST[dari]' AND '$_POST[sampai]'");

$row=array();

while($row=mysql_fetch_array($select))
{
    $arrayx=array(  "nama_menu"=>$row['nama_menu'],
                    "qty"=>$row['qty'],
                    "price"=>$row['price'],
                    "disc"=>$row['disc']
                );

    $rows[] = $arrayx;
}

echo json_encode($rows);
?>

【问题讨论】:

    标签: javascript jquery json ajax jquery-ui


    【解决方案1】:

    您正在使用表单。如果您提交表单,它将刷新页面。而是将按钮类型设为按钮并使用该按钮的单击事件。

     <form id="refresh" method="post" action="income.php">
           <input type="text" id="dari" name="dari" />
           <input type="text" id="sampai" name="sampai" />
           <button id='ref' type="button">refresh</button>
        </form>
    
        <script type="text/javascript">
        $(document).ready(function() {
            $('#ref').click(function() {
                $.ajax({
                    type: 'POST',
                    url: $("#refresh").attr('action'),
                    data: $("#refresh").serialize(),
                    dataType: 'json',
                    success: function(status) {
                        var datanya = JSON.parse(JSON.stringify(status));
                        $('#income').bootstrapTable('refresh', {
                            url: '../../tables/income.php'
                        });
                    }
                })
                return false;
            });
        })
        </script>
    

    【讨论】:

    • 按钮单击不起作用。我在点击事件上添加了alert("a");。没有警报出现。
    • 它的工作先生.. 但引导表调用income.php 仍然没有显示数据。如果我打开手动income.php,它可以工作。但不适用于餐桌。
    猜你喜欢
    • 2020-06-04
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多