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

Detailed explanation of CSS style cascading rules

CSS style rule syntax style is the basic unit of ...

Detailed explanation of process management in Linux system

Table of contents 1. The concept of process and t...

Example of creating a virtual host based on Apache port

apache: create virtual host based on port Take cr...

How to configure two or more sites using Apache Web server

How to host two or more sites on the popular and ...

Analysis of the causes of accidents caused by Unicode signature BOM

Maybe you are using include files here, which is u...

MySQL-group-replication configuration steps (recommended)

MySQL-Group-Replication is a new feature develope...

Sqoop export map100% reduce0% stuck in various reasons and solutions

I call this kind of bug a typical "Hamlet&qu...

Essential bonus items for optimizing and packaging the front end of Vue projects

Table of contents Preface 1. Routing lazy loading...

JS realizes the scrolling effect of announcement online

This article shares the specific code of JS to ac...

An example of how to implement an adaptive square using CSS

The traditional method is to write a square in a ...

Specific use of stacking context in CSS

Preface Under the influence of some CSS interacti...

Deep understanding of line-height and vertical-align

Several concepts Line box: A box that wraps an in...

Use of Linux crontab command

1. Command Introduction The contab (cron table) c...