php - 如何在控制器codeigniter中添加菜单以升序和降序排序?
问题描述
内容我的控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class AutoLoadDiv extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('ngoding/AutoLoad');
}
public function getData() {
$this->load->library('table');
$err = file_get_contents("application\logs\log.php");
$filestr = preg_replace(array('/(^|\R)ERROR\s*-\s*/', '/(^|\R)(.*?)\s*-->\s*/'), array('$1', '$1$2 '), $err);
$arraySpacing = nl2br($filestr);
$arr = explode("\n", $arraySpacing);
$output = '<style> th, td {text-align: left; padding: 10px;} tr:nth-child(even){background-color#FFF;} tr:nth-child(odd){background-color:#CCC;} </style>';
$output .= '<table border="1px solid #dddddd;" >';
$output .= '<tr><th>Date</th><tr>';
for ($i = count($arr)-1; $i >= 0; $i--) {
$output.="<tr><td>$arr[$i]</td></tr>";
}
$output.="</table>";
echo $output;
}
}
尝试实现 Datatables 但无法正常工作后,此处的代码视图
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js">
<script>
$(document).ready(function(){
setInterval(function(){
$("#table").load('AutoLoadDiv/getData')
}, 5000);
});
</script>
<style>
</style>
<title>Auto Load Page in Div using Jquery</title>
</head>
<body>
<h1>Auto Load Page in Div</h1>
<div id="content">Please wait....</div>
<div class="container">
<table id="table" class="display" cellspacing="0" width="100%">
<tr>
<th>Date</th>
</tr>
</table>
</div>
<script type="text/javascript">
var table;
table = $(document).ready(function() {
//datatables
table = $('#table').DataTable({
"processing": true,
"serverSide": true,
"order": [],
"ajax": {
"url": "<?php echo site_url('AutoLoadDiv/getData')?>",
"type": "POST"
},
"columnDefs": [
{
"targets": [ 0 ],
"orderable": false,
},
],
});
});
</script>
</body>
</html>
在我实现数据表之后,结果视图如下:
我在实现我的代码以使菜单像下拉菜单那样像这个例子一样升序和降序时遇到问题:https : //ibb.co/chO2Bz,我想在控制器中实现html asc和dsc,而不是在视图中,如果我点击那个菜单是升序排序,如果再次单击该菜单是降序排序?
解决方案
推荐阅读
- angular - 如何在 Angular 7 中运行 e2e 测试?
- php - Laravel 5 运行队列:按 laravel 时间表工作
- kotlin - mockk 验证 lambda 参数
- angular - 如何将 DomSanitizer 作为打字稿中的参数传递给管道?
- typescript - 编辑动态添加的输入字段的值
- ruby - 清除开罗的当前路径
- cloud-foundry - 来自cli的PCF登录问题
- google-cloud-platform - 使用 gcsfuse 同步存储桶后性能下降
- angular - 如何使用 @angular/elements 扩展 HTMLButtonElement
- spring - 使用 Cassandra 自行引用的用户定义类型