js 动态创建表格
/*
从数据库获取表数据
*/
function getTableData(){debugger;
var data1 = [];
从数据库获取表数据
*/
function getTableData(){debugger;
var data1 = [];
var current_instance_id = businessObj.getCurrentInstanceId();
if (current_instance_id) {
var req = SOAP_GetSaleCardStore.XMLDocument.cloneNode(true);
var root_id = businessObj.getRootInstanceId(current_instance_id)
if (root_id) {
req.selectSingleNode(".//processinstanceid").text =root_id;
var reqs = businessObj.executeSoap(req);
if(reqs&&reqs.selectNodes(".//tuple").length>0){
var tuple = reqs.selectNodes(".//tuple");
$.each(tuple, function(i){
var nodes = tuple[i].selectNodes(".//old/BPM_SH_SALECARDSTORE")[0];
var node_array = [i+1,
nodes.selectSingleNode(".//CARD_KIND_NAME").text,
nodes.selectSingleNode(".//CARD_TYPE_NAME").text,
$("#main_pro_info_name").text(),
nodes.selectSingleNode(".//CARD_PRICE").text,
nodes.selectSingleNode(".//APPLY_NUM").text,
nodes.selectSingleNode(".//CARD_PRA_VALUE").text,
nodes.selectSingleNode(".//CARD_DISCOUNT").text,
nodes.selectSingleNode(".//TOTAL_PRICE").text,
nodes.selectSingleNode(".//ID").text,
nodes.selectSingleNode(".//CARD_KIND").text,
nodes.selectSingleNode(".//CARD_TYPE").text,];
data1[i] = node_array;
});
}
$.each(data1, function(i){
CreateTableRow("","","applycard",data1[i],false,"");
});
}
}
}
/*
创建表格
front_callback 创建表格行前回调函数
obj button 按钮对象 可以为空
name 表格name
data 加载数据 数组对象
edit 是否可修改 默认false
callback 创建表格行后回调函数
*/
function CreateTableRow(front_callback,obj,name,data,edit,callback){debugger;
if(data.length>0){
var tr_id = data[9];
if(front_callback){front_callback(data);}
var edit_flag = false;
if(edit){edit_flag = edit;}
try{
var _table_tbody = $("#"+name+" TBODY");
var otr = document.createElement("tr");
otr.id = tr_id;
otr.card_kind = data[10];
otr.card_type = data[11];
otr.selected = "false";
if(edit_flag){otr.onclick = function(){selectRow(this,obj,applycard_callback)}}
_table_tbody[0].appendChild(otr);
var handClone_td = $("#"+name+" tr:first td").clone(true);
$.each(handClone_td, function(i){
handClone_td[i].bgColor = "#FFFFFF";
handClone_td[i].innerText = data[i];
handClone_td[i].style.cursor = "hand";
handClone_td[i].contentFlag = "1";
otr.appendChild(handClone_td[i]);
});
Statistics();
if(callback){callback();}
}catch(e){}
}
}
/*
选中某行
obj 当前表格列对象
button 修改按钮的button对象
callback 回调函数
*/
function selectRow(obj,button,callback){debugger;
var _tr = obj.parentNode.childNodes;
if(_tr.length > 2){
for (var i = 1; i < _tr.length; i++){
var _td = _tr[i].childNodes;
_tr[i].selected = "false";
for (var j = 0; j < _td.length; j++) {
_td[j].bgColor = '#FFFFFF';
}
}
}
obj.selected = "true";
var td = $(obj).find("td");
$.each(td,function(o){
td[o].bgColor = "#FFFFCC";
});
button.value = "修改";
button.onclick = function(){modifyTableValue(obj,button,modifyRow_callback)};
if(callback){callback(td);}
}
//删除表格数据
function delTableData(){
_tr_del = $("#gmgnQueryData tr[selected]");
_tr_del.remove();
}
//某些回调函数和方法因每个人的需求不同,在此就省略了。。
if (current_instance_id) {
var req = SOAP_GetSaleCardStore.XMLDocument.cloneNode(true);
var root_id = businessObj.getRootInstanceId(current_instance_id)
if (root_id) {
req.selectSingleNode(".//processinstanceid").text =root_id;
var reqs = businessObj.executeSoap(req);
if(reqs&&reqs.selectNodes(".//tuple").length>0){
var tuple = reqs.selectNodes(".//tuple");
$.each(tuple, function(i){
var nodes = tuple[i].selectNodes(".//old/BPM_SH_SALECARDSTORE")[0];
var node_array = [i+1,
nodes.selectSingleNode(".//CARD_KIND_NAME").text,
nodes.selectSingleNode(".//CARD_TYPE_NAME").text,
$("#main_pro_info_name").text(),
nodes.selectSingleNode(".//CARD_PRICE").text,
nodes.selectSingleNode(".//APPLY_NUM").text,
nodes.selectSingleNode(".//CARD_PRA_VALUE").text,
nodes.selectSingleNode(".//CARD_DISCOUNT").text,
nodes.selectSingleNode(".//TOTAL_PRICE").text,
nodes.selectSingleNode(".//ID").text,
nodes.selectSingleNode(".//CARD_KIND").text,
nodes.selectSingleNode(".//CARD_TYPE").text,];
data1[i] = node_array;
});
}
$.each(data1, function(i){
CreateTableRow("","","applycard",data1[i],false,"");
});
}
}
}
/*
创建表格
front_callback 创建表格行前回调函数
obj button 按钮对象 可以为空
name 表格name
data 加载数据 数组对象
edit 是否可修改 默认false
callback 创建表格行后回调函数
*/
function CreateTableRow(front_callback,obj,name,data,edit,callback){debugger;
if(data.length>0){
var tr_id = data[9];
if(front_callback){front_callback(data);}
var edit_flag = false;
if(edit){edit_flag = edit;}
try{
var _table_tbody = $("#"+name+" TBODY");
var otr = document.createElement("tr");
otr.id = tr_id;
otr.card_kind = data[10];
otr.card_type = data[11];
otr.selected = "false";
if(edit_flag){otr.onclick = function(){selectRow(this,obj,applycard_callback)}}
_table_tbody[0].appendChild(otr);
var handClone_td = $("#"+name+" tr:first td").clone(true);
$.each(handClone_td, function(i){
handClone_td[i].bgColor = "#FFFFFF";
handClone_td[i].innerText = data[i];
handClone_td[i].style.cursor = "hand";
handClone_td[i].contentFlag = "1";
otr.appendChild(handClone_td[i]);
});
Statistics();
if(callback){callback();}
}catch(e){}
}
}
/*
选中某行
obj 当前表格列对象
button 修改按钮的button对象
callback 回调函数
*/
function selectRow(obj,button,callback){debugger;
var _tr = obj.parentNode.childNodes;
if(_tr.length > 2){
for (var i = 1; i < _tr.length; i++){
var _td = _tr[i].childNodes;
_tr[i].selected = "false";
for (var j = 0; j < _td.length; j++) {
_td[j].bgColor = '#FFFFFF';
}
}
}
obj.selected = "true";
var td = $(obj).find("td");
$.each(td,function(o){
td[o].bgColor = "#FFFFCC";
});
button.value = "修改";
button.onclick = function(){modifyTableValue(obj,button,modifyRow_callback)};
if(callback){callback(td);}
}
//删除表格数据
function delTableData(){
_tr_del = $("#gmgnQueryData tr[selected]");
_tr_del.remove();
}
//某些回调函数和方法因每个人的需求不同,在此就省略了。。
--------------------------------------------------------------------------
今天,明天就在此刻!此刻奋斗,今天耕耘,明天收获,明天辉煌!此刻放弃, 今天无为,明天饥饿,明天黯淡!
JimmyCai