jqgrid+bootstrap样式实践
jqgrid+bootstrap样式实践,报错数据加载,选中,删除等功能
需要引入的样式
bootstrap.min.css ui.jqgrid.css
需要引入的JS
jquery.min.js
bootstrap.min.js
jquery.jqGrid.min.js
html代码:
- <div class="jqGrid_wrapper">
- <table id="jqGridList"></table>
- <div id="jqGridPager"></div>
- </div>
jqgrid初始化
- var jqGrid = $("#jqGridList");
- jqGrid.jqGrid({
- caption: "用户管理",
- url: "/User/GetList",
- mtype: "GET",
- styleUI: 'Bootstrap',//设置jqgrid的全局样式为bootstrap样式
- datatype: "json",
- colNames: ['主键', '登录帐号', '姓名','性别', '邮箱', '电话', '身份证'],
- colModel: [
- { name: 'Id', index: 'Id', width: 60, key: true, hidden: true },
- { name: 'Code', index: 'Code', width: 60 },
- { name: 'Name', index: 'Name', width: 60 },
- {
- name: 'Gender', index: 'Gender', width: 60,
- formatter: function(cellValue, options, rowObject) {
- return cellValue == 0 ? "男" : "女";
- }//jqgrid自定义格式化
- },
- { name: 'Email', index: 'Email', width: 60 },
- { name: 'Phone', index: 'Phone', width: 60 },
- { name: 'IdCard', index: 'IdCard', width: 60 }
- ],
- viewrecords: true,
- multiselect: true,
- rownumbers: true,
- autowidth: true,
- height: "100%",
- rowNum: 20,
- rownumbers: true, // 显示行号
- rownumWidth: 35, // the width of the row numbers columns
- pager: "#jqGridPager",//分页控件的id
- subGrid: false//是否启用子表格
- });
- // 设置jqgrid的宽度
- $(window).bind('resize', function () {
- var width = $('.jqGrid_wrapper').width();
- jqGrid.setGridWidth(width);
- });
其它jqgrid函数:
获取jqgrid选中的数据行:
- var id = $('#jqGridList').jqGrid('getGridParam', 'selrow');
- if (id)
- return $('#jqGridList').jqGrid("getRowData", id);
- else
- return null;
获取jqgrid的所有选中的数据
- var grid = $('#jqGridList');
- var rowKey = grid.getGridParam("selrow");
- if (rowKey) {
- var selectedIDs = grid.getGridParam("selarrrow");
- for (var i = 0; i < selectedIDs.length; i++) {
- console.log(selectedIDs[i]);
- }
- }
最终的效果图:
另附上后台控制器代码,又需要的可以看看
- /*******************************************************************************
- * Copyright (C) JuCheap.Com
- *
- * Author: dj.wong
- * Create Date: 2015/8/7 15:02:43
- * Description: Automated building by service@aspxpet.com
- *
- * Revision History:
- * Date Author Description
- *
- *********************************************************************************/
- using EP.Component.Tools;
- using EP.Site.Models;
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.ComponentModel.Composition;
- using System.Web.Mvc;
- using System.Linq.Expressions;
- namespace EP.Site.Web.Areas.Adm.Controllers
- {
- /// <summary>
- /// 用户管理
- /// </summary>
- [Export]
- public class UserController : BaseController
- {
- [Import]
- public IAccountSiteContract AccountService { get; set; }
- [Import]
- public ISys_UserSiteContract UserService { get; set; }
- [Import]
- public ISys_ParameterSiteContract ParamService { get; set; }
- // GET: Adm/User
- public ActionResult Index()
- {
- return View();
- }
- // GET: Adm/User/Add
- public ActionResult Add()
- {
- return View();
- }
- // GET: Adm/User/Edit
- public ActionResult Edit(int id)
- {
- var model = UserService.GetByKeyId(id);
- return View(model);
- }
- /// <summary>
- /// 分页获取
- /// </summary>
- /// <param name="query"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonResult GetList(QueryBase query)
- {
- try
- {
- Expression<Func<Sys_UserDto, bool>> exp = item => !item.IsDeleted && !item.IsUser;
- if (!query.SearchKey.IsBlank())
- exp = exp.And(item => item.Name.Contains(query.SearchKey) || item.Code.Contains(query.SearchKey));
- ResultDto<Sys_UserDto> dto = UserService.GetPages(query, exp, item => item.Id);
- return Json(dto, JsonRequestBehavior.AllowGet);
- }
- catch (Exception ex)
- {
- Log(ex);
- return Json(new ResultDto<Sys_UserDto>(), JsonRequestBehavior.AllowGet);
- }
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- [HttpPost]
- public JsonResult AddModel(Sys_UserDto model)
- {
- var result = new Result<string>();
- try
- {
- if (model == null)
- throw new ArgumentException("参数错误");
- bool flag = AccountService.Insert(model);
- if (result.flag)
- {
- ActionLog("Sys_User", model, ActionType.Insert, CurrentUser);
- }
- result.flag = flag;
- }
- catch (Exception ex)
- {
- Log(ex);
- result.msg = ex.Message;
- }
- return Json(result, JsonRequestBehavior.AllowGet);
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="model"></param>
- /// <returns></returns>
- [HttpPost]
- public JsonResult EditModel(Sys_UserDto model)
- {
- var result = new Result<string>();
- try
- {
- if (model == null)
- throw new ArgumentException("参数错误");
- bool flag = AccountService.Edit(model);
- if (result.flag)
- {
- ActionLog("Sys_User", model, ActionType.Update, CurrentUser);
- }
- result.flag = flag;
- }
- catch (Exception ex)
- {
- Log(ex);
- result.msg = ex.Message;
- }
- return Json(result, JsonRequestBehavior.AllowGet);
- }
- }
- }
jqgrid+bootstrap样式实践的更多相关文章
- 从覆盖bootstrap样式谈css选择器优先级
样式优先级 首先简单说几个定义样式的方式: 元素内嵌: <li><a href="" style="color:#ffffff;">SH ...
- 自定义bootstrap样式-9行样式自定义漂亮大气bootstrap导航栏
有人说前端发展太快,框架太多,各有所需,各有所长.看看这幅图,估计都知道这些框架,但是大部分公司中实际要用到的也就那么几个. 发展再快,框架再多.还是得回到原点,不就是Html+Css+JavaScr ...
- Yii2框架bootstrap样式理解
Yii2框架默认採用了bootstrap作为CSS风格,各种视图类组件都如此.之前一直採用默认风格,并在必要的时候加入或者改动一下class来达到目的.但在改版Yii1.1的orange项目时.发现之 ...
- js 重写 bootstrap 样式 alert/confirm 消息窗口
相信很多人都受够了 alert.confirm 的样子,最近正在用 bootstrap 做项目,顺便封装了一个 bootstrap 样式的消息框. 实现起来很简单,bootstrap 本身就自带了 m ...
- Angular中使用bootstrap样式
Angular中使用bootstrap样式 Angular中引入bootstrap的方法 方法1:在Angular.json中的styles数组中添加bootstrap路径 如下所示: " ...
- 利用vue v-bind属性绑定bootstrap样式以及输出数据
自从知道了bootstrap,就被他简介,大气美观的样式吸引,即使在vue框架中,仍旧想使用,下面给出了vue适配版和原版的代码,以飨读者 数据输出部分 export default { data() ...
- Python--day62--使用Bootstrap样式的出版社
没有使用之前: 使用Bootstrap样式之后:
- 自定义Bootstrap样式弹出框
最近做的一些功能需要用到Bootstrap,然而原来的系统并没有引入Bootstrap,为了新写的控件能够应用于老的页面,又不需要在老的页面上引入全套的Bootstrap文件决定写一个模仿Bootst ...
- Sweetalert模态对话框与Swiper轮播插件、Bootstrap样式组件、AdminLTE后台管理模板地址
Sweetalert纯JS模态对话框插件地址:http://mishengqiang.com/sweetalert/ AdminLTE后台管理模板系统地址(基于Bootstrap):https://a ...
随机推荐
- Top Coder算法题目浏览器
作者:Lucida 微博:@peng_gong 豆瓣:@figure9 原文链接:http://zh.lucida.me/blog/top-code-offline-browser/ 关于 左耳朵耗子 ...
- Spring集成MyBatis
本文原创,原文地址为http://www.cnblogs.com/fengzheng/p/5045105.html 如果觉得Hibernate不够灵活,可以尝试用Mybatis.相比于Hibernat ...
- 将一句话里的单词进行倒置,标点符号不倒换。比如将“I come from Shanghai.”倒换后变为“Shanghai. from come I”
string str = "I come from Shanghai."; //根据空格切割 string[] strS = str.Split(' '); string temp ...
- MVC中的AOP
一. AOP是什么? AOP(Aspect-Oriented Programming),面向切面编程,看着是跟OOP(面向对象编程)挺相近的,但实际上又有什么区别呢?OOP具有封装,继承,多态等东西来 ...
- 【.net深呼吸】非 Web 项目使用缓存
从.net 4 开始,非web项目也可以使用缓存技术,故曰:.net 4 乃框架成熟之标志也. 对于缓存嘛,耍过 ASP.NET 的伙伴们肯定知道,这么说吧,就是将一些使用频率较高的数据放于内存中,并 ...
- geotrellis使用(二十五)将Geotrellis移植到spark2.0
目录 前言 升级spark到2.0 将geotrellis最新版部署到spark2.0(CDH) 总结 一.前言 事情总是变化这么快,前面刚写了一篇博客介绍如何将geotrellis移植 ...
- C#字符串的倒序输出
介绍 在本文中,我将演示如何将字符串的单词倒序输出.在这里我不是要将“John” 这样的字符串倒序为成“nhoJ”,.这是不一样的,因为它完全倒序了整个字符串.而以下代码将教你如何将“你 好 我是 缇 ...
- 【分布式】Zookeeper使用--开源客户端
一.前言 上一篇博客已经介绍了如何使用Zookeeper提供的原生态Java API进行操作,本篇博文主要讲解如何通过开源客户端来进行操作. 二.ZkClient ZkClient是在Zookeepe ...
- ManualResetEvent知识总结
一. 用法概述 Manual发音:英[ˈmænjuəl] 直译,手动重置事件 开发者的可以手动对线程间的交互进行手动控制. 二.构造函数 构造函数,如果为 true,则将初始状态设置为终止:如果为 f ...
- 在DevExpress程序中使用TeeList控件以及节点查询的处理
在很多情况下,我们需要通过树列表进行数据的展示,如一些有层次关系的数据,通过有层级的展示,能够使用户更加直观查看和管理相关的数据.在一般Winform开发的情况下,可以使用微软的TreeView控件, ...