代码拉取完成,页面将自动刷新
目前layui+php后台,在启用layui-soul-table插件后,若开启自带page:true,则无法执行筛选。
page:false则可以正常执行筛选。
前端:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>debug</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link href="./layui-soul-table-master/layui/css/layui.css" rel="stylesheet">
<link href="./layui-soul-table-master/soulTable.css" rel="stylesheet" />
<style>
.layui-table-cell {
height: 25px;
line-height: 15px;
padding-left:1px;
padding-right:1px;
}
.layui-table td{
font-size: 12px;
}
</style>
</head>
<body>
<table id="myTable" ></table>
<script type="text/html" id="toolbar">
<div><button class="layui-btn layui-btn-sm" lay-event="clearFilter">清除所有筛选条件</button></div>
</script>
<script type="text/html" id="bar">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="./layui-soul-table-master/layui/layui.js"></script>
<table id="myTable2" lay-filter="myTable2"></table>
<script>
layui.config({
base: 'layui-soul-table-master/ext/', // 模块目录
version: 'v1.8.0'
}).extend({ // 模块别名
soulTable: 'soulTable',
shortcut: 'shortcut',
tableChild: 'tableChild',
tableMerge: 'tableMerge',
tableFilter: 'tableFilter',
excel: 'excel'
});
layui.use(['jquery','form', 'table','soulTable','tableFilter'], function () {
var table = layui.table,
soulTable = layui.soulTable,
tableFilter = layui.tableFilter;
table.render({
elem: '#myTable2'
,url: './data1.php'
,height: 500
,page:false
,cols: [[
{field: 'id', title: 'ID', width: 200, sort: true, filter: true},
{field: 'author', title: '作者', width: 165 , filter: true},
{field: 'content', title: '内容', width: 123, filter: true},
{field: 'type', title: '类型', width: 112, filter: {split:','}, sort:true},
{field: 'heat', title: '点赞数', width: 112, filter: true, sort:true},
{field: 'date', title: '录入时间', width: 165, filter: {type: 'date[yyyy-MM-dd HH:mm:ss]'}, sort:true},
]]
,done: function () {
soulTable.render(this)
}
});
})
</script>
</body>
</html>
php后台data1.php:
<?php
header('Content-type:text/html;charset=utf-8');
// 连接数据库
require './untils/db_conn.php';
if (isset($_GET['page']) && isset($_GET['limit'])) {
// 分页查询
$start = ($_GET['page'] - 1) * $_GET['limit'] ;
$limit = $_GET['limit'];
//查询条件
$sn = isset($_GET['name']) ? $_GET['name']:"%"; //where 条件,%模糊查询
$data = $pdo->query("SELECT * FROM table1 order by id desc limit $start, $limit")->fetchAll(PDO::FETCH_ASSOC);
$num = count($pdo->query("SELECT id FROM table1")->fetchAll(PDO::FETCH_ASSOC));
$json = json_encode(array(
"code" => 0,
"msg" => "",
"count" => $num,
"data" => $data
), JSON_UNESCAPED_UNICODE);
echo $json;
}elseif (isset($_GET['action']) && $_GET['action'] == 'del') {
$clean = array();
$clean['id'] = isset($_POST['id']) ? $_POST['id'] : '这个是数据库id';
$del = $pdo->exec("DELETE FROM table1 WHERE id='{$clean['id']}'");
if($del >0 ){
echo json_encode(array(
"code" => 1,
"msg" => "success",
"count" => $del,
"data" => array()
));
}else{
echo json_encode(array(
"code" => 1,
"msg" => "error",
"count" => 0,
"data" => array()
));
}
}else {
// 无参数
echo json_encode(array(
"code" => 1,
"msg" => "error",
"count" => 0,
"data" => array()
));
}