在前端使用Jqgrid表格显示数据,并进行数据的搜索、过滤、排序功能_jqgrid 过滤_柠檬味的Cat的博客-程序员宅基地

技术标签: Web前端  jqgrid  

在前端使用Jqgrid表格显示数据,并进行数据的搜索、过滤、排序功能

小编在日常生活工作中学习到的点,在此记录一下,希望能够帮助有需要的小伙伴。



前言

对表格数据进行搜索、过滤、排序是日常生活工作中常用的方法


提示:以下是本篇文章正文内容,下面案例可供参考

一、Jqgird是什么?

jqgrid是非常好的Web前端表格控件,用它可以轻松的显示,格式化,与前后端通过ajax进行数据交互

二、使用步骤

1.引入Js,CSS文件即可使用

代码如下(示例):

 <!-- The jQuery library is a prerequisite for all jqSuite products -->
    <script type="text/ecmascript" src="../../../js/jquery.min.js"></script> 
    <!-- We support more than 40 localizations -->
    <script type="text/ecmascript" src="../../../js/trirand/i18n/grid.locale-en.js"></script>
    <!-- This is the Javascript file of jqGrid -->   
    <script type="text/ecmascript" src="../../../js/trirand/jquery.jqGrid.min.js"></script>
    <!-- A link to a Boostrap  and jqGrid Bootstrap CSS siles-->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> 
    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/trirand/ui.jqgrid-bootstrap.css" />

2.前端写table标签,用于在前端显示Jqgrid表格

代码如下(示例):

<div class="div">
	<style>
		.div{
      margin:0 auto; width:1500px; height:400px; padding-top: 50px;}
	</style>
    <table id="jqGrid"></table>
    <div id="jqGridPager" ></div>
</div>    

3.显示表格(使用Js中的方法)

<script type="text/javascript"> 
    
        $(document).ready(function () {
     
			$.jgrid.styleUI.Bootstrap.base.rowTable = "table table-bordered table-striped";
            $("#jqGrid").jqGrid({
     
                url: 'a.json',
                mtype: "GET",
                datatype: "json",
                page: 1,
                colModel: [
                    {
        label : "搜索词",
						//sorttype: 'integer',
						name: '搜索词', 
						key: true, 
						align: 'center',
						width: 100,
						stype : 'text',
						searchoptions: {
     
							sopt : ['cn','eq']
						}
					},
					{
        label : "触发模式",
						//sorttype: 'integer',
						name: '触发模式', 
						align: 'center',
						width: 100,
						stype : 'select',
						searchoptions: {
     
							value: ":[全部];短语:短语;精确:精确",
							sopt : ['cn','eq']
						}
					},
                    {
     
						label: "展现",
                        name: '展现',
						sorttype: 'number',
						align: 'center',
						//sorttype: 'number',
                        width: 100,
                        // stype defines the search type control - in this case HTML select (dropdownlist)
                        stype: "text",
                        // searchoptions value - name values pairs for the dropdown - they will appear as options
                        searchoptions: {
     
                        	sopt : ['eq','le','ge']
                        }
                    },
                    {
      
						label: "消费",
                        name: '消费',
						sorttype: 'number',
						align: 'center',
                        width: 100,
                        searchoptions: {
     
                        	sopt : ['eq','le','ge']
                        }
                    },                    
                    {
     
						label : "点击",
                        name: '点击',
						sorttype: 'number',
						align: 'center',
                        width: 100,
                        searchoptions: {
     
                        	sopt : ['eq','le','ge']
                        }
                    },
                    {
     
						label: "平均点击价格",
						sorttype: 'number',
						name: '平均点击价格', 
						align: 'center',
						width: 100,
						searchoptions: {
     
							sopt : ['eq','le','ge']
						}
					}
                ],
				loadonce: true,
				viewrecords: true,
				rownumbers: true,
				rownumWidth: 50,
                width: 1500,
                height: 400,
                rowNum: 1000,
				colMenu : true,
                pager: "#jqGridPager"
            });
			
			$('#jqGrid').jqGrid('navGrid',"#jqGridPager", {
     
			    search: true, 
			    add: false,
			    edit: false,
			    del: false,
			    refresh: true,
				multipleSearch : true,
			});
			// activate the toolbar searching
            $('#jqGrid').jqGrid('filterToolbar',{
     
               defaultSearch:'cn',stringResult: true,searchOnEnter : false ,searchOperators: true 
            });
        });
			

    </script>

全部代码

<!DOCTYPE html>
<html lang="en">
<head>
    <!-- The jQuery library is a prerequisite for all jqSuite products -->
    <script type="text/ecmascript" src="http://www.guriddo.net/demo/js/jquery.min.js"></script> 
    <!-- We support more than 40 localizations -->
    <script type="text/ecmascript" src="http://www.guriddo.net/demo/js/trirand/i18n/grid.locale-cn.js"></script>
    <!-- This is the Javascript file of jqGrid -->   
    <script type="text/ecmascript" src="http://www.guriddo.net/demo/js/trirand/jquery.jqGrid.min.js"></script>
    <!-- A link to a Boostrap  and jqGrid Bootstrap CSS siles-->
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> 
    <link rel="stylesheet" type="text/css" media="screen" href="http://www.guriddo.net/demo/css/trirand/ui.jqgrid-bootstrap.css" />
	<script>
		$.jgrid.defaults.width = 1500;
		$.jgrid.defaults.responsive = true;
		$.jgrid.defaults.styleUI = 'Bootstrap';
	</script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <script type="text/ecmascript" src="http://www.guriddo.net/demo/js/bootstrap-datepicker.js"></script> 
    <script type="text/ecmascript" src="http://www.guriddo.net/demo/js/bootstrap3-typeahead.js"></script> 
    <link rel="stylesheet" type="text/css" media="screen" href="http://www.guriddo.net/demo/css/bootstrap-datepicker.css" />
    <meta charset="utf-8" />
    <title>jqGrid Loading Data - Toolbar Searching with Search Options</title>
</head>
<body>
<div class="div">
	<style>
		.div{
      margin:0 auto; width:1500px; height:400px; padding-top: 50px;}
	</style>
    <table id="jqGrid"></table>
    <div id="jqGridPager" ></div>
</div>    
	<script type="text/javascript"> 
    
        $(document).ready(function () {
     
			$.jgrid.styleUI.Bootstrap.base.rowTable = "table table-bordered table-striped";
            $("#jqGrid").jqGrid({
     
                url: 'a.json',
                mtype: "GET",
                datatype: "json",
                page: 1,
                colModel: [
                    {
        label : "搜索词",
						//sorttype: 'integer',
						name: '搜索词', 
						key: true, 
						align: 'center',
						width: 100,
						stype : 'text',
						searchoptions: {
     
							sopt : ['cn','eq']
						}
					},
					{
        label : "触发模式",
						//sorttype: 'integer',
						name: '触发模式', 
						align: 'center',
						width: 100,
						stype : 'select',
						searchoptions: {
     
							value: ":[全部];短语:短语;精确:精确",
							sopt : ['cn','eq']
						}
					},
                    {
     
						label: "展现",
                        name: '展现',
						sorttype: 'number',
						align: 'center',
						//sorttype: 'number',
                        width: 100,                 
                        stype: "text",                     
                        searchoptions: {
     
                        	sopt : ['eq','le','ge']
                        }
                    },
                    {
      
						label: "消费",
                        name: '消费',
						sorttype: 'number',
						align: 'center',
                        width: 100,
                        searchoptions: {
     
                        	sopt : ['eq','le','ge']
                        }
                    },                    
                    {
     
						label : "点击",
                        name: '点击',
						sorttype: 'number',
						align: 'center',
                        width: 100,
                        searchoptions: {
     
                        	sopt : ['eq','le','ge']
                        }
                    },
                    {
     
						label: "平均点击价格",
						sorttype: 'number',
						name: '平均点击价格', 
						align: 'center',
						width: 100,
						searchoptions: {
     
							sopt : ['eq','le','ge']
						}
					}
                ],
				loadonce: true,
				viewrecords: true,
				rownumbers: true,
				rownumWidth: 50,
                width: 1500,
                height: 400,
                rowNum: 1000,
				colMenu : true,
                pager: "#jqGridPager"
            });
			
			$('#jqGrid').jqGrid('navGrid',"#jqGridPager", {
     
			    search: true, 
			    add: false,
			    edit: false,
			    del: false,
			    refresh: true,
				multipleSearch : true,
			});
			// activate the toolbar searching
            $('#jqGrid').jqGrid('filterToolbar',{
     
               defaultSearch:'cn',stringResult: true,searchOnEnter : false ,searchOperators: true 
            });
        });			
    </script>
</body>
</html>

效果图

在这里插入图片描述

总结

可以直接在上面的表格中对数据进行搜索、过滤、排序,下面是学习文档

bootstrap样式的Jqgrid Demo:http://www.guriddo.net/demo/bootstrap/

中文文档的Jqgrid Demo:https://blog.mn886.net/jqGrid/

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_42739591/article/details/109890605

智能推荐

matlab二阶锥,二次规划和锥规划 - MATLAB & Simulink - MathWorks 中国-程序员宅基地

基于求解器的二次规划Example of quadratic programming with bound constraints and variousoptions.This example shows the benefit of the active-set algorithm on problems withmany linear constraints.Example showing ..._matlab求解二阶锥规划问题

将博客搬至CSDN-程序员宅基地

https://blog.csdn.net/wangzan18

ubuntu入系统的时候recovering journal的解决办法-程序员宅基地

ubuntu由于意外断电或者文件损坏的原因进不去桌面1、进入命令行:rm -rf /etc/X11/xorg.conf2、cp /etc/X11/xorg.conf.failsafe /etc/X11/xorg.conf3、ctrl+ALT+F1 进入tty模式重新安装显卡程序即可。..._recovering journal

分布式一致性算法的演进-程序员宅基地

点击上方“程序员小灰”,选择“置顶公众号”有趣有内涵的文章第一时间送达!本文转载自公众号 码农翻身分布式系统的难题张大胖遇到了一个难题。他们公司的有个服务器,上面保存着...

git常见的报错问题解决-程序员宅基地

git报错OpenSSL SSL_read: Connection was reset, errno 10054关闭ssl,执行下面命令:$ git config --global http.sslVerify "false"git报错Failed to connect to github.com port 443: Timed out看网上说原因听多的,我的原因是因为开了全局代理,关闭全局代理之后问题就解决了git报错Failed to connect to 127.0..

03--ApplicationListener用法与原理-程序员宅基地

import org.springframework.context.ApplicationEvent;import org.springframework.context.ApplicationListener;import org.springframework.stereotype.Component;@Componentpublic class MyApplicationListener implements ApplicationListener<ApplicationEvent._applicationlistener

随便推点

oracle9.2.04下载,Linux AS3.0下安装ORACLE9.2.04_邹晓航0号的博客-程序员宅基地

Linux AS3.0下安装ORACLE9.2.04一、 下载 Sun's Java Development Kit (JDK 1.4.2).j2sdk-1_3_1_09-linux-i586.rpm.bin下载Oracle 安装软件 otn.oracle.com.lnx_920_disk1.cpio.gzlnx_920_disk1.cpio.gzlnx_920_disk1.cpio.gz下载 ..._oracle9.2安装包下载

10年经验的纤亿通网络工程师告诉你-有源波分和无源波分到底怎么选最合适!_无源波分和有源波分区别_波分传输_纤亿通的博客-程序员宅基地

一说到波分复用器,我想你马上就能脱口而出两个词“CWDM”和“DWDM”那怎么选择有源波分还是无源波分?首先,先确定你要的是波分是“CWDM”还是“DWDM”因为这两种波分都包含有源与无源的产品如果两者不懂如何区分,往下看CWDM和DWDM都是波分复用器,那它们有什么区别?CWDM(即稀疏波分复用)与DWDM(即密集波分复用),从字面上我们便可以大概看出两者的区别在于:“密集”与“稀疏”。稀疏波分复用,顾名思义,是密集波分复用的近亲。..._无源波分和有源波分区别

kotlin activity 之间跳转及传参-程序员宅基地

gradle中实现implementation "org.jetbrains.anko:anko-commons:0.10.3startActivity(this!!.intentFor<UploadActivity>() .putExtra("","") .putExtra("",""))## **安卓高级开发交流群:qq 3350...

Java15新特性一览_java: -source 15-程序员宅基地

作者:Java技术栈JDK 15 2020/09/15 如期而至!这个时间牛逼啊,和苹果发布会同天?OracleJDK 15 发布地址:https://www.oracle.com/java/technologies/javase/15all-relnotes.htmlOpenJDK 15 发布地址:https://openjdk.java.net/projects/jdk/15/OracleJDK 和 OpenJDK 两者的区别这里不撰述了,不清楚的请点击这里进行查_java: -source 15

L1-062 幸运彩票-程序员宅基地

分数 15作者 陈越单位 浙江大学彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的。本题就请你判断给定的彩票是不是幸运的。输入格式:输入在第一行中给出一个正整数 N(≤ 100)。随后 N 行,每行给出一张彩票的 6 位数字。输出格式:对每张彩票,如果它是幸运的,就在一行中输出 You are lucky!;否则输出 Wish you good luck.。输入样例:2233008123456输出样例:

队列与链表_度心℃的博客-程序员宅基地

数据结构线性结构:1、线性结构作为最常用的数据结构,其特点是数据元素之间存在一对一的线性关系。2、线性结构有两种不同的存储结构,即顺序存储和链式存储结构。顺序存储的线性表称为顺序表,顺序表中的存储元素是连续的。3、链式存储的线性表称为链表,链表中的存储元素不一定是连续的,元素节点中存放数据元素和相邻元素的地址信息。4、线性结构常见的有:数组、列表、链表和栈,非线性结构:非线性结构包括:二维数组,多维数组,广义表,树结构,图结构。稀疏数组基本介绍:当一个数组大部分元素为0,或者为同一个值的_队列与链表