jqgrid控件列分组

<%-- builed by manage.aspx.cmt [ver:2014.48.11] at 2014/10/11 16:48:33 --%>

<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="SysDictManage.aspx.cs"
Inherits="HraWeb.SysDictManage" %>

<%@ Register Assembly="Trirand.Web" TagPrefix="asp" Namespace="Trirand.Web.UI.WebControls" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<style>
.left
{
width: 20%;
float: left;
overflow: auto;
display: inline;
height: 300px;
}
.right
{
width: 80%;
float: left;
overflow: hidden;
display: inline;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="toolbar" class="datagrid-toolbar">
<span class="title">字典名称:</span><input type="text" id="txt_Name_LK_" name="txt_Name_LK_"
class="input datacontrol" style="width: 100px" />
<span class="title">字典类别:</span>
<asp:TextBox runat="server" ID="prm_TypeCode_" CssClass="input datacontrol" Style="width: 180px" />
<a href="#" id="btn_add" iconcls="icon-add" class="button">新增</a> <a href="#" id="btn_edit"
iconcls="icon-edit" class="button">编辑</a> <a href="#" id="btn_del" iconcls="icon-remove"
class="button">删除</a> <a href="#" id="btn_search" iconcls="icon-search" class="button">
查询</a>
<asp:Button runat="server" ID="aa" OnClick="groupbtn"/>
</div>
<div style="width: 100%">
<%-- GroupSettings-CollapseGroups="true" GroupSettings-ShowSummaryOnHide="true" --%>
<div class="left">
<ul id="tt" class="easyui-tree">
</ul>
</div>
<div class='right'>
<asp:JQGrid runat="server" ID="jq" SortSettings-InitialSortColumn="Sequence" AutoWidth="True"
Height="400" DataUrl="/admin/Sys/SysDictManage.aspx?_method=search">

<Columns>

<asp:JQGridColumn DataField="Name" Visible="true" HeaderText="字典名称">
</asp:JQGridColumn>
<asp:JQGridColumn DataField="Code" Visible="true" HeaderText="字典编码">
</asp:JQGridColumn>
<asp:JQGridColumn DataField="TypeCode" Visible="true" HeaderText="字典类别">
<Formatter>
<asp:CustomFormatter FormatFunction="ChangeType" />
</Formatter>
</asp:JQGridColumn>
<asp:JQGridColumn DataField="IsActive" TextAlign="Center" Width="80" FixedWidth="True"
Visible="true" HeaderText="是否有效">
<Formatter>
<asp:CheckBoxFormatter />
</Formatter>
</asp:JQGridColumn>
<asp:JQGridColumn DataField="Sequence" Visible="false" HeaderText="顺序">
</asp:JQGridColumn>
<asp:JQGridColumn DataField="Id" Visible="False" HeaderText="数据字典ID" PrimaryKey="true">
</asp:JQGridColumn>
</Columns>

<%-- <HeaderGroups>
<asp:JQGridHeaderGroup StartColumnName="TypeCode" />
</HeaderGroups>--%>
<GroupSettings CollapseGroups="true" ShowSummaryOnHide="false">
<GroupFields>
<asp:GroupField DataField="TypeCode" ShowGroupColumn="true" GroupSortDirection="Asc" />
</GroupFields>
</GroupSettings>
<ClientSideEvents LoadComplete="JDataGrid.loadComplete" RowDoubleClick="JDataGrid.rowDoubleClick" />
</asp:JQGrid>
</div>
</div>
</form>
<script type="text/javascript">
var parentId = "";
function LoadTree() {
DataGrid.WaitMessage();
$("#tt").tree(
{ url: 'SysDictManage.aspx?_method=LoadDictType&a=' + Math.random(),
method: 'post',
animate: true,
onClick: function (node) {

var queryParams = $("body").GetSearchPostData();

if ($("#txt_Name_LK_").val() == "") {

queryParams["txt_Name_LK_"] = "";
}
//右边的easyui树代表字典类别TypeCode,下拉框prm_TypeCode_也是字典类别, 当点击树节点的时候,查询以点击的节点的字典类别为主,
//下拉框选择的字典类别prm_TypeCode_应当不再起作用所以设置
//queryParams["prm_TypeCode_"] = "";queryParams["txt_TypeCode_"] = node.id;
queryParams["prm_TypeCode_"] = "";
if (node.id != "-1")
queryParams["txt_TypeCode_"] = node.id;
else {
queryParams["txt_TypeCode_"] = "";
}
queryParams["ParentName"] = node.text;
$.post("SysDictManage.aspx?_method=MemoDictTypeCode&TypeCode=" + node.id + "&TypeName=" + node.text);

$("#jq").jqGrid("setGridParam", { page: 1, postData: queryParams }).trigger("reloadGrid");
},
onLoadSuccess: function (node, data) {
DataGrid.RemoveWaitMessage();
}
}
);

}


function getJson() {
var url = 'SysDictManage.aspx?entityType=SysDictType&_method=entity&tmp=' + Math.random() + '&queryTextFild=Name&idFild=Code';
$.ajax({
async: false,
type: "post",
url: url,
data: {},
dataType: "json",
success: function (data) {
jsonDic = data;
}
});
}

var jsonDic;

function PageOnLoad() {

LoadTree();
$(" .left").height(ComputGridHeight(100));
UTIL.SetEntityCombo($("#prm_TypeCode_"), "SysDictType", "Name", [[
{ field: 'Code', title: '字典编码', align: 'left', width: 40 },
{ field: 'Name', title: '字典名称', width: 40 }
]], null, 'Code');
//控件按钮设置
$(".button").linkbutton({ plain: true });

$("#btn_search").click(function () {
var queryParams = $("body").GetSearchPostData();
var row = $("#prm_TypeCode_").combogrid('grid').datagrid('getSelected');
if (row != null) {
queryParams["prm_TypeCode_"] = row.Code;
} else {
$("#prm_TypeCode_").val();

}
$("#jq").jqGrid("setGridParam", { postData: queryParams, page: 1 }).trigger("reloadGrid");
});
//参数说明:控件Id,查询地址,编辑页面的宽度,高度,编辑页面标题,新增按钮,编辑按钮,删除按钮,查询按钮,查询回调函数
JDataGrid.InitGrid("jq", "/admin/Sys/SysDictEdit.aspx", 600, 270, "数据字典", null, $("#btn_edit"), $("#btn_del"), $("#btn_search"));
$("#btn_add").click(function () {
var url = "/admin/Sys/SysDictEdit.aspx?x=1";
var menuId = UTIL.getUrlParam("_menuId");
if (menuId != null) {
url += "&_menuId=" + menuId;
}
if (parentId != "") {
url += "&typeId=" + parentId;
}
JDataGrid.Add(url, 600, 270, "数据字典");
});
}
function ChangeType(value, indx, rec) {

while (jsonDic == undefined) {
jsonDic = UTIL.GetChangeTypeJson("SysDictType", "Code", "Name");

}
return BindDictDrop(value, jsonDic, "Code", "Name", false);
}
</script>
</body>
</html>

 

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseService;
using Framework;
using HraWeb.Common;
using Trirand.Web.UI.WebControls;
using WebApp.Common;
using Contract.Domain;
using System.Collections;

namespace HraWeb
{
public partial class SysDictManage : JQEntityManage<Contract.Domain.SysDict>
{
protected override void Page_Load(object sender, EventArgs e)
{

//jq.GroupSettings.GroupFields.Add(new GroupField()
//{
// DataField = "IsActive",
// ShowGroupColumn = true,
// GroupSortDirection = Trirand.Web.UI.WebControls.SortDirection.Desc
//});

//给基类服务接口复制,可不付
//base.svc = Psvc;
if (!IsPostBack)
{
if (Request["_method"]=="LoadDictType")
{
LoadDictType();
}
if (!string.IsNullOrEmpty(Request["_method"]) && Request["_method"] == "MemoDictTypeCode")
{
string TypeCode = Request["TypeCode"] ?? "";
if (!string.IsNullOrEmpty(TypeCode))
{
Session["TypeCode"] = TypeCode;
}
HttpContext.Current.Response.End();
}
else if (Request["_method"] == "entity")
{
string entityType = Request["entityType"] ?? "";
if (!string.IsNullOrEmpty(entityType))
{
info = new QueryInfo();
info.QueryObject = "SysDictType";
IList list1 = Dao.FindList(info);
//IList<SysDictType> list = Holworth.Utility.Utility.ListToT<SysDictType>(list1);
HttpContext.Current.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(list1));
HttpContext.Current.Response.End();

}
}
//if (string.IsNullOrEmpty(Request["_method"]))
//{
// Framework.QueryInfo info = new Framework.QueryInfo();
// info.QueryObject = "SysDictType";
// IList dictList = Dao.FindList(info);
// prm_TypeCode_.DataSource = dictList;
// prm_TypeCode_.DataTextField = "Name";
// prm_TypeCode_.DataValueField = "Code";
// prm_TypeCode_.DataBind();
// prm_TypeCode_.Items.Insert(0, new ListItem());
//}
}
base.Page_Load(sender, e);
}


private void LoadDictType()
{
Session["TypeCode"] = Request["TypeCode"];
Framework.QueryInfo info = new Framework.QueryInfo();
info.QueryObject = "SysDictType";
IList dictList = Dao.FindList(info);
IList<SysDictType> typeList = Holworth.Utility.Utility.ListToT<SysDictType>(dictList);
typeList = (from s in typeList orderby s.Name ascending select s).ToList();
EasyUiTree node = new EasyUiTree();
node.id = "-1";
node.text = "字典类型";
foreach (Contract.Domain.SysDictType dict in typeList)
{
if (node.children == null)
{
node.children = new List<EasyUiTree>();
}
var child = new EasyUiTree();
child.id = dict.Code;
child.text = dict.Name;
node.children.Add(child);
}
System.Collections.ArrayList list = new ArrayList();
list.Add(node);
Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(list));
Response.End();

}
/// <summary>
/// 设置查询条件或者语句
/// </summary>
/// <returns></returns>
protected override Framework.QueryInfo SetInfo()
{
info = base.SetInfo();


string ParentName = string.Empty;



//if (!string.IsNullOrEmpty(Request["ParentId"]))
{
//Session["ParentName"] = Request["ParentName"].ToString();

//if (Request["ParentId"] != "-1")
//{
// info.Parameters.Clear();
// info.AddParam("TypeCode", Request["ParentId"]);
//}
}
return info;
}
/// <summary>
/// 初始化页面控件
/// </summary>
protected override void InitPage()
{
base.InitPage();

// BindDrop(drp_Unit, "SPSW", true);
}
//private Contract.IService.ISysDictService psvc;
///// <summary>
///// 初始化
///// </summary>
//Contract.IService.ISysDictService Psvc
//{
// get
// {
// if (psvc == null)
// {
// psvc = ctx.GetObject("SysDictService") as Contract.IService.ISysDictService;
// }
// return psvc;

// }
//}
protected void groupbtn(object sender, EventArgs e)
{
jq.GroupSettings.GroupFields.Add(new GroupField()
{
DataField = "Sequence",
ShowGroupColumn = true,
GroupSortDirection = Trirand.Web.UI.WebControls.SortDirection.Desc
});
jq.DataBind();

}
}
}

posted on 2015-08-22 12:11  听哥哥的话  阅读(1409)  评论(0编辑  收藏  举报

导航