**
返回文本框格式
**
function init_datagrid() {
dgSafeAQY = $("#datagrid").datagrid({
url: "/SafeKHPJ/CQTSDJManager",
//title: "通知列表",
// iconCls: "icon-save",
fit: true,
singleSelect: true,
pagination: true,
pagePosition: "bottom",
pageSize: 50,
pageList: [15, 20, 25, 30,50],
fitColumns: true,
checkOnSelect: false,
nowrap: false,
rownumbers: true, //行号
toolbar: toolbar.length == 0 ? null : toolbar,
idField: "Id",
sortName: "Id",
sortOrder: "asc",
selectOnCheck:true,
striped: true,
remoteSort: false,
columns: [[
{ field: 'Id', title: 'Id', width: 50, align: 'center',hidden:true },
{
field: 'BMMC', title: '部门名称', width: 50, align: 'center',sortable:"true",
sorter: function () {
return (a > b ? 1 : -1);
}
},
{
field: 'GZGW', title: '工作岗位', width: 50, align: 'center', sortable: "true",
sorter: function (a, b) {
return (a > b ? 1 : -1);
}
},
{
field: 'XM', title: '姓名', width: 50, align: 'center', sortable: "true",
sorter: function (a, b) {
return (a > b ? 1 : -1);
}
},
{
field: 'SJCQTS', title: '出勤天数', width:50, align: 'center',
formatter: function (value, rowData, rowIndex) {
if(value==null||value=="")
{
return "<input type='text' id='ids" + rowData.Id + "' style='border:#ff0000 1px solid' />";
}
return "<input type='text' id='ids" + rowData.Id + "' value='" + value + "' style='border:#ff0000 1px solid' />";
}
},
{
field: 'LRSJ', title: '录入时间', width: 50, align: 'center', sortable: "true",
sorter: function (a, b) {
return (a > b ? 1 : -1);
},hidden:true
}
]]
});
dgSafeAQY.datagrid('hideColumn', 'Id');
}
**
//把文本框输入的值保存到datagrid中
**
function changge()
{
var rows = $("#datagrid").datagrid("getRows");
for (var i in rows) {
var value = $("input[id='ids" + rows[i].Id + "']").val();
var index = $('#datagrid').datagrid('getRowIndex', rows[i]);
$('#datagrid').datagrid('updateRow', {
index: index,
row: {
SJCQTS: value
}
});
}
}
**
//把页面的数据保存到数据库
**
function SaveChanges()
{
var rowsData = $('#datagrid').datagrid('getRows');
var json = JSON.stringify(rowsData);
var json = [];
var loc;
$.each(rowsData, function (i) {
loc = {
"BMMC": rowsData[i].BMMC,
"GZGW": rowsData[i].GZGW,
"XM": rowsData[i].XM,
"SJCQTS": rowsData[i].SJCQTS,
};
json.push(loc);
});
json = JSON.stringify(json); //转换成json数据
***//注意dataType返回类型要和后台返回类型一致,要不然进不了success方法***
$.ajax({
url: "/SafeKHPJ/Savedays",
dataType: 'text',
type: "post",
data:
{
"datasource":json
},
success:function(data) {
alert(data);
if (data == "OK") {
$.messager.alert("提示", "保存成功!");
}
else {
$.messager.alert("提示", "保存失败!");
}
}
});
}
//后台代码
public string Savedays()
{
string data = "";
string Msg = "ON";
if(Request.Form["datasource"]!=null)
{
data = Request.Form["datasource"];
}
string Id = "1";
//将json数据转换为list集合
JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
List<T_CQTSDJ> List1 = new List<T_CQTSDJ>();
List1 = (List<T_CQTSDJ>)jsonSerializer.Deserialize(data, typeof(List<T_CQTSDJ>));
OperContext oc = OperContext.CurrentContext;
List<T_KHJDPZ> listsafezzgj = oc.BllSession.IT_KHJDPZBLL.GetListBy1(x => true).ToList();
var list = listsafezzgj[listsafezzgj.Count - 1];//返回最新第一条季度设置表里数据
string ND = list.ND.ToString();//获取设置里的年度
string JD = list.JD.ToString();//获取设置里的季度
//循环保存
for (int i=0;i<List1.Count;i++)
{
T_CQXXDJ aq = new T_CQXXDJ
{
Id = int.Parse(Id),
BMMC =List1[i].BMMC,
GZGW=List1[i].GZGW,
SJCQTS=List1[i].SJCQTS,
XM=List1[i].XM,
ND = ND,//年度
JD = JD//季度
};
int iret =Model_T_CQXXDJ.AddCQXXDJ(aq);
Msg = "OK";
}
return Msg;
}