我需要帮助。 我想显示数据在我选择的日期范围内。 到目前为止,这是我的代码
这是显示数据表的代码
查看
<div class="box-body">
<div class="table-responsive">
<div class="row">
<div class="col-md-4">
<div class="form-group start-date">
<label>From</label>
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right" id="start_date" name="start_date">
</div>
<!-- /.input group -->
</div>
</div>
<div class="col-md-4">
<div class="form-group end-date">
<label>To</label>
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right" id="end_date" name="end_date">
</div>
<!-- /.input group -->
</div>
</div>
<div class="col-md-2">
<div class="form-group met-cheq">
<label>Go </label>
<div class="input-group date">
<button class="btn btn-warning btn-md" name = "search" id="search">Search!</button>
</div>
<!-- /.input group -->
</div>
</div>
</div>
<table id="table-sales" class="table table-bordered table-striped">
<thead>
<tr>
<th>DR</th>
<th>Date</th>
<th>Customer</th>
<th>Price</th>
<th>Paid Amnt</th>
<th>Balance</th>
<th>Receipt</th>
<th>Remarks</th>
<th>Items</th>
<th style="width:55px;">Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($sales_inv as $inv) {
$balance = $inv->inv_price-$inv->payment;
$status = "";
$payment = $inv->payment;
if ($inv->inv_type==1) {
$status = "Department Store";
}elseif($inv->inv_type==2){
$status = "Local";
}elseif($inv->inv_type==3){
$status = "Provincial";
}elseif($inv->inv_type==4){
$status = "UNITOP";
}elseif($inv->inv_type==5){
$status = "GAISANO";
}
?>
<tr class="row-<?php echo $inv->id; ?>">
<td><a href="#" class="btn-inv-show" data-value="<?php echo $inv->inv_cno; ?>@<?php echo $inv->id; ?>"><?php echo $inv->inv_cno; ?></a></td>
<td><?php echo date("M d, Y", strtotime($inv->timestamp)); ?></td>
<td><?php echo $inv->cust_name; ?></td>
<td class="price-<?php echo $inv->inv_cno; ?>">Php <?php echo number_format($inv->inv_price,2); ?></td>
<td class="payment-<?php echo $inv->inv_cno; ?>">Php <?php echo number_format($payment,2); ?></td>
<td class="bal-<?php echo $inv->inv_cno; ?>">Php <?php echo number_format($balance,2); ?></td>
<td><?php echo $status; ?></td>
<td>
<button class="btn btn-info btn-sm btn-rem" data-value="<?php echo $inv->id; ?>">View Remarks
</button>
</td>
<td>
<button class="btn btn-success btn-sm btn-item" data-value="<?php echo $inv->inv_cno; ?>">View Item
</button>
</td>
<td>
<button class="btn btn-primary btn-xs btn-print" data-value="<?php echo $inv->inv_cno; ?>"><i class="fa fa-print"></i></button>
<button class="btn btn-warning btn-xs btn-add-pay" data-value="<?php echo $inv->inv_cno; ?>@<?php echo $inv->custid; ?>@<?php echo $inv->id; ?>"><i class="fa fa-credit-card"></i></button>
<button class="btn btn-danger btn-xs btn-edit-pay" data-value="<?php echo $inv->inv_cno; ?>@<?php echo $inv->custid; ?>@<?php echo $inv->id; ?>"><i class="fa fa-edit"></i></button>
</td>
</tr>
<?php } ?>
</tbody>
<tfooter>
<tr>
<th>DR</th>
<th>Date</th>
<th>Customer</th>
<th>Price</th>
<th>Paid Amnt</th>
<th>Balance</th>
<th>Receipt</th>
<th>Remarks</th>
<th style="width:55px;">Action</th>
</tr>
</tfooter>
</table>
</div>
<!-- /.table-responsive -->
</div>
</div>
<!-- /.box -->
</section>
<!-- right col -->
</div>
模型
public function rangeDate($start_date,$end_date){
$query = $this->db->select($this->tables['invent_inv'].'.id,'
.$this->tables['invent_inv'].'.inv_type,'.$this->tables['invent_inv'].'.inv_cno,'
.$this->tables['invent_cust'].'.id as custid,'.$this->tables['invent_cust'].'.cust_name,'
.$this->tables['invent_inv'].'.inv_price, '.$this->tables['invent_inv'].'.inv_tax,'
.$this->tables['invent_inv'].'.pay_due, SUM('.$this->tables['invent_sales'].'.paid_amnt) as payment,'
.$this->tables['invent_inv'].'.timestamp')
->join($this->tables['invent_cust'], $this->tables['invent_inv'].'.cust_id='
.$this->tables['invent_cust'].'.id','LEFT')
->join($this->tables['invent_sales'], $this->tables['invent_inv'].'.inv_cno='
.$this->tables['invent_sales'].'.inv_cno','LEFT')
->where($this->tables['invent_inv'].'.status !=', 1)
->where($this->tables['invent_inv'].'.status !=', 0)
->where($this->tables['invent_inv'].'.timestamp >=',$start_date)
->where($this->tables['invent_inv'].'.timestamp <=',$end_date)
->group_by($this->tables['invent_sales'].".inv_cno")
->group_by($this->tables['invent_inv'].".inv_cno")
->group_by($this->tables['invent_inv'].".timestamp")
->get($this->tables['invent_inv']);
return $query;
}
JS
$('#start_date').datepicker({
dateFormat: 'yy-mm-dd',
autoclose: true
})
$('#end_date').datepicker({
dateFormat: 'yy-mm-dd',
autoclose: true
})
$('#table-sales').DataTable();
现在,我的问题是我不知道要在控制器上放什么,也不知道如何在table-sales
上显示它。我不知道我输入的代码是否正确,或者是否正确。我正在使用codeigniter3x。有人可以帮我吗。
预先感谢您会帮助我的人。
答案 0 :(得分:0)
Search
按钮时调用ajax,并将开始日期和结束日期作为参数传递给ajax请求和过滤器数据。从控制器获得Ajax响应后,您可以使用带有更新数据的jquery更新tbody
表中的table-sales
。
例
假设您获得了更新数据数组
var tab_body ='';
$.each(sub_subject, function (key, value)
{
tab_body = tab_body + '<tr><td>' + value.sub_subject_name + '</td>' +
'<td>' + value.sub_subject_code + '</td>' +
'<td><div class="text-center"><button class="btn btn-primary open_edit_sub_subject_model" sub_subject_id="' + value.sub_subject_id + '" type="button" title="Edit" request_type="open_edit" subject_name="' + d.subject_name + '"><i class="fas fa-edit"></i></button>\n\
<button type="button" class="btn btn-primary subject-data-delete" title="Remove" delete_type="sub_subject" subject_group_id="' + d.subject_group_id + '" subject_id="' + d.subject_id + '" sub_subject_id="' + value.sub_subject_id + '"><i class="fa fa-trash"></i></button>\n\
</div></td>' +
'</tr>';
});
// example is just for reference
put above data in table using
$("#table-sales tbody").html(tab_body);
希望它会有所帮助。