问题描述
我的数据显示如下:image of how the data & the features looks
我只想显示表格并使用图片中绿色标志上的搜索功能。但是,当我按照教程进行操作时,会显示一些功能(例如:图片中的红色和蓝色符号)。
哪里可以更改去除图片中的红色特征,将图片中的蓝色标志特征移到绿色标志上?
我仍在学习 ajax 的工作原理。对不起,如果我的解释太复杂了。但是,我希望你能理解...希望你能帮助我...
这是我在模型中使用的函数 - detkelModel.PHP:
var $table = 'detail_keluarga';
var $column_order = array('nama','hubungan','personilid','lahir',null); //set column field database for datatable orderable
var $column_search = array('nama','lahir'); //set column field database for datatable searchable just nama,hubungan,personilid,lahir are searchable
var $order = array('id' => 'desc'); // default order
private function _get_datatables_query()
{
$this->db->from($this->table);
$i = 0;
foreach ($this->column_search as $item) // loop column
{
if ($_POST['search']['value']) // if datatable send POST for search
{
if ($i === 0) // first loop
{
$this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
$this->db->like($item,$_POST['search']['value']);
} else {
$this->db->or_like($item,$_POST['search']['value']);
}
if (count($this->column_search) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
$i++;
}
if (isset($_POST['order'])) // here order processing
{
$this->db->order_by($this->column_order[$_POST['order']['0']['column']],$_POST['order']['0']['dir']);
} else if (isset($this->order)) {
$order = $this->order;
$this->db->order_by(key($order),$order[key($order)]);
}
}
function get_datatables()
{
$this->_get_datatables_query();
if ($_POST['length'] != -1)
$this->db->limit($_POST['length'],$_POST['start']);
$query = $this->db->get();
return $query->result();
}
function count_filtered()
{
$this->_get_datatables_query();
$query = $this->db->get();
return $query->num_rows();
}
public function count_all()
{
$this->db->from($this->table);
return $this->db->count_all_results();
}
<div class="navbar navbar-expand navbar-white navbar-light">
<!--left navbar / Data Keluarga label-->
<div class="col-sm-6 float-left">
<h5>Data Keluarga Personil</h5>
</div>
<!-- Right navbar links -->
<ul class="navbar-nav ml-auto">
<!-- Navbar Search,filter,plus data -->
<li class="nav-item">
<div class="form-inline">
<div class="input-group" data-widget="search-bar">
</div>
</div>
</li>
<!-- Filter Dropdown Menu -->
<li>
</li>
<!-- Plus data dropdown menu -->
<li>
<a class="btn btn-default" data-toggle="dropdown" href="#">
</a>
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
</div>
</li>
</ul>
</div>
<div class="card">
<div class="table-responsive p-0">
<table id="table" class="table table-hover text-Nowraps">
<thead>
<tr>
<th>Nama</th>
<th>id personil</th>
<th>Hubungan</th>
<th>Tanggal Lahir</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
这是我认为的脚本
<script type="text/javascript">
var save_method; //for save method string
var table;
$(document).ready(function() {
//datatables
table = $('#table').DataTable({
"processing": true,//Feature control the processing indicator.
"serverSide": true,//Feature control DataTables' server-side processing mode.
"order": [],//Initial no order.
// Load data for the table's content from an Ajax source
"ajax": {
"url": "<?PHP echo site_url('DetkelController/ajax_list') ?>","type": "POST"
},//Set column deFinition initialisation properties.
"columnDefs": [{
"targets": [-1],//last column
"orderable": false,//set not orderable
},],});
});
</script>
这是我的控制器中的 ajax_list() DetkelController.PHP:
public function ajax_list()
{
$list = $this->dk->get_datatables();
$data = array();
//$no = $_POST['start'];
foreach ($list as $dk) {
//$no++;
$row = array();
$row[] = $dk->nama;
$row[] = $dk->hubungan;
$row[] = $dk->personilid;
$row[] = $dk->lahir;
//add html for action
$row[] = '<a class="btn btn-sm btn-primary" href="javascript:void(0)" title="Edit" onclick="edit_person(' . "'" . $dk->id . "'" . ')"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
<a class="btn btn-sm btn-danger" href="javascript:void(0)" title="Hapus" onclick="delete_person(' . "'" . $dk->id . "'" . ')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],"recordsTotal" => $this->dk->count_all(),"recordsFiltered" => $this->dk->count_filtered(),"data" => $data,);
//output to json format
echo json_encode($output);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)