查询

查询

有条件查询:
在这里插入图片描述

表格加载: 加载layui模块

layui.use(['table'], function () {	layuiTable = layui.table;
	//渲染表格:
	tabStudent = layuiTable.render({	//tabStudent全局变量, layuiTable=layui.table;
		elem: "#tabStudent",//table的ID HTML元素的ID
		url: "/Main/SelectStudents",//数据接口 方法的路径
		cols: [[
			{ title:'序号',type:'numbers'},
			//numbers 序号列,title设定标题名称,width: 160 指定宽度,align 指定对其方式
			{ title: '学生编号', field: 'studentNumber', align: 'center' },
			{ title: '学生姓名', field: 'studentName', align: 'center' },
			{ title: '班级', field: 'calssName', align: 'center' },
			{ title: '性别', field: 'studentSex', align: 'center' },
			{ title: '手机号', field: 'telephone', align: 'center' },
			{ title: '身份证号', field: 'studentIDCard', align: 'center' },
 			{ title: '图片', templet: showPicture, align: 'center' },
			{ title: '操作', templet: setOperate, width: 160, align: 'center' }
		]],
		page: true   //开启分页	});});

多条件查询table:

function tabStudentSearch(){//获取页面输入数据
	var studentNumber = $("#studentNumber").val();//编号
	if (studentNumber == undefined) {	studentNumber = "";	}
	var studentName = $("#studentName").val();//姓名
	if (studentName == undefined) {		studentName = "";		}
	var classID = $("#classID").val();//班级ID
	if (classID == "" || classID == undefined) {	classID = 0;	}
	var studentIDCard = $("#studentIDCard").val();//身份证号
	if (studentIDCard == undefined) {	studentIDCard = "";	}
	tabStudent.reload({//表格重载
		where: {
			studentNumber: studentNumber, //编号
			studentName: studentName, //姓名
			classID: classID, //班级ID
			studentIDCard: studentIDCard, //身份证号
                },page: {	curr: 1//重新从第一页开始	}	});	}

后台去数据库查询出需要的数据:

public ActionResult SelectStudents(LayuiTablePage layuiTablePage, string studentNumber, 
	  string studentName, int? classID, string studentIDCard) {
	var listStudent = from tbStudent in myModel.S_Student
	join tbClass in myModel.S_Class on tbStudent.classID equals tbClass.classID
	select new StudentVo	{ 
		studentID=tbStudent.studentID,//学生ID
		classID=tbStudent.classID,//班级ID
		studentNumber=tbStudent.studentNumber,//学生编号
		studentName=tbStudent.studentName,//学生姓名
		calssName=tbClass.calssName,//班级
		studentSex=tbStudent.studentSex,//性别
		telephone=tbStudent.telephone,//手机号
		studentIDCard = tbStudent.studentIDCard,//身份证号
		studentPicture=tbStudent.studentPicture,//图片	};
//条件筛选
	if (!string.IsNullOrEmpty(studentNumber)) //编号	{ Contains模糊查询
		listStudent = listStudent.Where(m => m.studentNumber.Contains(studentNumber));	} 
	if (!string.IsNullOrEmpty(studentName)) //姓名		{
		listStudent = listStudent.Where(m => m.studentName.Contains(studentName));		}
	if (classID > 0) //班级ID						{
		listStudent = listStudent.Where(m => m.classID == classID);					}
	if (!string.IsNullOrEmpty(studentIDCard))//身份证号{
		listStudent = listStudent.Where(m => m.studentIDCard.Contains(studentIDCard));	}
//分页查询学生数据
	List<StudentVo> listStu= listStudent
		.OrderByDescending(m => m.studentID)//根据学生ID倒叙排序
		.Skip(layuiTablePage.GetStartIndex())//跳过前面页数的数据                                              
		.Take(layuiTablePage.limit)//查询本页数据的条数
		.ToList();//返回List集合
//查询学生数据的总条数
	int intTotalRow = myModel.S_Student.Count();
//准备Layui Table所需的数据格式(泛型)
	LayuiTableData<StudentVo> layuiTableData = new LayuiTableData<StudentVo>()	{
		count = intTotalRow,//总条数
		data = listStu,//本页的数据		};
//返回Json
	return Json(layuiTableData, JsonRequestBehavior.AllowGet);}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值