<pre class="html" name="code"><body>
<table id="dg"></table>
<script>
$('#dg').treegrid({
url: '../ashprama/test.ashx',
idField: 'id',
treeField: 'DEPATMENT',
queryParams: {id:"all"},//这里的all只加载第一层数据
onBeforeExpand: function (row) {
if (row) {
$(this).treegrid('options').url = '../ashprama/test.ashx';
//这里不用再加参数,因为默认会post id=treefiedld的值过去,这也是我监听很久后才发现的
}
},
columns: [[
{ field: 'aaa', width: '30', sortable: 'true', order: 'desc' },
{ field: 'DEPATMENT', title: '部门', width: '150', sortable: 'true', order: 'desc' },
{ field: 'USER_NO', title: 'id', width: '70', hidden: 'true', sortable: 'true', order: 'desc' },
{ field: 'USER_NAME', title: '姓名', width: '70', sortable: 'true', order: 'desc' },
{ field: 'USER_JOB', title: '职务', width: '150', sortable: 'true', order: 'desc' },
{ field: 'TEL_OFFICE', title: '办公电话', width: '120', sortable: 'true', order: 'desc' },
{ field: 'FAX', title: '传真', width: '120', sortable: 'true', order: 'desc' },
{ field: 'OFFICE_NUB', title: '办公室 ', width: '70', sortable: 'true', order: 'desc' },
{ field: 'USER_ODERNUM', title: 'num', width: '70', hidden: 'true', sortable: 'true', order: 'desc' },
{ field: 'TEL_MOB', title: '手机号码', width: '120', sortable: 'true', order: 'desc' },
{
field: 'dongxiru', title: '编辑', width: '60', sortable: 'true', order: 'desc', formatter: function (value, row) {
if (row.USER_NAME != "") {
return '<a οnclick="telabc(\'' + row.USER_NAME + '\',\'' + row.DEPATMENT + '\')" href="javascript:void(0)">编辑</a>';
}
}
}]],
});
</script>
</body>
</pre><pre class="html" name="code" snippet_file_name="blog_20150505_3_4970237" code_snippet_id="659731">注意第一次加载与第二次加载返回的数据格式不一样,异步加载首次加载时必须设state为closed 点击加载返回的数据格式为[{},{}],不再需要使用到_parentid,首次加载格式为{total:11,rows:[{},{}]}
<pre class="csharp" name="code">using Oracle.DataAccess.Client;
using System;
using System.Collections.Generic;
using System.Web;
using gxqgsdz.dataprama;
using System.Data;
using System.Web.SessionState;
namespace gxqgsdz.ashprama
{
/// <summary>
/// tel_for_deplay 的摘要说明
/// </summary>
public class tel_for_deplay : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
string actionstr = context.Request["action"];
string mm="";
string sid = context.Request["id"];
string strid = "";
if (sid == "all")
{
mm = "[";
OracleParameter[] pan = { };
DataTable dt = new DataTable();
dt = qg_comm.getcommdata(1, 0, "qg_dept", "t.*", "deptparent is null", "t.deptno ASC");
if (dt.Rows.Count != 0)
for (int i = 0; i < dt.Rows.Count; i++)
{
strid = dt.Rows[i]["deptid"].ToString();
mm = mm + "{\"id\":\"" + strid + "\",\"USER_NO\":\"\",\"state\":\"closed\",\"USER_NAME\":\"\",\"USER_JOB\":\"\",\"TEL_OFFICE\":\"\",\"FAX\":\"\",\"TEL_MOB\":\"\",\"OFFICE_NUB\":\"\",\"USER_ODERNUM\":\"\",\"DEPATMENT\":\"" + dt.Rows[i]["deptname"].ToString() + "\"},";
if (getdepttojson(dt.Rows[i]["deptid"].ToString()) != "")
{
mm = mm + getdepttojson(dt.Rows[i]["deptid"].ToString()) + ",";//有下一级加载部门
}
}
mm = mm.Substring(0, mm.Length - 1);
mm = mm + "]";
mm = "{\"total\":307,\"rows\":" + mm + "}";
}
if (sid != "all")
{
mm ="["+ getempyeetojson(sid)+"]";
}
context.Response.Write(mm);
private static string getdepttojson(string dept)//dept为id 不是部门名
{
string deptsub = "";
DataTable ds = new DataTable();
ds = qg_comm.getcommdata(1, 0, "qg_dept", "t.*", "deptparent='" + dept + "'", "t.deptno desc");
if (ds.Rows.Count != 0)
{
for (int i = 0; i < ds.Rows.Count; i++)
{
deptsub = deptsub + "{\"id\":\"" + ds.Rows[i]["deptid"].ToString() + "\",\"USER_NO\":\"\",\"state\":\"closed\",\"_parentId\":\"" + dept + "\",\"USER_NAME\":\"\",\"USER_JOB\":\"\",\"TEL_OFFICE\":\"\",\"FAX\":\"\",\"TEL_MOB\":\"\",\"OFFICE_NUB\":\"\",\"USER_ODERNUM\":\"\",\"DEPATMENT\":\"" + ds.Rows[i]["deptname"].ToString() + "\"},";
}
deptsub = deptsub.Substring(0, deptsub.Length - 1);
}
return deptsub;
}
private static string getempyeetojson(string dept)
{
DataTable ds = new DataTable();
string strJson = "";
ds = qg_comm.getcommdata(1, 0, "qg_emplyee", "t.USER_NO,t.USER_NAME,t.USER_JOB,t.TEL_OFFICE,t.FAX,t.TEL_MOB,t.OFFICE_NUB,t.USER_ODERNUM,t.DEPATMENT", "depatment='" + dept + "'", "t.user_odernum ASC");
if (ds.Rows.Count != 0)
{
for (int i = 0; i < ds.Rows.Count; i++)
{
strJson = strJson + "{\"id\":\""+ ds.Rows[i]["user_no"].ToString() +"\",\"USER_NO\":\"" + ds.Rows[i]["user_no"].ToString() + "\",\"USER_NAME\":\"" + ds.Rows[i]["user_name"].ToString() + "\",\"USER_JOB\":\"" + ds.Rows[i]["user_job"].ToString() + "\",";
strJson = strJson + " \"TEL_OFFICE\":\"" + ds.Rows[i]["tel_office"].ToString() + "\",\"FAX\":\"" + ds.Rows[i]["fax"].ToString() + "\",\"TEL_MOB\":\"" + ds.Rows[i]["tel_mob"].ToString() + "\",\"OFFICE_NUB\":\"" + ds.Rows[i]["office_nub"].ToString() + "\",";
strJson = strJson + " \"USER_ODERNUM\":\"" + ds.Rows[i]["user_odernum"].ToString() + "\",\"DEPATMENT\":\"" + dept + "\"},";
}
strJson = strJson.Substring(0, strJson.Length - 1);
}
return strJson;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}