easyui DatagrId 的实例讲解

下面是代码实现
@{
ViewBag.Title = "人员查找";
ViewBag.LeftWidth = "200px";
ViewBag.MiddleWidth = "200px";
}
<html>
<head>
<link href="../../../Script/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css" />
<link href="../../../Script/easyui/themes/icon.css" rel="stylesheet" type="text/css" />
<link href="../../../Content/themes/base/Common/common.css" rel="stylesheet" type="text/css" />
<script src="../../../Script/easyui/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="../../../Script/Common/json2.js" type="text/javascript"></script>
<script src="../../../Script/easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="../../../Script/easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../../Script/Common/Toolbar.js" type="text/javascript"></script>
<script src="../../../Script/easyui/plugins/JValidator.js" type="text/javascript"></script>
<script src="../../../Script/Common/Common.js" type="text/javascript"></script>
</head>
<body class="easyui-layout">
<div region="north" data-options="border:false" style="height: 50px;" >
<div style=" margin-top:15px; margin-left:15px" >
<a id="btn_byforDepmen" onclick="searchByforDep()" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'">
按部门设置</a>
<a id="btn_byforRose" onclick="searchByforRose()" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'">
按角色设置</a>
</div>
</div>
<div region="west" title="部门树" id="leftDepTree" split="true" style="width: 230px;">
<div style="border: 1px;">
<ul id="Deptree" class="easyui-tree">
</ul>
</div>
</div>
<div region="center">
<div id="cc" class="easyui-layout" data-options="fit:true,border:false">
<div region="center" title="选择人员">
<table id="SearchEmployeeList" class="easyui-datagrid" data-options="fit:true,border:true">
</table>
</div>
</div>
</div>
<div region="east" title="选中人员" split="true" style="width: 260px;">
<table id="EmployeeList" class="easyui-datagrid" fitColumns="true" data-options="fit:true,border:false"
checkOnSelect:"true" singleselect="false">
<thead>
<tr>
<th field="ck" width="50" checkbox="true">
</th>
<th field="UserId" hidden= "true" width="50">
</th>
<th field="RealName" width="50">
姓名
</th>
</tr>
</thead>
</table>
</div>
<div region="south" split="true" style="margin-bottom: 15px; margin-right: auto;
margin-left: auto; text-align: center">
<table>
<tr>
<td>
<a id="btn_query" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save'">确定</a>
</td>
<td>
<a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">
清空</a>
</td>
<td>
<a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">
取消</a>
</td>
</tr>
</table>
</div>
</body>
</html>
<script type="text/javascript">
//页面加载按部门搜索部门树列表
var MySearchEmployee = {
//加载左侧部门树
onloadDepTree: function (flag) { //部门树方法
$('#Deptree').tree({
checkbox: false,
url: '../SearchEmployee/GetOrganizationList',
onClick: function (node) {
//flag代表着开关, D表示加载部门信息
if (flag == "D") {
MySearchEmployee.EmployeeListByforOrg(node.EX1, node.id); //传递参数绑定gridList
}
else {
MySearchEmployee.onloadRoleTree(node.id); //加载员工数
}
}
});
$('#cc').layout('remove', 'west');
},
//加载左侧岗位上
onloadRoleTree: function (orgid) {
$('#roleTree').tree({
checkbox: false,
url: '../SearchEmployee/GetRoseList?orgID=' + orgid,
onClick: function (node) {
MySearchEmployee.onloadSeachEmpListByforRole(node.id); //加载人员列表
}
});
},
//清空原来的数据
removeEmpListTree: function () {//岗位树
MySearchEmployee.onloadDepTree("R");
//隐藏部门加载人员列表
var region = 'west';
var options = {
region: region
};
options.width = 260;
options.split = true;
options.title = "岗位树";
options.id = "leftroleTree";
$('#cc').layout('add', options);
$("#leftroleTree").append(" <div style=\"border: 1px;\"> <ul id=\"roleTree\" class=\"easyui-tree\"> </ul> </div> ");
var data = $('#SearchEmployeeList').datagrid('getData'); //清空下searList
for (var i = (data.total - 1); i >= 0; i--) {
$('#SearchEmployeeList').datagrid('deleteRow', i);
}
$('#EmployeeList').datagrid('clearChecked');
},
//点击部门按钮
checkDepTree: function () {
//去掉岗位树
$('#cc').layout('remove', 'west');
var data = $('#SearchEmployeeList').datagrid('getData'); //清空下searList
for (var i = (data.total - 1); i >= 0; i--) {
$('#SearchEmployeeList').datagrid('deleteRow', i);
}
$('#EmployeeList').datagrid('clearChecked');
MySearchEmployee.onloadDepTree("D");
},
onloadSeachEmpList: function (UserId, RealName) {//单击选中checkbox 确定最终的显示人
var contains = false;
var data = $('#EmployeeList').datagrid('getData');
if (data.total == 0) {
$('#EmployeeList').datagrid('insertRow', {
index: 1, // index start with 0
row: { "UserId": UserId, "RealName": RealName }
});
}
else {
for (var i = 0; i < data.total; i++) {
if (data.rows[i].UserId == UserId) {
contains = true;
break;
}
}
if (!contains) {
$('#EmployeeList').datagrid('insertRow', {
index: 1, // index start with 0
row: { "UserId": UserId, "RealName": RealName }
});
}
}
$('#EmployeeList').datagrid('checkAll'); //默认全部选中
},
EmployeeListByforOrg: function (Category, OrganizationId) {//根据部门的ID和种类查询出本部门下所有的人员
var param = {
"Category": Category, "OrganizationId": OrganizationId
};
$("#SearchEmployeeList").datagrid({
url: '../SearchEmployee/GetEmployeeByForOrg',
nowrap: false, //是否换行,True 就会把数据显示在一行里
striped: true, //True 奇偶行使用不同背景色
fitColumns: true, //True 就会自动扩大或缩小列的尺寸以适应表格的宽度并且防止水平滚动。
queryParams: param,
onSelect: function (rowIndex, rowData) //选中时绑定人员表
{
MySearchEmployee.onloadSeachEmpList(rowData.UserId, rowData.RealName);
},
onUnselect: function (rowIndex, rowData) { //取消选中是的时候同时也要删
MySearchEmployee.UnloadEmployeeList(rowData.UserId);
},
onSelectAll: function (rows) //全部选中
{
MySearchEmployee.onSelectAllByforSearchEmployeeList(rows); //全部选中
},
onUnselectAll: function (rows) {
MySearchEmployee.onUnselectAllByforSearchEmployeeList(rows); //全部不选中
},
onLoadSuccess: function (data) {
MySearchEmployee.selectedByforSeacherEmployeeList(data);
},
columns: [[
{ field: 'ck', checkbox: 'true', width: 30 },
{ field: 'UserId', width: 30, hidden: true },
{ field: 'RealName', title: '姓名', width: 300 }
]]
});
},
//根据角色树加载List列表
onloadSeachEmpListByforRole: function (roleID) {
var param = {
"roleID": roleID
};
$("#SearchEmployeeList").datagrid({
url: '../SearchEmployee/GetUserByforRole',
nowrap: false, //是否换行,True 就会把数据显示在一行里
striped: true, //True 奇偶行使用不同背景色
fitColumns: true, //True 就会自动扩大或缩小列的尺寸以适应表格的宽度并且防止水平滚动。
queryParams: param,
onSelect: function (rowIndex, rowData) //选中时绑定人员表
{
MySearchEmployee.onloadSeachEmpList(rowData.UserId, rowData.RealName);
},
onUnselect: function (rowIndex, rowData) { //取消选中是的时候同时也要删
MySearchEmployee.UnloadEmployeeList(rowData.UserId);
},
onSelectAll: function (rows) //全部选中
{
MySearchEmployee.onSelectAllByforSearchEmployeeList(rows); //全部选中
},
onUnselectAll: function (rows) {
MySearchEmployee.onUnselectAllByforSearchEmployeeList(rows); //全部不选中
},
onLoadSuccess: function (data) {
MySearchEmployee.selectedByforSeacherEmployeeList(data);
},
columns: [[
{ field: 'ck', checkbox: 'true', width: 30 },
{ field: 'UserId', width: 30, hidden: true },
{ field: 'RealName', title: '姓名', width: 300 }
]]
});
},
UnloadEmployeeList: function (UserId) { //取消的时候删除行
//根据userID查找这一行的索引
var data = $('#EmployeeList').datagrid('getData');
for (var i = 0; i < data.total; i++) {
if (data.rows[i].UserId == UserId) {
$('#EmployeeList').datagrid('deleteRow', i);
}
}
},
unselectRowEmployeeList: function (UserId) { //去除已经选择上的人员,并且在SearchEmployeeList把打钩去掉
var data = $('#SearchEmployeeList').datagrid('getData');
for (var i = 0; i < data.total; i++) {
if (data.rows[i].UserId == UserId) {
$('#SearchEmployeeList').datagrid('unselectRow', i);
}
}
},
onSelectAllByforSearchEmployeeList: function (rows) { //SearchEmployeeList 全选
//那么EmployeeList 就要显示选中的行
//选清空一下
// $('#EmployeeList').datagrid('clearChecked');
//然后在增加
for (var i = 0; i < rows.length; i++) {
MySearchEmployee.onloadSeachEmpList(rows[i].UserId, rows[i].RealName);
}
},
onUnselectAllByforSearchEmployeeList: function (rows) { //SearchEmployeeList 全不选
var data = $('#EmployeeList').datagrid('getData'); //获取当前的EmloyeeList所有的数据
//删除EmployeeList
for (var i = 0; i < rows.length; i++) {
for (var k = 0; k < data.total; k++) {
if (rows[i].UserId == data.rows[k].UserId) {
$('#EmployeeList').datagrid('deleteRow', k);
}
}
}
},
onloadForEmployeeList: function () {
$("#EmployeeList").datagrid({
onUnselect: function (rowIndex, rowData) {
$('#EmployeeList').datagrid('deleteRow', rowIndex); //删除当前行
MySearchEmployee.unselectRowEmployeeList(rowData.UserId); //去除SearchEmployeeList打钩数据
},
onLoadSuccess: function (data) { //接收data
//全局变量
},
onUnselectAll: function (rows) {
MySearchEmployee.deleteAllforEmployeeList(rows); //删除所有的列表人员
}
});
},
deleteAllforEmployeeList: function (rows) { //清空选中的列表
var data = $('#SearchEmployeeList').datagrid('getData'); //获取当前的EmloyeeList所有的数据
var arryList = [];
for (var i = (rows.length - 1); i >= 0; i--) {
for (var k = 0; k < data.total; k++) {
if (data.rows[k].UserId == rows[i].UserId) {
arryList.push(k);
}
}
$('#EmployeeList').datagrid('deleteRow', i); //删除list列表
}
for (var i = 0; i < arryList.length; i++) {
$('#SearchEmployeeList').datagrid('unselectRow', arryList[i]);
}
},
selectedByforSeacherEmployeeList: function (Depdata) { //执行回调打钩
var Empdata = $('#EmployeeList').datagrid('getData');
var arryList = []; //存放索引的值
for (var i = 0; i < Depdata.total; i++) {
for (var k = 0; k < Empdata.total; k++) {
if (Depdata.rows[i].UserId == Empdata.rows[k].UserId) {
arryList.push(i);
}
}
}
for (var i = 0; i < arryList.length; i++) {
$('#SearchEmployeeList').datagrid('checkRow', arryList[i]); // checkRow selectRow
}
},
retureEmpListData: function () { //返回提交EmpList表中的数据
var Empdata = $('#EmployeeList').datagrid('getData');
return Empdata.rows;
}
};
//单击部门
function searchByforDep() { //按部门搜索
MySearchEmployee.checkDepTree();
}
//单击按角色查询
function searchByforRose() {
MySearchEmployee.removeEmpListTree(); //加载角色权限树
}
$("#btn_query").click(function () { //点击确定回传数据
// MySearchEmployee.retureEmpListData();
});
//页面初始化
$(function () {
MySearchEmployee.onloadDepTree("D");
MySearchEmployee.onloadForEmployeeList(); //页面出
});
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Web.Mvc;
using System.Web;
using System.Data;
using GWork.Models;
using Newtonsoft.Json;
using GWork.DataAccess;
using GWork.Business;
using GWork.IBusiness;
using SysManager.Models;
using SysManager.Common.Utilities;
using Newtonsoft.Json.Converters;
namespace GWork.Controllers.OpenWindows.SearchEmployee
{
public class SearchEmployeeController : Controller
{
private SYS_User userinfo = new SYS_User();
private SYS_Organization organizationinfo = new SYS_Organization(); //权限表中的组织部门
private SysManager.IBusiness.IOrganizationBLL organizationibll = SysManager.Business.BusinessFactory.Instance.CreateOrganization();//部门工厂
private SysManager.IBusiness.IRolesBLL rolesbll = SysManager.Business.BusinessFactory.Instance.CreateRoles();//角色工厂
private SysManager.IBusiness.IUserBLL userbll = SysManager.Business.BusinessFactory.Instance.CreateUser();// 获取员工用户方法
public ActionResult SearchEmployeeList()
{
return View();
}
#region 获取部门列表树集合
/// <summary>
/// 获取部门列表树集合
/// </summary>
/// <returns></returns>
public string GetOrganizationList()
{
System.Collections.IList orgainList = organizationibll.GetList();//获取部门方法
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";
List<SYS_Organization> listtree = SysManager.Common.Utilities.IListHelper.IListToList<SYS_Organization>(orgainList);//将IList 转化成List
SYS_Organization orgobj = listtree.Find(org => org.ParentId == "0");//构造顶级节点//(数据库中用的是O)
LEFTTREE lefttree = new LEFTTREE();
lefttree.ID = orgobj.OrganizationId; //树节点
lefttree.TEXT = orgobj.FullName; //公司名称
lefttree.CHILDREN = new List<LEFTTREE>(); //树子节点
lefttree.EX1 = orgobj.Category;// (额外条件种类)
TreeDiGui(lefttree.ID, lefttree, listtree); //递归用法
return "[" + JsonConvert.SerializeObject(lefttree).Replace("TEXT", "text").Replace("ID", "id").Replace("CHILDREN", "children") + "]";
}
#region 查找树的子节点
/// <summary>
/// 查找树的子节点
/// </summary>
/// <param name="sb"></param>
/// <param name="ParentId"></param>
/// <returns></returns>
public LEFTTREE TreeDiGui(string ParentId, LEFTTREE LEFTTREE, IEnumerable<SYS_Organization> ALLTREE)
{
//
IEnumerable<SYS_Organization> FindTree = ALLTREE.Where(new Func<SYS_Organization, bool>(d => d.ParentId == ParentId));
foreach (SYS_Organization item in FindTree)
{
LEFTTREE ChildTree = new LEFTTREE();
ChildTree.ID = item.OrganizationId;
ChildTree.TEXT = item.FullName;
ChildTree.CHILDREN = new List<LEFTTREE>();
ChildTree.EX1 = item.Category;//种类
LEFTTREE.CHILDREN.Add(ChildTree);
TreeDiGui(ChildTree.ID, ChildTree, ALLTREE);
}
return LEFTTREE;
}
#endregion
#region 根据部门查找该部门下所有的人
/// <summary>
/// 根据组织部门下的人员
/// </summary>
/// <returns></returns>
public string GetEmployeeByForOrg()
{
try
{
string Category = Request["Category"].ToString(); //获取种类
string OrganizationId = Request["OrganizationId"].ToString();//获取部门ID
System.Collections.IList userIList = userbll.GetDataTableByOrganizationId(Category, OrganizationId);//根据种类和orgid查询出该部门下所有的人员
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";
List<SYS_User> userList = SysManager.Common.Utilities.IListHelper.IListToList<SYS_User>(userIList);//把得到IList转化成List格式
return JsonConvert.SerializeObject(userList, timeConverter);
}
catch (Exception ex)
{
throw (ex);
}
}
#endregion
#endregion
#region 获取岗位列表树集合
/// <summary>
/// 获取角色列表集合
/// </summary>
/// <returns></returns>
public string GetRoseList() //string
{
string orgID = Request["orgID"].ToString();//获取orgID
System.Collections.IList roseList = rolesbll.GetList(orgID);
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";
List<SYS_Roles> listtree = SysManager.Common.Utilities.IListHelper.IListToList<SYS_Roles>(roseList);//将IList 转化成List
List<LEFTTREE> List = new List<LEFTTREE>();
foreach (SYS_Roles item in listtree)
{
LEFTTREE lefttree = new LEFTTREE();
lefttree.ID = item.RoleId; //树节点
lefttree.TEXT = item.FullName; //公司名称
lefttree.CHILDREN = new List<LEFTTREE>(); //树子节点
List.Add(lefttree);
}
return JsonConvert.SerializeObject(List, timeConverter).Replace("TEXT", "text").Replace("ID", "id").Replace("CHILDREN", "children") ;
}
#endregion
#region 根据岗位角色条件查询人
/// <summary>
///根据角色条件查询
/// </summary>
/// <returns></returns>
public string GetUserByforRole()
{
try
{
string roleID = Request["roleID"].ToString();
string strWhere = " and roleid=" + "'" + roleID + "'";
System.Collections.IList userList = userbll.GetUserListBywhere(strWhere);
IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";
List<SYS_User> list = SysManager.Common.Utilities.IListHelper.IListToList<SYS_User>(userList);//把得到IList转化成List格式
return JsonConvert.SerializeObject(userList, timeConverter);
}
catch (Exception ex)
{
throw (ex);
}
}
#endregion
}
}
| -- |
easyui DatagrId 的实例讲解的更多相关文章
- Jquery EasyUI DataGrid .net实例
前台界面:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...
- JSON.stringify 语法实例讲解+easyui data-options属性+expires【申明:来源于网络】
JSON.stringify 语法实例讲解+easyui data-options属性+expires[申明:来源于网络] JSON.stringify 语法实例讲解:http://www.jb51. ...
- EasyUI datagrid优化
easyui datagrid 在IE上加载速度慢, 150行数据就无法忍受了. firefox加载速度还可以. jquery easyui datagrid使用参考 http://www.cnblo ...
- 实现easyui datagrid在没有数据时显示相关提示内容
本示例实现easyui datagrid加载/查询数据时,如果没有相关记录,则在datagrid中显示没有相关记录的提示信息,效果如下图所示 本实例要实现如下图所示的效果: 本示例easyui版本为1 ...
- jQuery EasyUI datagrid实现本地分页的方法
http://www.codeweblog.com/jquery-easyui-datagrid%e5%ae%9e%e7%8e%b0%e6%9c%ac%e5%9c%b0%e5%88%86%e9%a1% ...
- [转载]再次谈谈easyui datagrid 的数据加载
这篇文章只谈jQuery easyui datagrid 的数据加载,因为这也是大家谈论最多的内容.其实easyui datagrid加载数据只有两种方式:一种是ajax加载目标url返回的json数 ...
- 解决easyui datagrid加载数据时,checkbox列没有根据checkbox的值来确定是否选中
背景: 昨天帮朋友做一个easyui datagrid的小实例时,才发现easyui datagrid的checkbox列,没有根据值为true或false来选中checkbox,当时感觉太让人失 ...
- springMVC注解方式+easyUI+MYSQL配置实例
刚接触springMVC,使用的注解方式,也在学习阶段,所以把自己学习到的记下来.本文利用springMVC从数据库读取用户信息为例,分享一下. 1.准备相关架包及资源.因为使用springMVC+e ...
- 谈谈easyui datagrid 的数据加载(转)
这篇文章只谈jQuery easyui datagrid 的数据加载,因为这也是大家谈论最多的内容.其实easyui datagrid加载数据只有两种方式:一种是ajax加载目标url返回的json数 ...
随机推荐
- 调用subprocess调用shell命令时屏蔽标准输出
import os, subprocessp = subprocess.Popen(args, stdout = subprocess.PIPE,stderr = subprocess.STDOUT)
- software collection
software software Table of Contents 1. Privacy 2. GFW 2.1. google search 2.2. 修改 DNS 服务器 2.2.1. 修改ip ...
- DemoKit编译过程
E:\Project_code\EAE\src_rev_24139_A95LYD\Project\DemoKit>make release Checking uITRON - DemoKit r ...
- StringBuilder的构造方法
/* * String和StringBuilder的区别: * String的内容是固定的 * StringBuilder的内容是可变的 * 构造方法: * StringBuilder() * 成员方 ...
- h5dnd sortable mutil groups
h5dnd sortable mutil groups https://codepen.io/webgeeker/pen/JmPXaN https://codepen.io/webgeeker/pen ...
- hdu 2546 0-1背包
#include<stdio.h> #include<string.h> #define N 1100 int dp[N],a[N]; int main() { int n,m ...
- [51Nod1089] 最长回文子串 V2(Manacher算法)
1089 最长回文子串 V2(Manacher算法) 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 回文串是指aba.abba.cccbccc.aaaa这种左右对称 ...
- 关于Git的简单使用
新电脑git push一直出问题,到现在也没有解决,但是一些git的命令还是有用的,就先记下来吧.(下图就是没解决的报错) 一.上传本地项目到git 1.初始化git git init 2.配置用户名 ...
- BAT经典面试题,深入理解Java内存模型JMM
Java 内存模型 Java 内存模型(JMM)是一种抽象的概念,并不真实存在,它描述了一组规则或规范,通过这组规范定义了程序中各个变量(包括实例字段.静态字段和构成数组对象的元素)的访问方式.试图屏 ...
- - > 动规讲解基础讲解四——矩阵取数
给定一个m行n列的矩阵,矩阵每个元素是一个正整数,你现在在左上角(第一行第一列),你需要走到右下角(第m行,第n列),每次只能朝右或者下走到相邻的位置,不能走出矩阵.走过的数的总和作为你的得分,求最大 ...