当前位置:网站首页>How to use layui to display the data in the database in the form of tables
How to use layui to display the data in the database in the form of tables
2022-07-01 07:48:00 【Struggling young man】
layui Native table data rendering
The premise of all the following operations is that you
Must introduce layui!
One , First write html
<body>
<div class="layui-card">
<div class="layui-card-header">
<span class="layui-breadcrumb">
<a href=""> Navigation management </a>
<a><cite> View navigation </cite></a>
</span>
</div>
<div class="layui-card-body">
<form class="layui-form" action="">
<div class="layui-inline">
<button type="button" class="layui-btn layui-btn-danger" style="margin-right: 20px;"><i class="layui-icon layui-icon-delete" style="margin-right:5px;"></i> Batch deletion </button>
<div class="layui-input-inline" style="width: 200px;">
<input type="text" placeholder=" Please enter the search content " autocomplete="off" class="layui-input">
</div>
<button type="button" class="layui-btn"><i class="layui-icon layui-icon-search" style="margin-right:5px;"></i> Search for </button>
</div>
</form>
<!-- Here is the table label -->
<table class="layui-table tableRender"></table>
</div>
</div>
</body>
Be careful : The content of the table label here is empty .
Two , Introduce... Into the page js file , The content is :
layui.use(['element', 'table'], function () {
var {
element, table } = layui
table.render({
elem: '.tableRender',
url: "/admin/nav/query", // Interface for back-end data transmission
cols: [[ // Header
{
field: "nav_id", title: 'ID', width: 80, sort: true, fixed: 'left' },
{
field: 'nav_name', title: ' Navigation name ' },
{
field: 'nav_alias', title: ' Navigation alias ' },
{
field: 'nav_sort', title: ' Navigation sort ' },
{
field: 'nav_is_show', title: ' Whether to show ' },
{
field: '', title: ' operation ' },
]],
page: true
});
});
introduce
tablemodular , And deconstruct the assignment .
3、 ... and , Write back-end data interface , By querying the database , To return data
// View navigation page data
router.get("/query", (req, res) => {
const sql = "SELECT * FROM nav;"
db.query(sql, (err, results) => {
if (err) {
return res.send({
code: 1,
msg: err.msg
})
}
if (results.length) {
return res.send({
code: 0,
msg: " Data query successful ",
data: results,
count: 12, // Here is the total number of records
})
} else {
return res.send({
code: 1,
msg: " Data information query failed "
})
}
})
})
Write the interface in the corresponding route , The returned data should be in accordance with
layui The requirements ofto , See the official documents for details .Back end data interface routing uses
express.jsbuild .Used
mysql2modular , Realize database interaction . theredbIs the encapsulated module , Use by introduction , I won't go into details here .
Four , Page rendering successful


Here's just a door for everyone , Want more advanced usage , You can go to the official documents to check .
边栏推荐
- Conscience Amway universal wheel SolidWorks model material website
- Gru of RNN
- Array: question brushing record
- 力扣——求一组字符中的第一个回文字符
- Eigen matrix operation Library
- kubernetes资源对象介绍及常用命令(二)
- 【mysql学习笔记27】存储过程
- 2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation
- redisson使用全解——redisson官方文档+注释(下篇)
- [microservice openfeign] feign's log record
猜你喜欢

热烈祝贺五行和合酒成功挂牌
![[target detection] yolov5, the shoulder of target detection (detailed principle + Training Guide)](/img/47/80d2e92ea7347cc5c7410194d5bf2e.png)
[target detection] yolov5, the shoulder of target detection (detailed principle + Training Guide)

Illusory and simple screen raindrop post-processing effect

Todolist classic case ①

I bet on performance and won the CTO of the company. I want to build Devops platform!

redisson使用全解——redisson官方文档+注释(中篇)

关系数据库如何工作

继妹变继母,儿子与自己断绝关系,世界首富马斯克,为何这么惨?

【Flutter 问题系列第 72 篇】在 Flutter 中使用 Camera 插件拍的图片被拉伸问题的解决方案

浅谈CVPR2022的几个研究热点
随机推荐
Félicitations pour l'inscription réussie de wuxinghe
redisson使用全解——redisson官方文檔+注釋(上篇)
【mysql学习笔记25】sql语句优化
华泰证券开户是安全可靠的么?怎么开华泰证券账户
【编程强训】删除公共字符(哈希映射)+组队竞赛(贪心)
Gru of RNN
【mysql学习笔记28】存储函数
Saving db4i depth camera pictures with MATLAB
【编程强训2】排序子序列+倒置字符串
Subclasses call methods and properties of the parent class with the same name
ctfshow-web352,353(SSRF)
She is the "HR of others" | ones character
力扣每日一题-第31天-1790.仅执行一次字符串交换能否使两个字符串相等
The database is locked. Is there a solution
Redisson uses the full solution - redisson official documents + comments (Part 2)
TodoList经典案例①
2022 mobile crane driver test exercises and online simulation test
[programming training 2] sorting subsequence + inverted string
Mysql与Redis一致性解决方案
力扣每日一题-第31天-202.快乐数