存储表常用方法积累
1、修改创建存储表时的列信息
dom.bind( "OnDataSetEvent", function (e,para){
if (para.IDataSetEvent.mType==="DSEVENT_OPEN" ){
var arrayModel = para.IDataSetEvent.mExtParams.newColModel.slice();
var arrayName = para.IDataSetEvent.mExtParams.newColModel.slice();
var i = 0;
var j = 0;
$.each(arrayModel, function (k,v){
if (v.name=="F_SCHEMA_FMC" ){
i = k;
}
if (v.name=="F_SCHEMA" ){
v.width = "80" ;
j = k;
}
});
para.IDataSetEvent.mExtParams.newColModel[i] = arrayModel[j];
para.IDataSetEvent.mExtParams.newColModel[j] = arrayModel[i];
para.IDataSetEvent.mExtParams.newColNames[i] = arrayName[j];
para.IDataSetEvent.mExtParams.newColNames[j] = arrayName[i];
}
});
2、加载完成事件
dom.jqGrid("hideCol",["F_PKEY"]);
dom.bind("panGrid_loadCompleteTrigger",function(){
dom.setLabel("F_SCHEMA_FMC","方案名称");
dom.setLabel("F_SCHEMA","方案编号");
dom.jqGrid("showCol",["F_SCHEMA"]);
});
3、新增行
dom.panJqStore("addNewRow",{"newData":{"F_SCHEMA":ysbh}});
doms.find("table[storeid='YL_GCQRD_MX']").panJqStore("addNewRow",{"newData":{}}); //子凭据新增一行
4、删除行
dom.panJqStore("deleteRow");
5、保存
dom.panJqStore("submit");
6、刷新
dom.panJqStore("initpaging");
dom.panJqStore("reLoadData");
7、设置行的某一列数据
cdoms.panJqStore("setRowData", { rowid : rowid,rowData : obj});
8、隐藏列
dom.setGridParam().hideCol(col).trigger("reloadGrid"); //jqgrid原生
dom.jqGrid("hideCol",col);//panJqStore封装 col为数组
9、设置列不可编辑
$("#grid9").jqGrid("removeColEditable",[数组]);//设置列不可编辑
10、设置列可编辑
cdoms.jqGrid("setColEditable",cols);
10、获取某一列数据
$("#grid9").jqGrid('getCol','列名',false);
11、监听input事件 获取选中行数据
//监听input事件
function listenpz(gridid) {
var doms = $("#" + gridid);
doms.bind("input", function(e, para) {
var rowid=para.rowid;
var rowdata = doms.jqGrid("getRowData", rowid);
});
}
12、输入框模糊搜索
function sprinputselect() {
$("#spr").panTextInputSelect({
changed: function(v, cb) {
if (v !== "") {
var senddata1 = {
"service": "BIZDctService",
"method": "queryDCTPageRowEx",
"DCT_ID": "SSF_USERS", //字典表
"DCT_PARENT_ID": "#ROOT",
"DCT_PARENT_LEVEL": "0",
"SHOW_ALL_CHILDREN": "1",
//名称和id
"SQL_FILTER_WHERE": "ZD.USR_USRID like '" + v + "%' or ZD.USR_CAPTION like '%" + v + "%'"
};
var xx = $.ajax({
url: "commAction.do",
data: {
jsondata: $.toJSON(senddata1)
},
type: "POST",
dataType: "json",
async: true,
success: function(data) {
var array = [];
$.each(data.DCT_ROWSET.ROWS, function(k, v) {
var obj = {};
obj.icon = "TIS-test-icon";
obj.bh = v.USR_USRID;
obj.mc = v.USR_CAPTION + "(" + v.USR_USRID + ")";
obj.hpid = v.USR_USRID;
array.push(obj);
});
cb(array);
}
});
return xx;
} else {
var array = [];
cb(array);
$("#spr").data("userInfo", {
"userid": "",
"usermc": ""
});
return null;
}
},
selected: function(data) { //点击事件
$("#spr").data("userInfo", {
"userid": data.bh,
"usermc": data.mc
});
searchs();
return data.mc;
},
"width": 160,
"max_height": 158
});
}
查询:
var sprid = "";
var spr = $("#spr");
if (spr.val() != "") {
sprid = spr.data("userInfo").userid;
stoobj.F_SPR = "%%" + sprid;
}
13、设置多选框不可编辑(用jqgrid原生)
dom.jqGrid("removeColEditable","F_TRS_OK");
14、存储表公司选择明细级
Swing sto 公司字段 ShowFormat ACT:0012
15、进度条,参考资产卡片同步
<div class="pbarDiv" style="display:none">
<!-- 进度条开始 -->
<div id="progress_bar" class="ui-progress-bar">
<div class="ui-progress"></div>
<div class="ui-label">
<span class="value">同步中...</span>
</div>
</div>
<!-- 进度条结束 -->
</div>
默认隐藏 执行方法是设为显示 执行后隐藏
16、获取grid改变过的数据
dom.panGrid("creatFormatData");
var rowdatas = dom.panGrid("getChangedData");
根据rowdata 里的RS值的第一个数字可以判断该行数据是新增 删除 修改 状态
新增是“1” 修改是“0”
17、jqgrid判断两行直接是否有重复数据(科目与物料对照)
var colVal = dom.jqGrid('getRowData');
dom.jqGrid("removeEditState"); //移除单元格的编辑状态
if (colVal.length > 0) {
var n = {};
n[colVal[0]["F_KMBH"] + "_" + colVal[0]["F_FKWL"]] = true; //hash表赋默认值,如:{"0001":true}
var repeat = "0";
for (var i = 1; i < colVal.length; i++) {
if (n[colVal[i]["F_KMBH"] + "_" + colVal[i]["F_FKWL"]]) { //如果hash表中没有当前项
repeat = "1";
break; //跳出for循环
} else {
n[colVal[i]["F_KMBH"] + "_" + colVal[i]["F_FKWL"]] = true;
}
}
if (repeat == "1") {
tipAlert("消息提示", "同一个物料编号不能有重复科目!", "确认", 0);
return false;
}
$("#grid9").panJqStore("submit");;
}
18、设置某一行选中状态
$('#timeGrid tr').eq(3).find('td').eq(1).click();
19、导出excel
function dcexcel(){
var excelname = "";
var djlxid = djlxselect.panSelect("getValue");//单据类型
if(djlxid=="0089"){
name="其他入库单"
}
if(djlxid=="0090"){
name="其他出库单"
}
var coVal = $("#grid9").jqGrid('getCol','F_SSDW_FMC',false);
if(coVal.length){
excelname = "信息补录(单位:"+coVal[0]+"、单据类型:"+name+")";
}else{
excelname = "信息补录(单据类型:"+name+")";
}
var para = {"pdivid":"contgrid","tableid":"grid9","excelname":excelname};
var pdivid = para.pdivid;//包含grid的div id
var tableid = para.tableid;//创建tablegrid的id
var excelname = para.excelname;//要导出的excel的名称
var allobj = {};
var headobj = {};
var tablehead = $("#"+pdivid).find("table").eq(0);
var trarrayh = [];
var tdobjh = {};
tdobjh.rowspan = "1";
tdobjh.colspan = $("#"+tableid).find("tr").eq(0).find("td:visible").length;
tdobjh.value = excelname;
tdobjh.align = "2";
tdobjh.type = "1";
tdobjh.format = "";
tdobjh.fontsize = "15";
tdobjh.fontname = "微软雅黑";
trarrayh.push(tdobjh);
headobj["tr"] = trarrayh;
$.each(tablehead.find("tr"),function(k,v){
var trarray = [];
var index = 0;
if(tablehead.find("tr").length===1){
index = -1;
}
if(k!==index){
$.each($(v).find("th"),function(a,b){
if($(b).is(":visible")){
var tdobj = {};
tdobj.rowspan = $(b).attr("rowspan")||"1";
tdobj.colspan = $(b).attr("colspan")||"1";
if($(b).find("div").length>0){
tdobj.value = $(b).find("div").text();
}else{
tdobj.value = $(b).text();
}
tdobj.align = "2";
tdobj.type = "1";
tdobj.format = "";
trarray.push(tdobj);
}
});
headobj["tr"+k] = trarray;
}
});
var rowsobj = {};
var tablerows = $("#"+tableid);
$.each(tablerows.find("tr"),function(k,v){
var trarrayrows = [];
if(k!==0){
$.each($(v).find("td"),function(a,b){
if($(b).is(":visible")){
var tdobj = {};
tdobj.rowspan = "1";
tdobj.colspan = "1";
if($(b).find("input").length>0){
tdobj.value = $(b).find("input").val();
}else{
tdobj.value = $("#"+tableid).jqGrid("getCell",$(v).attr("id"),a);
}
var newcolmodel = $("#"+tableid).jqGrid("getGridParam","colModel");
var zd = $(b).attr("aria-describedby").replace(tableid+"_","");
$.each(newcolmodel,function(c,d){
if(d.name===zd){
var formatter = d.formatter||"";
var format = "";
var type = "1";//字符型
if(formatter==="number"){
format = "###,##0.00"||"";
if(tdobj.value===""){
tdobj.value = "0";
}
if(parseFloat(tdobj.value)===0){
if(format!==""){
format = "0.00";
}
}
type = "0";
}
tdobj.type = type;
tdobj.format = format;
return false;
}
});
//tdobj.value = $(b).text();
var talign = $(b).css("text-align");
if(talign==="left"){
tdobj.align = "1";
}
if(talign==="center"){
tdobj.align = "2";
}
if(talign==="right"){
tdobj.align = "3";
}
trarrayrows.push(tdobj);
}
});
rowsobj["tr"+k] = trarrayrows;
}
});
allobj.head = headobj;
allobj.body = rowsobj;
var excelobj = {};
excelobj[excelname] = allobj;
var exportexcel = {};
exportexcel.F_KEY = excelobj;
exportexcel.F_VALUE = excelname+".xlsx";
var formhtml = "<form id='expexcel' name='excels' action='"+sys_ctx+"/exportExcel.do' method='POST'>"
+"<input id='exportex' name='exportex' type='hidden'>"
+"</form>";
$("body").append(formhtml);
$("#exportex").val($.toJSON(exportexcel));
var form1 = window.document.getElementById("expexcel");//获取form1对象
form1.submit();
}