Layui implements sample code for multi-condition query

Layui implements sample code for multi-condition query

I recently made a file system and found that there are too many fields

Multi-condition query with paging (paging requires backend paging, and the page can only be passed to the backend to be implemented, and the frontend cannot be implemented directly)

When we click the search button, the relevant data of the input value will be filtered out. Multi-condition query is based on the data. After the data is queried, the conditions are opened to make a certain value under the queried data equal to the value entered by the user when the value entered by the user is not empty. Then the queried data is returned to the view and the rendered table is reloaded. The queried data is the filtered data related to the value entered by the user.

insert image description here

Multiple condition query form

<form class="layui-form" action="">
		<div class="layui-inline">
			<label class="layui-form-label">Grade</label>
			<div class="layui-input-inline">
				<input type="text" id="grade" name="grade" placeholder="Please select grade"
					autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-inline">
			<label class="layui-form-label">Professional</label>
			<div class="layui-input-inline">
				<select name="majorid" id="majorid">
					<option value="">Please select</option>
				</select>
			</div>
		</div>
		<div class="layui-inline">
			<div class="layui-input-inline">
				<button class="layui-btn" id="searchBtn" lay-submit
					lay-filter="formDemo" data-type="reload" style="margin-left: 15px">
					<i class="layui-icon layui-icon-search"></i> Search </button>
				<button type="reset" class="layui-btn layui-btn-primary">Reset</button>
			</div>
		</div>
	</form>

Use the year calendar to select grade and dynamically obtain major options

//Grade displayed in calendar var laydate = layui.laydate;
	laydate.render({
		elem : '#grade', //Specify element type : 'year'
	});

	//Get the drop-down box professional $.ajax({
		url : '../../MajorFindAllServlet?deptid=5',
		dataType : 'json',
		data : {
			'state' : 0
		}, //Query all institution types with normal status type : 'post',
		success : function(data) {
			$.each(data, function(index, item) {
				$('#majorid').append(
						new Option(item.majorname, item.majorid)); // Add elements to the drop-down menu });
			layui.form.render("select");
		}
	});

All js are included in..., table is the data table, laydata is the calendar, form is the form, just write which part you need, for details, see Layui official website

layui.use(['table', 'laydate', 'form' ], function() {...}

Generate table

//Generate table var table = layui.table;
	table.render({
		elem : '#table',
		url : '../../ClassesFindByPageServlet',
		toolbar : '#toolbarDemo',
		title: 'Class table', //Export file name page: {
			layout:['count','prev','page','next', 'skip']
		}, //Open paging id: 'tableAll',
		where : {
			majorid: '',
			grade : ''
		},
		request : {
			'limitName' : 'pageSize' //Change the default field of the number of entries per page to pageSize
		},
		cellMinWidth : 80, //Globally define the minimum width of regular cells, LayUI 2.2.1 added cols : [ [ {
			type : 'checkbox',
			fixed : 'left'
		}, {
			field : 'classid',
			title: 'Class number'
		}, {
			field : 'classname',
			title: 'Class name'
		}, {
			field : 'deptname',
			title : 'Department Name'
		}, {
			field : 'majorname',
			title : 'Professional name'
		}, {
			field : 'grade',
			title: 'Grade',
			sort : true
		}, {
			fixed : 'right',
			title : 'Operation',
			toolbar : '#barDemo'
		} ] ]
	});

Click submit to reload the form for multiple conditional queries

//Click the query button to reload the table $('#searchBtn').on('click', function() {
		table.reload('tableAll', {
			method : 'post',
			where : {
				grade : $('#grade').val(),
				majorid : $('#majorid').val()
			},
			page : {
				curr : 1
			}
		});
		return false;
	});

This concludes this article about the sample code for implementing multi-condition query in Layui. For more information about multi-condition query in Layui, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Layui implements paging with query conditions
  • Layui table data addition, modification, deletion, query, double-click to obtain row data method
  • layUI implements list query function

<<:  How to set focus on HTML elements

>>:  CSS3 uses transform deformation combined with events to complete fan-shaped navigation

Recommend

How to Install Oracle Java 14 on Ubuntu Linux

Recently, Oracle announced the public availabilit...

Two implementation codes of Vue-router programmatic navigation

Two ways to navigate the page Declarative navigat...

Detailed explanation of Windows time server configuration method

Recently, I found that the company's server t...

Mysql command line mode access operation mysql database operation

Usage Environment In cmd mode, enter mysql --vers...

How to set horizontal navigation structure in Html

This article shares with you two methods of setti...

How to deploy Spring Boot using Docker

The development of Docker technology provides a m...

How to use worm replication in Mysql data table

To put it simply, MySQL worm replication is to co...

Installation of Docker CE on Ubuntu

This article is used to record the installation o...

Understand the initial use of redux in react in one article

Redux is a data state management plug-in. When us...

jQuery achieves seamless scrolling of tables

This article example shares the specific code of ...

IE8 compatibility notes I encountered

1. IE8's getElementById only supports id, not ...

Summary of common problems and solutions in Vue (recommended)

There are some issues that are not limited to Vue...

Table td picture horizontally and vertically centered code

Html code: Copy code The code is as follows: <t...