1.jcgrid实现

<span class="JcGrid" id="MyGrid" listdata="Rds.List.UserList" style="overflow: visible;
width: 100%;" jctype="jcgrid" valstring="Title:主Grid" onaddafter="OnAddAfter();">
<table border="0" width="100%" cellspacing="1" id="Table2">
<tr height="26" align="center">
<td type="indicator" cellvalign="middle" cellalign="center" style="width: 3%;">
&nbsp;
</td>
<td name="UserName" style="width: 20%" editor="jcpopup" notallowempty poptype="Url"
valstring='Title:姓名' returnmode="DataList" returnparam="" popparam="" popstyle=""
onpopafter="SetValue()" popurl="">
姓名
</td>
<td name="UserId" hidden>
</td>
<td name="Duty" editor="jcselect" datatype="Enum" enum="Page.Enum.Duty" width="30%"
valstring="Title:现任职务;DataType:String;">
现任职务
</td>
<td name="DutyAfter" editor="jcselect" datatype="Enum" enum="Page.Enum.Duty" width="30%"
valstring="Title:拟任职务;DataType:String;">
拟任职务
</td>
<td type="function" functype="Delete" style="width: 5%;">
删除
</td>
</tr>
</table>
</span>

2.jcgrid数据填充

DataStore ds = new DataStore();
Goodway.Data.DataList dl = new Goodway.Data.DataList(); DbRecord dbrec = new DbRecord(dbAccess, TBNAME, szId);
dfrm = dbrec.ToDataForm("RecData");
dl = DbTool.DataTableToDataList(dbAccess.QueryDataTable("select * from HrSelectionFileObject where Relateid='" + szId + "'")); dl.SetName("UserList");
ds.Add(dl);

3.每一列的用户选择

function OnAddAfter() {
var currentbut = $("#Table2>tbody:last .jcpopup_Button:last");
currentbut.unbind("click").removeAttr('onclick').click(GetUser);
} function GetUser() {
     var url = "/Framework.WebService/HttpHandlers/UserChooser2.aspx?SelectType=User";
var result = window.showModalDialog(url, window, "dialogWidth:800px;dialogHeight:600px;status:yes;resizable:no");
var ids;
var names;
if (result != null && result.length > 0) {
ids = result[0];
names = result[2];
while (ids.indexOf(";") != -1)
ids = ids.replace(";", ",");
while (names.indexOf(";") != -1)
names = names.replace(";", ",");
while (names.indexOf("(") != -1)
names = names.replace("(", "(");
while (names.indexOf(")") != -1)
names = names.replace(")", ")");
}
if (ids.indexOf(",") != -1) {
alert("该处被设置成单项选择!我们将自动截取到您所选择的第一个选择项!")
ids = ids.substring(0, ids.indexOf(","));
names = names.substring(0, names.indexOf(","));
}
     $(this).parent().prev().find("input").val(names);
$(this).parent().parent().parent().parent().parent().parent().next().find("input").val(ids);
}

4.点击保存,把数据保存到数据库

function DoSave(){
var df = Co.PageForm.GetDataForm("RecData"); var dl = Co.MyGrid.GetValue();
dl.SetName("MyGrid");
var rtn = Execute.Post("Update", df,dl);
if (rtn.HasError)
rtn.ShowError();
else {
alert("保存成功!");
window.ReturnValue = 12;
window.close();
}
}

后台:

private DataStore Update()
{
DataStore ds = new DataStore();
try
{
DataForm df = this.RequestDs.Forms("RecData");
DbRecord dr = new DbRecord(dbAccess, TBNAME, df.GetValue("Id"));
string FormId = df.GetValue("Id");
string objName = "";
//dr.SetData(df); string strSql = "delete from HrSelectionFileObject where RelateId='" + FormId + "'";
this.dbAccess.ExecSql(strSql); Goodway.Data.DataList dl = this.RequestDs.Lists("MyGrid");
for (int i = ; i < dl.GetItemCount(); i++)
{
DbRecord drsub = new DbRecord(dbAccess, "HrSelectionFileObject");
drsub["RelateId"] = FormId;
drsub["UserID"] = dl.GetItem(i).GetAttr("UserId");
drsub["UserName"] = dl.GetItem(i).GetAttr("UserName");
drsub["Duty"] = dl.GetItem(i).GetAttr("Duty");
drsub["DutyAfter"] = dl.GetItem(i).GetAttr("DutyAfter");
drsub["UserDate"] = DateTime.Now.ToString();
drsub.Update(Guid.NewGuid().ToString());
objName += drsub["UserName"];
} dr["ReviewObject"] = objName;
dr.Update(); ds.Add(DbTool.GetResultParam((int)DbResult.Successful, null, null));
}
catch (DbException dbe)
{
ds.Add(DbTool.GetResultParam((int)DbResult.SqlError, dbe.Message, null));
}
return ds;
}

5.HrSelectionFileObject表对应的表结构

jcgrid-LMLPHP

6. 例外一种填充数据方式:比如前端选择某个流程编号,取出数据后在前端填充

jcgrid清除数据

Co["MemberList"].Reset(new DataList());

整体填充

var dlUser = new DataList(di.GetAttr("MembersInfo"));
Co["MyGrid"].SetValue(dlUser);

也可以遍历填充

                for (var j = 0; j < dlUser.GetItemCount(); j++) {
var diuser = dlUser.GetItem(j); Co["MyGrid"].AddRow(
"UserID", diuser.GetAttr("UserID"),
"UserName", diuser.GetAttr("UserName"),
"Sex", diuser.GetAttr("Sex"),
"CardNo", diuser.GetAttr("CardNo"),
"PassportNumber", diuser.GetAttr("PassportNumber"),
"UserDeptID", diuser.GetAttr("UserDeptID"),
"UserDeptName", diuser.GetAttr("UserDeptName"),
"Duty", diuser.GetAttr("Duty"),
"LinkPhone", diuser.GetAttr("LinkPhone"),
"CellPhone", diuser.GetAttr("CellPhone"),
"YearCount", diuser.GetAttr("YearCount"),
"BehaviorSign", BehaviorSign,
"SecureSign", SecureSign,
"Remark", diuser.GetAttr("Remark")
);
document.getElementById("MyGrid_TR" + j + "_UserName").childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].value = diuser.GetAttr("UserName");
}

7.取jcgrid数据

Co.MyGrid.GetValue().ToString()
05-11 10:54