123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- /**
- * 创建表格
- * @param contid
- * @param gridData
- * @param columsData
- * @param callback
- */
- function createIndexTable(contid,gridData,columsData,callback){
- var $dom = $("#"+contid);
- var $gridMainCont = $('<div class="gridmaincont"></div>');
- $dom.append($gridMainCont);
- var $gridCont = $('<div class="gridCont"></div>');
- $gridMainCont.append($gridCont);
- var tablehtml = '<div class="tablediv"><table class="tablecont" cellspacing="0" >';
- tablehtml += '<tr class="tablehead">';
- for(var i=0;i<columsData.length;i++){
- tablehtml += '<th width="'+columsData[i].width+'"><span>'+columsData[i].display+'</span></th>';
- }
- tablehtml += '</tr>';
- if(gridData.length!=0){
- for(var j=0;j<gridData.length;j++){
- var rowData = gridData[j];
- var idx = gridData.length-j;
- tablehtml += '<tr id="row_'+idx+'" class="tablerow">';
- for(var k=0;k<columsData.length;k++){
- var culum = columsData[k].name;
- var renderFun = columsData[k].render;
- var editordata = columsData[k].editor;
- var value = rowData[culum]==undefined ?"":rowData[culum];;
- if(renderFun&&renderFun!=""){
- var strhtml = renderFun(idx,rowData,culum,columsData);
- tablehtml += '<td id="td_'+culum+'_'+idx+'" >'+strhtml+'</td>';
- }else{
- if(editordata && editordata.type == "select"){
- var editData = editordata.data.list;
- value = getKeyFromValue(editData,value);
- }
- tablehtml += '<td id="td_'+culum+'_'+idx+'" ><span title="'+value+'">'+value+'</span></td>';
- }
- }
- tablehtml += '</tr>';
- }
- }
- tablehtml += '<tr id="row_end" ><td height="100px" colspan="'+columsData.length+'"></td></tr>';
- tablehtml += '</table></div>';
- $gridCont.append(tablehtml);
-
- if(gridData.length!=0){
- for(var j=0;j<gridData.length;j++){
- var rowData = gridData[j];
- var idx = gridData.length-j;
- $("#row_"+idx).data("idx",idx).data("rowData",rowData).data("columsData",columsData);
- }
- }
-
- $(".tablerow").bind("dblclick", function() { //双击事件
- if(!($(this).hasClass("dbclickflag"))){
- var idx = parseInt($(this).data("idx"));
- var rowData = $(this).data("rowData");
- var colData = $(this).data("columsData");
- callback(idx,rowData,colData);
- }
- });
-
- $gridMainCont = null;
- $gridCont = null;
- };
- /**
- * 将编辑表单行保存成普通表格行
- * @param idx
- * @param rowData
- * @param columsData
- */
- function rowInputToSpan(idx,rowData,columsData){
- var $trdom = $("#row_"+idx);
- $trdom.removeClass("dbclickflag");
- for(var k=0;k<columsData.length;k++){
- var culum = columsData[k].name;
- var renderFun = columsData[k].render;
- var editordata = columsData[k].editor;
- var value = rowData[culum]==undefined ?"":rowData[culum];
- var $tddom = $('#td_'+culum+'_'+idx);
- $tddom.html("");
- if(renderFun&&renderFun!=""){
- var strhtml = renderFun(idx,rowData,culum,columsData);
- $tddom.append(strhtml);
- }else{
- if(editordata && editordata.type == "select"){
- var editData = editordata.data.list;
- value = getKeyFromValue(editData,value);
- }
- var html = '<span title="'+value+'" >'+value+'</span>';
- $tddom.append(html);
- }
- }
- $trdom.data("rowData",rowData);
- }
- /***
- * 将普通表格行转变成编辑表单行
- * @param idx
- * @param rowData
- * @param columsData
- */
- function rowSpanToInput(idx,rowData,columsData){
- var $trdom = $("#row_"+idx);
- $trdom.addClass("dbclickflag");
- for(var k=0;k<columsData.length;k++){
- var culum = columsData[k].name;
- var renderFun = columsData[k].render;
- var editordata = columsData[k].editor;
- var value = rowData[culum]==undefined ?"":rowData[culum];
- var $tddom = $('#td_'+culum+'_'+idx);
- $tddom.html("");
- if(editordata&&editordata!=""){
- if(renderFun&&renderFun!=""){
- var strhtml = renderFun(idx,rowData,culum,columsData);
- var html = strhtml;
- $tddom.append(html);
- }else{
- var $input = null;
- if(editordata.type=="text"){
- $input = $('<input id="'+culum+idx+'" name="'+culum+'" style="width: 99%;height:44px;line-height:44px;text-align:center;" type="'+editordata.type+'" value="'+value+'" />');
- $tddom.append($input);
- }
- if(editordata.type=="textarea"){
- $input = $('<textarea id="'+culum+idx+'" name="'+culum+'" style="width:99%;height:44px;rows="2">'+value+'</textarea>');
- //$input = $('<input id="'+culum+idx+'" name="'+culum+'" style="width: 99%;height:32px;line-height:32px;" type="'+editordata.type+'" value="'+value+'" />');
- $tddom.append($input);
- }
- if(editordata.type=="select"){
- //$input = $('<input style="width: 99%;" type="'+editordata.type+'" data="'+editordata.data+'" />');
- $input = $('<select id="'+culum+idx+'" name="'+culum+'" editable=false prompt="请选择" selWidth="'+editordata.selWidth+'" ></select>');
- $tddom.append($input);
- $input.data("data",editordata.data);
- $input.render();
- $input.setValue(value);
- }
- $input.render();
- }
- }else{
- if(renderFun&&renderFun!=""){
- var strhtml = renderFun(idx,rowData,culum);
- var html = strhtml;
- $tddom.append(html);
- }
- }
- }
- }
- /**
- * 添加新可编辑表单行
- * @param idx
- * @param rowData
- * @param columsData
- * @param callback
- */
- function addNewRows (idx,rowData,columsData,callback){
- var $dom = $(".tablerow").eq(0);
- //console.log($dom);
- if($dom.length==0){
- $dom = $("#row_end");
- }
- idx = idx + 1;
- var tablehtml = '<tr id="row_'+idx+'" class="tablerow">';
- for(var k=0;k<columsData.length;k++){
- var culum = columsData[k].name;
- var value = rowData[culum]==undefined ?"":rowData[culum];
- tablehtml += '<td id="td_'+culum+'_'+idx+'" ><span title="'+value+'">'+value+'</span></td>';
- }
- tablehtml += '</tr>';
- $dom.before(tablehtml);
- $("#row_"+idx).data("idx",idx).data("rowData",rowData).data("columsData",columsData);
- rowSpanToInput(idx,rowData,columsData);
- $("#row_"+idx).bind("dblclick", function() { //双击事件
- if(!($(this).hasClass("dbclickflag"))){
- var idx = parseInt($(this).data("idx"));
- var rowData = $(this).data("rowData");
- var colData = $(this).data("columsData");
- callback(idx,rowData,colData);
- }
- });
-
-
- }
- /**
- * 下拉框数据,通过value取key值
- * @param editData
- * @param value
- * @returns
- */
- function getKeyFromValue(editData,value){
- for(var l=0;l<editData.length;l++){
- if(editData[l].value == value){
- value = editData[l].key;
- }
- }
- return value;
- }
- /***
- * 将json转变成Array数组,并去掉value为空的数据
- * @param json
- * @returns {Array}
- */
- function jsonToArray(json){
- var result = [];
- $.each(json, function(key, value) {
- if(value != ""){
- result.push(value);
- }
- });
- return result;
- }
|