Home Web Front-end Layui Tutorial Detailed explanation of layui framework paging settings

Detailed explanation of layui framework paging settings

Dec 09, 2019 pm 05:26 PM
layui

Detailed explanation of layui framework paging settings

The specific steps are as follows:

1. Copy the following from the official document - built-in module - data table:

Detailed explanation of layui framework paging settings

2. Copy to the page and change the CSS address and JS address to your local address

Detailed explanation of layui framework paging settings

3. When the browser is run, the following will appear

Detailed explanation of layui framework paging settings

4. Found that the data interface request exception was prompted: error.

Solution:

1.1 Change the url request address in the code to your own address

1.2 Change the cols parameter to the parameter returned by your own interface address

Detailed explanation of layui framework paging settings

5. Then go to the browser to continue the scope, and the error is still reported. The error is as follows:

Detailed explanation of layui framework paging settings

6. Look at the problem, The data format returned by the interface is incorrect

Then we go to the manual to see the interface data return format.

Details: Official document - built-in module - data table - returned data

Detailed explanation of layui framework paging settings

7. The specific returned data format is as follows, among which, success The returned code should be 0

{
    "code": 0,
    "msg": "",
    "count": 1000,
    "data": [ {},{},{} ]
}
Copy after login

Detailed explanation of layui framework paging settings

8. After changing the return format of your interface, go to the browser again and the following effect will appear, indicating the interface format and The returned data is correct

Detailed explanation of layui framework paging settings

9. In this block, the paging effect appears in the results you see. Which block of code is affected? You will find a piece of code in the js code: page:true // Turn on paging. However, there are still problems, and the paging data displayed is incorrect. Solution: Copy the following code, write it in your own code, and assign the data returned by the interface to the corresponding parameters. The specific operations are as follows:

操作:示例 – 组件示例 – 数据表格 – 解析任意数据格式 – 查看代码 - parseData

Detailed explanation of layui framework paging settings

10、然后再次运行、会发现我们自己写的限制条数并没有起作用、然后再次看请求地址、会发现是通过get请求、固定参数 page、limit来操作的、同时给了默认的值;

page:1,
limit:10,
Copy after login

Detailed explanation of layui framework paging settings

11、那如何改为post请求呢?只需要指定请求方式post

操作:官方文档 - 内置模块 - 数据表格 – 异步数据接口 – method

1Detailed explanation of layui framework paging settings

12、运行、查看请求、如下:

1Detailed explanation of layui framework paging settings

13、请求参数的名称名称已经知道是page、limit 如何修改为我们自己想要的参数名呢?

操作:官方文档 - 内置模块 - 数据表格 – 异步数据接口 – request代码:

request: {
    pageName: 'page',   // 页码的参数名称,默认:page
    limitName: 'size'   // 每页数据量的参数名,默认:limit
}
Copy after login

1Detailed explanation of layui framework paging settings

14、运行、查看请求参数、具体如下:

1Detailed explanation of layui framework paging settings

15、改变默认的每页显示条数

如何将首页默认显示条数改为自己想要的?
如何将浏览器默认显示的每页显示的条数改为自己想要的?
操作:官方文档 – 内置模块 – 数据表格 – 基础参数一览表 – limit、limits
代码修改:

limit:3,
limits:[2,3,5],
Copy after login

1Detailed explanation of layui framework paging settings

16、运行、查看请求参数、具体如下:

Detailed explanation of layui framework paging settings

17、最终的html代码如下:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>table模块快速使用</title>
    <link rel="stylesheet" href="./layui/css/layui.css" media="all">
</head>

<body>
    <table id="demo" lay-filter="test"></table>
    <script ></script>
    <script>
        layui.use(&#39;table&#39;, function () {
            var table = layui.table;
            //第一个实例
            table.render({
                elem: &#39;#demo&#39;
                , url: &#39;http://localhost/php/public/index.php/index/index/index&#39; //数据接口
                , method: &#39;post&#39;
                , page: true //开启分页
                , limit: 3
                , limits: [2, 3, 5]
                , cols: [[
                    { width: 80, type: &#39;checkbox&#39; },
                    { field: &#39;type_id&#39;, width: 80, title: &#39;ID&#39;, sort: true },
                    { field: &#39;type_name&#39;, title: &#39;分类名称&#39;, sort: true }
                ]],
                parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.msg, //解析提示文本
                        "count": res.data.total, //解析数据长度
                        "data": res.data.data //解析数据列表
                    };
                },
                request: {
                    pageName: &#39;page&#39; // 页码的参数名称,默认:page
                    , limitName: &#39;size&#39; //每页数据量的参数名,默认:limit
                },
            });
        });
    </script>
</body>

</html>
Copy after login

18、接口使用的TP5.0 没有使用模型层、具体简单代码如下:

<?php

namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Request;

class Index extends Controller
{
    public function index()
    {
        $size = Request::instance()->post( &#39;size&#39;, 3 );
        $page = Request::instance()->post( &#39;page&#39;, 1 );
        $res = Db::table( &#39;goods_type&#39; )->paginate( $size, false, [ &#39;page&#39;=> $page] );
        $arr[&#39;code&#39;] = 0;
        $arr[&#39;msg&#39;] = &#39;ok&#39;;
        $arr[&#39;data&#39;] = $res;
        return json( $arr );
    }
}
?>
Copy after login

推荐:layui使用教程

The above is the detailed content of Detailed explanation of layui framework paging settings. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set up jump on layui login page How to set up jump on layui login page Apr 04, 2024 am 03:12 AM

Layui login page jump setting steps: Add jump code: Add judgment in the login form submit button click event, and jump to the specified page through window.location.href after successful login. Modify the form configuration: add a hidden input field to the form element of lay-filter="login", with the name "redirect" and the value being the target page address.

How to get form data in layui How to get form data in layui Apr 04, 2024 am 03:39 AM

layui provides a variety of methods for obtaining form data, including directly obtaining all field data of the form, obtaining the value of a single form element, using the formAPI.getVal() method to obtain the specified field value, serializing the form data and using it as an AJAX request parameter, and listening Form submission event gets data.

How layui implements self-adaptation How layui implements self-adaptation Apr 26, 2024 am 03:00 AM

Adaptive layout can be achieved by using the responsive layout function of the layui framework. The steps include: referencing the layui framework. Define an adaptive layout container and set the layui-container class. Use responsive breakpoints (xs/sm/md/lg) to hide elements under specific breakpoints. Specify element width using the grid system (layui-col-). Create spacing via offset (layui-offset-). Use responsive utilities (layui-invisible/show/block/inline) to control the visibility of elements and how they appear.

How to transfer data in layui How to transfer data in layui Apr 26, 2024 am 03:39 AM

The method of using layui to transmit data is as follows: Use Ajax: Create the request object, set the request parameters (URL, method, data), and process the response. Use built-in methods: Simplify data transfer using built-in methods such as $.post, $.get, $.postJSON, or $.getJSON.

What is the difference between layui and vue? What is the difference between layui and vue? Apr 04, 2024 am 03:54 AM

The difference between layui and Vue is mainly reflected in functions and concerns. Layui focuses on rapid development of UI elements and provides prefabricated components to simplify page construction; Vue is a full-stack framework that focuses on data binding, component development and state management, and is more suitable for building complex applications. Layui is easy to learn and suitable for quickly building pages; Vue has a steep learning curve but helps build scalable and easy-to-maintain applications. Depending on the project needs and developer skill level, the appropriate framework can be selected.

How to run layui How to run layui Apr 04, 2024 am 03:42 AM

To run layui, perform the following steps: 1. Import layui script; 2. Initialize layui; 3. Use layui components; 4. Import layui styles (optional); 5. Ensure script compatibility and pay attention to other considerations. With these steps, you can build web applications using the power of layui.

What does layui mean? What does layui mean? Apr 04, 2024 am 04:33 AM

layui is a front-end UI framework that provides a wealth of UI components, tools and functions to help developers quickly build modern, responsive and interactive web applications. Its features include: flexible and lightweight, modular design, rich components, Powerful tools and easy customization. It is widely used in the development of various web applications, including management systems, e-commerce platforms, content management systems, social networks and mobile applications.

What language is layui framework? What language is layui framework? Apr 04, 2024 am 04:39 AM

The layui framework is a JavaScript-based front-end framework that provides a set of easy-to-use UI components and tools to help developers quickly build responsive web applications. Its features include: modular, lightweight, responsive, and has complete documentation and community support. layui is widely used in the development of management backend systems, e-commerce websites, and mobile applications. The advantages are quick start-up, improved efficiency, and easy maintenance. The disadvantages are poor customization and slow technology updates.

See all articles