当前位置:网站首页>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 .
边栏推荐
- Alibaba OSS postman invalid according to policy: policy condition failed: ["starts with", "key", "test/"]
- Eigen矩阵运算库快速上手
- IMDB practice of emotion classification (simplernn, LSTM, Gru)
- Long way to go with technology
- How relational databases work
- The computer has a network, but all browser pages can't be opened. What's the matter?
- 熱烈祝賀五行和合酒成功掛牌
- She is the "HR of others" | ones character
- Why some people earn nearly 10billion a year, while others earn 3000 a month: the details you ignore actually make the most money
- How to make the two financial transactions faster
猜你喜欢
随机推荐
038 network security JS
Stepsister becomes stepmother, son breaks off relationship with himself, and musk, the world's richest man, why is it so miserable?
Missing API interface actual development series (14): ID card real name authentication verification
Eigen matrix operation Library
2022 tea master (intermediate) recurrent training question bank and answers
十大劵商如何开户?另外,手机开户安全么?
Redisson uses the full solution - redisson official documents + comments (Part 2)
LeetCode+ 71 - 75
【推荐系统】美团外卖推荐场景的深度位置交互网络DPIN的突破与畅想
Cadence OrCAD Capture “网络名”相同,但是未连接或连接错误的解放方案之nodename的用法
力扣每日一题-第31天-202.快乐数
Todolist classic case ①
Rk3399 platform development series explanation (network debugging) 7.30. What will affect the sending process of TCP packets?
C # read and write customized config file
ctfshow-web352,353(SSRF)
2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) special operation certificate examination question bank simulated examination platform operation
2022危险化学品经营单位主要负责人试题及模拟考试
软件测试方法和技术 - 基础知识概括
[software] phantomjs screenshot
【Flutter 问题系列第 72 篇】在 Flutter 中使用 Camera 插件拍的图片被拉伸问题的解决方案








