[英]How to sort date datatable on Json
I have 2 input date 我有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>
and for js : 和js:
<script>
$(document).ready(function() {
$('#dari').datepicker({
autoclose: true,
format: 'yyyy-mm-dd'
})
$('#sampai').datepicker({
autoclose: true,
format: 'yyyy-mm-dd'
})
});
</script>
so how if I click button, it just refresh table, and date is change. 所以,如果我单击按钮,它只是刷新表,而日期更改。 this is my ajax when click button, it just refresh datatable. 这是我的ajax,当单击按钮时,它只是刷新数据表。 also date range change like I post on input #dari
and #sampai
日期范围也发生变化,例如我在输入#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>
Add whole code income.php 添加整个代码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);
?>
You are using a form. 您正在使用表格。 If you submit a form, it will refresh the page. 如果您提交表单,它将刷新页面。 Instead make the button type as button and use the click event of that button. 而是将按钮类型设置为按钮,并使用该按钮的click事件。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.