{
field: 'ObtainCert', title: "是否获证", width: 50,
editor: { type: 'checkbox',
options: {
on: 1,
off: 0
}
}
},
//* singleSelect: false, false 是可以选择多行 true 只可以选择一行
{ field: 'TrainResultId', title: '培训结果', width: 100, align: 'center',
formatter: function (value, row) {
return row.NameCN;
},
editor: {
type: 'combobox',
options: {
valueField: 'Id',
textField: 'NameCN',
url: '<%: Url.Content("~/SysModule/Common/GetAssessStatusList") %>',
required: true
}
}
} ,
// 一下是判断是否双击才可以编辑
onBeforeLoad: function () {
$(this).datagrid('rejectChanges');
},
onLoadSuccess: function (data) {
beginEdit();
},
onClickRow: function (rowIndex) {
editingIndex = rowIndex;
if (lastIndex != rowIndex) {
if ($(this).datagrid('validateRow', lastIndex)) {
$(this).datagrid('endEdit', lastIndex);
$(this).datagrid('beginEdit', rowIndex);
lastIndex = rowIndex;
} else {
$(this).datagrid('selectRow', lastIndex);
editingIndex = lastIndex;
}
}
},
onAfterEdit: function (rowIndex, rowData, chanages) {
}
});
});
function endEdit() {
var $dg = $("#grid");
var rows = $dg.datagrid('getRows');
for (var i = 0; i < rows.length; i++) {
$dg.datagrid('endEdit', i);
}
}
function beginEdit() {
var $dg = $("#grid");
var rows = $dg.datagrid('getRows');
for (var i = 0; i < rows.length; i++) {
$dg.datagrid('beginEdit', i);
}
}
{
text: '提交',
iconCls: 'icon-save',
handler: function () {
endEdit();
if ($dg.datagrid('getChanges').length) {
var inserted = $dg.datagrid('getChanges', "inserted");
var deleted = $dg.datagrid('getChanges', "deleted");
var updated = $dg.datagrid('getChanges', "updated");
var effectRow = new Object();
if (inserted.length) {
effectRow["inserted"] = JSON.stringify(inserted);
}
if (deleted.length) {
effectRow["deleted"] = JSON.stringify(deleted);
}
if (updated.length) {
effectRow["updated"] = JSON.stringify(updated);
}
}
var url = '<%:Url.Content("~/CertModule/SailorTrainC/Save") %>';
$.post(url, effectRow, function (rsp) {
//if (rsp.status) {
$.messager.alert("提示", "提交成功!");
$dg.datagrid('acceptChanges');
beginEdit();
//}
}, "JSON").error(function () {
$.messager.alert("提示", "提交错误!");
beginEdit();
});
}
},
//提交代码
public class SailorTrainCEdit
{
public string Id { get; set; }
public int SailorTrainId { get; set; }
public int SailorInfoId { get; set; }
public int? TrainResultId { get; set; }
public bool ObtainCert { get; set; }
public int? PayMethodsId { get; set; }
}
public ActionResult Save()
{
var client = new CertModuleServiceReference.CertModuleServiceClient();
//获取编辑数据 这里获取到的是json字符串
string deleted = Request.Form["deleted"];
string inserted = Request.Form["inserted"];
string updated = Request.Form["updated"];
if (deleted != null)
{
//把json字符串转换成对象
List<SailorTrainCEdit> listDeleted = deleted.JsonDeserialize<List<SailorTrainCEdit>>();
foreach (var item in listDeleted)
{
if (item == null)
{
continue;
}
if (item.Id != null && item.Id != "")
{
client.DeleteSailorTrainC(DataConverter.CInt(item.Id).Value);
}
}
}
if (inserted != null)
{
//把json字符串转换成对象
List<SailorTrainCEdit> listInserted = inserted.JsonDeserialize<List<SailorTrainCEdit>>();
foreach (var item in listInserted)
{
var sailorTrainC = new SailorTrainCListDTO();
sailorTrainC.SailorTrainId = item.SailorTrainId;
sailorTrainC.SailorInfoId = item.SailorInfoId;
sailorTrainC.ObtainCert = item.ObtainCert;
sailorTrainC.PayMethodsId = item.PayMethodsId;
sailorTrainC.TrainResultId = item.TrainResultId;
client.AddSailorTrainC(sailorTrainC);
}
}
if (updated != null)
{
//把json字符串转换成对象
List<SailorTrainCEdit> listUpdated = updated.JsonDeserialize<List<SailorTrainCEdit>>();
foreach (var item in listUpdated)
{
var sailorTrainC = client.GetSailorTrainC(DataConverter.CInt(item.Id).Value);
sailorTrainC.SailorTrainId = item.SailorTrainId;
sailorTrainC.SailorInfoId = item.SailorInfoId;
sailorTrainC.ObtainCert = item.ObtainCert;
sailorTrainC.PayMethodsId = item.PayMethodsId;
sailorTrainC.TrainResultId = item.TrainResultId;
client.UpdateSailorTrainC(sailorTrainC);
}
}
return Json(new { IsSuccess = true, Message = "保存成功" }, "text/html", JsonRequestBehavior.AllowGet);
}
//后台代码
小弟新手 如有错误 请指点出来 留下您宝贵意见!