EasyUi 保存$("#tt").datagrid('getChanges', "inserted"); 获取数据为空?
$("#tt").datagrid({
url:"servlet/FitAction?method=searchProduct",
title:"配件信息列表",
toolbar:"#tb",
striped: true, //交替条纹
rownumbers : true, //显示行数
loadMsg: '正在拼命加载,请稍后...',
fitColumns : true,
singleSelect : false,
onDblClickRow:onClickRow,//双击启动编辑
pagination : true,
height : 400,
pageSize : 10, //默认显示几条数据
pageList : [ 5, 10, 15 ], //制定显示几条
onAfterEdit:function(rowIndex, rowData, changes){
var inserted = $('#tt').datagrid('getChanges','inserted');
var updated = $('#tt').datagrid('getChanges','updated');
},
columns:[[
{field:"id",title:"id",width:100,checkbox:true},
{field:"productNo",title:"编号",width:200},
{field:"packName",title:"包名",width:200,
formatter:function(value,rowData,rowIndex){
for(var i=0; i<aa.length; i++){
if(aa[i].productid==value){
return aa[i].proname;
}
}
return value;
},
editor:{
type:'combobox',
options:{
data:synchroAjaxByUrl("servlet/FitAction?method=queryResult&parentId=0"),
valueField:"productid",
textField:"proname",
required:true,
onSelect:function(data){
var row = $("#tt").datagrid("getSelected");
var rowIndex = $("#tt").datagrid("getRowIndex",row);//获取行号
var thisTarget = $("#tt").datagrid("getEditor", {"index":rowIndex,"field":"packName"}).target;
var value = thisTarget.combobox("getValue");
var target = $("#tt").datagrid("getEditor", {"index":rowIndex,"field":"cateName"}).target;
target.combobox("clear"); //清除原来的数据
var url = "servlet/FitAction?method=queryResult&parentId="+value;
target.combobox("reload", url);//联动下拉列表重载
},
onLoadSuccess:function(data,value){
// 如果data是数据的话,aa = data ;就可以啊
aa=$(this).combobox("getData");
}
}
}
},
{field:"cateName",title:"类别",width:200,
formatter:function(value,rowData,rowIndex){
for(var i=0; i<bb.length; i++){
if(bb[i].productid==value){
return bb[i].proname;
}
}
return value;
},
editor:{
type:'combobox',
options:{
data:synchroAjaxByUrl("servlet/FitAction?method=queryResult"),
valueField:"productid",
textField:"proname",
required:true,
onSelect:function(data){
var row = $("#tt").datagrid("getSelected");
var rowIndex = $("#tt").datagrid("getRowIndex",row);//获取行号
var thisTarget = $("#tt").datagrid("getEditor", {"index":rowIndex,"field":"cateName"}).target;
var value = thisTarget.combobox("getValue");
var target = $("#tt").datagrid("getEditor", {"index":rowIndex,"field":"productName"}).target;
target.combobox("clear"); //清除原来的数据
var url = "servlet/FitAction?method=queryResult&parentId="+value;
target.combobox("reload", url);//联动下拉列表重载
},
onLoadSuccess:function(data,value){
// 如果data是数据的话,aa = data ;就可以啊
bb=$(this).combobox("getData");
}
}
}
},
{field:"productName",title:"产品名称",width:200,
formatter:function(value,rowData,rowIndex){
for(var i=0; i<cc.length; i++){
if(cc[i].productid==value){
return cc[i].proname;
}
}
return value;
},
editor:{
type:'combobox',
options:{
data:synchroAjaxByUrl("servlet/FitAction?method=queryResult"),
valueField:"productid",
textField:"proname",
required:true,
onSelect:function(data){
var row = $("#tt").datagrid("getSelected");
var rowIndex = $("#tt").datagrid("getRowIndex",row);//获取行号
var thisTarget = $("#tt").datagrid("getEditor", {"index":rowIndex,"field":"productName"}).target;
var value = thisTarget.combobox("getValue");
var target = $("#tt").datagrid("getEditor", {"index":rowIndex,"field":"sizeName"}).target;
target.combobox("clear"); //清除原来的数据
var url = "servlet/FitAction?method=queryResult&parentId="+value;
target.combobox("reload", url);//联动下拉列表重载
},
onLoadSuccess:function(data,value){
// 如果data是数据的话,aa = data ;就可以啊
cc=$(this).combobox("getData");
}
}
}
},
{field:"sizeName",title:"规格",width:200,
formatter:function(value,rowData,rowIndex){
for(var i=0; i<dd.length; i++){
if(dd[i].productid==value){
return dd[i].proname;
}
}
return value;
},
editor:{
type:'combobox',
options:{
data:synchroAjaxByUrl("servlet/FitAction?method=queryResult"),
valueField:"productid",
textField:"proname",
required:true,
onLoadSuccess:function(data,value){
// 如果data是数据的话,aa = data ;就可以啊
dd=$(this).combobox("getData");
}
}
}
},
{field:"amount",title:"数量",width:200,
editor:{
type:"numberbox",
options: {
required:true,
min:1
}
}
},
{field:"remark",title:"备注",width:300,editor:"textbox"}
]]
});
//点击某一行
var editIndex = undefined;
function endEditing(){
if (editIndex == undefined){
return true;
}
if ($('#tt').datagrid('validateRow', editIndex)){
var ed = $('#tt').datagrid('getEditor', {index:editIndex,field:'packName'});
if(ed!=null){
var packName = $(ed.target).combobox('getText');
$('#tt').datagrid('getRows')[editIndex]['packName'] = packName;
}
$('#tt').datagrid('endEdit', editIndex);
editIndex = undefined;
return true;
} else {
return false;
}
}
function onClickRow(index){
if (editIndex != index){
if (endEditing()){
$('#tt').datagrid('selectRow', index)
.datagrid('beginEdit', index);
editIndex = index;
} else {
$('#tt').datagrid('selectRow', editIndex);
}
}
}
//添加一行
function append(){
if (endEditing()){
//1 先取消所有的选中状态
$('#tt').datagrid('unselectAll');
//2追加一行
$('#tt').datagrid('appendRow',{
remark:''
});
//3获取当前页的行号
editing = $('#tt').datagrid('getRows').length -1;
//4选中并开启编辑状态
$('#tt').datagrid('selectRow',editing);
$('#tt').datagrid('beginEdit', editing);
/* $('#tt').datagrid('appendRow',{status:'P'});
editIndex = $('#tt').datagrid('getRows').length-1;
$('#tt').datagrid('selectRow', editIndex)
.datagrid('beginEdit', editIndex); */
}
}
function removeit(){
if (editIndex == undefined){return}
$('#tt').datagrid('cancelEdit', editIndex)
.datagrid('deleteRow', editIndex);
editIndex = undefined;
}
//保存
function accept(){
if (endEditing()){
//$('#tt').datagrid('acceptChanges');
//利用easyui控件本身的getChange获取新添加和修改的内容
if($("#tt").datagrid('getChanges').length){
var inserted = $("#tt").datagrid('getChanges', "inserted");
var updated = $("#tt").datagrid('getChanges', "updated");
var effectRow = new Object();
if (inserted.length) {
effectRow["inserted"] = JSON.stringify(inserted);
}
if(updated.length){
effectRow["updated"] = JSON.stringify(updated);
}
}
/* $.post("servlet/FitAction?method=insertAndUpdateProduct", effectRow, function(rsp) {
if(rsp.status){
$.messager.alert("提示", "提交成功!");
$('#tt').datagrid('acceptChanges');
}
}, "JSON").error(function() {
$.messager.alert("提示", "提交错误!");
}); */
}
}
<a href="javascript:void(0)" id="addFun" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="append()">添加</a>
<a href="javascript:void(0)" id="saveFun" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="accept()">保存</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
到处都是坑
回复
还好,算是功能比较齐全的框架了
还有公司用easyui,震惊