easyui-tabs 页签绑定click事件,动态加载jqgrid

1.前台代码

<%-- builed by manage.aspx.cmt [ver:2015.14.27] at 2015/7/27 15:14:34 --%>


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

<%@ Register Assembly="Trirand.Web" TagPrefix="asp" Namespace="Trirand.Web.UI.WebControls" %>
<%@ Register TagPrefix="a" Namespace="System.Runtime.Serialization" Assembly="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" %>

<!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>
</head>
<body>
<form id="form1" runat="server">
<div id="ceng" style="height: 100px;">
<div class="easyui-tabs" id="tabs" style="width: 100%; height: 10px;">
<div title="资产负债表" style="padding: 10px">
<div id="toolbar1" class="datagrid-toolbar">
<span class="title">公司名称1:</span><input type="text" id="txt_CompanyName1_LK_" name="txt_CompanyName1_LK_" class="input datacontrol" style="width: 200px" />
<a href="#" id="btn_add1" iconcls="icon-add" class="button add">新增</a>
<a href="#" id="btn_edit1" iconcls="icon-edit" class="button edit">编辑</a>
<a href="#" id="btn_del1" iconcls="icon-remove" class="button del">删除</a>
<a href="#" id="btn_search1" iconcls="icon-search" class="button search">查询</a>
<a href="#" id="btn_import1" iconcls="icon-import" class="button">导入</a>
<a href="#" id="btn_DelHistory1_" iconcls="icon-remove" class="button">删除历史数据</a>
</div>
</div>
<div title="收支利润表" style="padding: 10px">
<div id="toolbar2" class="datagrid-toolbar">
<span class="title">公司名称2:</span><input type="text" id="txt_CompanyName2_LK_" name="txt_CompanyName2_LK_" class="input datacontrol" style="width: 200px" />
<a href="#" id="btn_add2" iconcls="icon-add" class="button add">新增</a>
<a href="#" id="btn_edit2" iconcls="icon-edit" class="button edit">编辑1</a>
<a href="#" id="btn_del2" iconcls="icon-remove" class="button del">删除</a>
<a href="#" id="btn_search2" iconcls="icon-search" class="button search">查询</a>
<a href="#" id="btn_import2" iconcls="icon-import" class="button">导入</a>
<a href="#" id="btn_DelHistory2_" iconcls="icon-remove" class="button">删除历史数据</a>
</div>

</div>
<div title="现金流量表" style="padding: 10px">
<div id="toolbar3" class="datagrid-toolbar">
<span class="title">公司名称3:</span><input type="text" id="txt_CompanyName3_LK_" name="txt_CompanyName_LK_" class="input datacontrol" style="width: 200px" />
<a href="#" id="btn_add3" iconcls="icon-add" class="button add">新增</a>
<a href="#" id="btn_edit3" iconcls="icon-edit" class="button edit">编辑</a>
<a href="#" id="btn_del3" iconcls="icon-remove" class="button del">删除</a>
<a href="#" id="btn_search3" iconcls="icon-search" class="button search">查询</a>
<a href="#" id="btn_import3" iconcls="icon-import" class="button">导入</a>
<a href="#" id="btn_DelHistory3_" iconcls="icon-remove" class="button">删除历史数据</a>
</div>
</div>
</div>

</div>
<div>
<asp:JQGrid runat="server" ID="jq" Height="300" MultiSelect="True" DataUrl="/CCR/CcrCompanyManage.aspx?_method=searchlist">
<Columns>
<asp:JQGridColumn DataField="CompanyName" Visible="true" HeaderText="公司名称" Frozen="True"></asp:JQGridColumn>


<asp:JQGridColumn DataField="Id" Visible="false" PrimaryKey="true"></asp:JQGridColumn>
</Columns>
<ClientSideEvents LoadComplete="JDataGrid.loadComplete" />
</asp:JQGrid>
</div>

</form>
<script language="javascript" type="text/javascript">
$(".easyui-tabs").width(screen.width * 0.878);
$(".easyui-tabs").height(ComputGridHeight(50));
var height = screen.height * 0.61;

</script>

<script type="text/javascript">
var jsonDic;
var parentId = "";
var jsonDic2;
var sel = false;
var url = "";
$(function () {
var tabs = $("#tabs").tabs().tabs('tabs');
var title = "";
for (var i = 0; i < tabs.length; i++) {
///以下代码是为页签动态绑定单击事件 tabs[i].panel(
'options').tab.unbind().bind('click', { index: i }, function (e) { title = ($(this).find(".tabs-title").html()); switch (title) { case "资产负债表": source = "CcrBalanceSheet"; break; case "收支利润表": source = "CcrIncomeStatement"; break; case "现金流量表": source = "CcrCashFlowStatement"; break; } url = "/CCR/" + source + "Edit.aspx"; $.post("CcrCreditInputDataManage.aspx?_method=setDataUrl", {url:url,title:title}); form1.action = "/CCR/CcrCreditInputDataManage.aspx?_method=SetGridDataSource&source=" + source; form1.submit(); }); } }); function PageOnLoad() { InitDrop(); $("#ceng").height(ComputGridHeight(480)); url = "<%=Session["CcrCreditInputDataEditUrl"]%>"; var tabTitle = "<%=Session["CcrCreditInputDataTabTtile"]%>"; $("#tabs").tabs("select",tabTitle); JDataGrid.InitGrid("jq", url, 700, 300, tabTitle, $(".add"), $(".edit"), $(".del"), $(".search")); $("#jq").setGridHeight("370"); $("#btn_search1").click(function () { var queryParams = $("body").GetSearchPostData(); var row = $("#txt_CompanyName2_LK_").combogrid("grid").datagrid("getSelected"); if (row != null) { queryParams["txt_CompanyName_LK_"] = row.Id; } else { queryParams["txt_CompanyName_LK_"] = ""; } $("#tb1").jqGrid("setGridParam", { postData: queryParams, page: 1 }).trigger("reloadGrid"); }); $("#btn_DelHistory1_").click(function () { //删除历史记录 PW.getWindow("/CCR/DelCcrCreditRawDataChoice.aspx", "删除历史数据", 800, 500); }); $("#btn_DelHistory2_").click(function () { //删除历史记录 PW.getWindow("/CCR/DelCcrCreditRawDataChoice.aspx", "删除历史数据", 800, 500); }); $("#btn_import1").click(function () { PW.getWindow("/CCR/CcrCreditRawDataUpFileManage.aspx", "上传", 800, 500); }); $("#btn_import2").click(function () { PW.getWindow("/CCR/CcrCreditRawDataUpFileManage.aspx", "上传", 800, 500); }); //控件按钮设置 $(".button").linkbutton({ plain: true }); } function InitDrop() { UTIL.SetEntityCombo($("#txt_CompanyName2_LK_"), "CcrFundermental", "CompanyName", [[ { field: 'Id', title: '客户id', align: 'left', width: 40 }, { field: 'CompanyName', title: '公司名称', width: 40 } ]], null, "Id"); } </script> </body> </html> 2.后台代码 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using HraWeb.Common; using WebApp.Common; using Contract.Domain; using System.Collections; using System.Text; using DevExpress.XtraRichEdit.SpellChecker; using HraModel.Sys.Enum; using Trirand.Web.UI.WebControls; namespace HraWeb { public partial class CcrCreditInputDataManage : JQEntityManage<Contract.Domain.CcrCreditInputData> { private Spring.Caching.ICache cache; private Spring.Caching.ICache SpringCache { get { if (cache == null) cache = (Spring.Caching.ICache)ctx.GetObject("AspNetCache"); return cache; } set { cache = value; } } private void InitGrid(string entityName) { SpringCache.Remove("CcrCreditInputDataManage_JQ_SEL_TAB"+System.Environment.UserDomainName+System.Environment.UserName); SpringCache.Insert("CcrCreditInputDataManage_JQ_SEL_TAB" + System.Environment.UserDomainName + System.Environment.UserName,entityName); ArrayList colInfoList = GetTableInfo(ListAndTableExtension.ConvertToTableColumnName(entityName)); if (colInfoList != null && colInfoList.Count > 0) { int i = 0; foreach (dynamic c in colInfoList) { JQGridColumn col = new JQGridColumn(); col.DataField = ListAndTableExtension.ConvertToEntityColumnName(c.ColumnName); col.HeaderText = c.Comments; i++; if (col.DataField != "Id") jq.Columns.Add(col); } JQGridColumn cc = new JQGridColumn(); cc.DataField = "Id"; cc.Frozen = true; cc.PrimaryKey = true; cc.Visible = true; cc.HeaderText = "PK"; jq.Columns.Insert(0, cc); } else { throw new Exception("表不存在或未定义任何列"); } jq.DataUrl = string.Format("/CCR/CcrCreditInputDataManage.aspx?_method=search&source="+entityName, entityName); jq.ComputHeight = string.Empty; jq.Height = 150; jq.Width = int.Parse((System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width * 0.6).ToString().Split('.')[0]); } private ArrayList GetTableInfo(string tableName) { info = new Framework.QueryInfo(); info.Parameters.Add("table_name", tableName); System.Data.DataSet ds = Holworth.Utility.HraUtility.EntityRowMapper.ExcuteDataSet("ETLColumn", info, Server.MapPath("~/config/ETL.xml")); System.Collections.ArrayList list = new System.Collections.ArrayList(); for (var i = 0; i < ds.Tables[0].Rows.Count; i++) { var row = ds.Tables[0].Rows[i]; var obj = new { Comments = string.IsNullOrEmpty(row["comments"].ToString()) ? row["column_name"].ToString() : row["comments"].ToString(), ColumnName = row["column_name"].ToString() }; list.Add(obj); } return list; } protected override void Page_Load(object sender, EventArgs e) { jq.ComputHeight = string.Empty; jq.Height = 300; ArrayList list = GetTableInfo("CCR_BALANCE_SHEET"); StringBuilder sb = new StringBuilder(); sb.AppendLine("$(\"#tb3\").jqGrid({,"); sb.AppendLine("url:url,"); sb.AppendLine("datatype:\"json\","); sb.AppendLine("width:\"90%\","); sb.AppendLine("height:height,"); sb.AppendLine("colNames:[{0}" + "],"); sb.AppendLine("colModel:[{1}" + "],"); sb.AppendLine("viewrecords:true,"); sb.AppendLine("rowNum:25"); sb.AppendLine("rowList:[5,10,15]"); sb.AppendLine("pager:\"#gridPager1\""); sb.AppendLine("ondblClickRow:function(rowid){} }).navGrid('#gridPager3', { edit: false, add: false, del: false });"); string colNames = ""; string colModels = ""; foreach (dynamic item in list) { colNames +="'"+ item.Comments.ToString().Split('-') [0]+ "'" + ","; } string s = sb.ToString(); foreach (dynamic item in list) { colModels += "{name:" +"'"+ item.ColumnName+"'" + "," + "index:" + "'" + item.ColumnName + "'"+"},\n"; } //给基类服务接口复制,可不付 //base.svc = Psvc; if (!IsPostBack) { } switch (Request["_method"]) { case "SetGridDataSource": InitGrid(Request["source"]); break; case "setDataUrl": Session["CcrCreditInputDataEditUrl"] = Request["url"]; Session["CcrCreditInputDataTabTtile"] = Request["title"]; break; } base.Page_Load(sender, e); } protected override void setDataSource() { if ((string.IsNullOrEmpty(info.QueryObject) && string.IsNullOrEmpty(info.CustomSQL))) { info.QueryObject = SpringCache.Get("CcrCreditInputDataManage_JQ_SEL_TAB" + System.Environment.UserDomainName + System.Environment.UserName).ToString(); } if (svc == null) { info = Dao.FindByQueryInfo(info); } else { info = svc.FindByQueryInfo(info); } } /// <summary> /// 设置查询条件或者语句 /// </summary> /// <returns></returns> protected override Framework.QueryInfo SetInfo() { info = base.SetInfo(); if (Request["_menuId"] == "7004122") { info.AddParam("Purpose", ((int)SysEnum.CCR_Credit_Score_Training).ToString()); } if (Request["_menuId"] == "7004289") { info.AddParam("purpose", ((int)SysEnum.CCR_Credit_Score_Rating).ToString()); } return info; } } }

 

转载于:https://www.cnblogs.com/kexb/p/5100577.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值