多条件筛选表格数据

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

开发工具与关键技术:VS  MVC.NET

作者:周乐献

撰写时间:2020年8月18日

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

当DOM载入就绪可以查询及操纵时查询出全部的学生数据数据

$(document).ready(function () {

            layui.use(['layer', 'table'], function () {

                layer = layui.layer;

                layTable = layui.table;

                TabStudent = layTable.render({

                    elem: '#tabStudent',

                    data: [],

                    cols: [[

                        { type: 'numbers', title: '序号', width: 100 },

                        { field: 'studentNumber', title: '学生编号', align: 'center' },

                        { field: 'studentName', title: '学生姓名', align: 'center' },

                        { field: 'calssName', title: '班级', align: 'center' },

                        { field: 'studentSex', title: '性别', align: 'center' },

                        { field: 'telephone', title: '手机号', align: 'center', width: 180, },

                        { field: 'studentIDCard', title: '身份证号', align: 'center', width: 220, },

                        { templet: InquirePicture, title: '图片', align: 'center' },

                        { templet:operation, title: '操作', align: 'center' },

                    ]],

                    page: {

                        limit: 10,

                        limits:[5,10,15,20,25,30,50],

                    }

                })

                InquireStudent();

            })

        })

然后根据条件筛选学生数据

function InquireStudent() {

            var studentNumber = $("#studentNumber").val();

            var studentName = $("#studentName").val();

            var classID = $("#classID").val();

            var studentIDCard = $("#studentIDCard").val();

            TabStudent = layTable.reload("tabStudent",{

                url:"@Url.Content("~/Main/InquireStudentInfo")",

                where: {

                studentNumber: studentNumber,

                studentName: studentName,

                classID: classID,

                studentIDCard: studentIDCard

                },

            page: {

                    curr:1

            },

            })

        }

在控制器根据页面传递过来的筛选条件对所以的学生数据进行筛选,然后再把符合筛选条件的数据返回到页面

public ActionResult InquireStudentInfo(LayuiTablePage layuiTablePage, string studentNumber, string studentName, int? classID, string studentIDCard)

        {

            try

            {

                var dbStudent = (from tbStudent in myModel.S_Student

                                 join tbClass in myModel.S_Class on tbStudent.classID equals tbClass.classID

                                 orderby tbStudent.studentID descending

                                 select new StudentVo()

                                 {

                                     studentID = tbStudent.studentID,

                                     classID = tbClass.classID,

                                     calssName = tbClass.calssName,

                                     studentNumber = tbStudent.studentNumber,

                                     studentName = tbStudent.studentName,

                                     studentSex = tbStudent.studentSex,

                                     telephone = tbStudent.telephone,

                                     studentIDCard = tbStudent.studentIDCard,

                                     studentPicture = tbStudent.studentPicture,

                                 });

                //筛选条件----学生编号

                if (!string.IsNullOrEmpty(studentNumber))

                {

                    dbStudent = dbStudent.Where(m => m.studentNumber.Contains(studentNumber));

                }

//筛选条件----学生姓名

                if (!string.IsNullOrEmpty(studentName))

                {

                    dbStudent = dbStudent.Where(m => m.studentName.Contains(studentName));

                }

//筛选条件----班级

                if (classID > 0)

                {

                    dbStudent = dbStudent.Where(m => m.classID == classID);

                }

//筛选条件----学生身份证号

                if (!string.IsNullOrEmpty(studentIDCard))

                {

                    dbStudent = dbStudent.Where(m => m.studentIDCard.Contains(studentIDCard));

                }

                int StudentCount = dbStudent.Count();

                List<StudentVo> listStudent = dbStudent

                                             .Skip(layuiTablePage.GetStartIndex())

                                             .Take(layuiTablePage.limit)

                                             .ToList();

                LayuiTableData<StudentVo> layuiTableData = new LayuiTableData<StudentVo>()

                {

                    count = StudentCount,

                    data = listStudent,

                };

                return Json(layuiTableData, JsonRequestBehavior.AllowGet);

            }

            catch (Exception e)

            {

                Console.WriteLine(e);

                return Content("数据异常");

            }

        }  

这里的筛选条件用的是模糊查询,只要学生数据中对应的信息里包含有筛选的条件就能把含有筛选条件的学生数据查询出来;

1.不进行筛选时所有的学生数据

2.把学生编号包含10的学生数据查询出来, 不符合的则不显示

3.根据学生姓名进行筛选

4.根据班级进行筛选

5.根据身份证进行筛选

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值