/** * MC版本:v3.1.0 * * 异步表格对象 * by:cqe; * date:2020-05-20 * ***/ var tableList = [];//当前已有的MCTable集合 function getMCTable(formId){ for(var i=0;i0){ table = $('#left-datagrid-btable-ajax'+formId); }else{ table = $('#datagrid-btable-ajax'+formId); } if(table.length>0){ table.find('input[type="checkbox"]').each(function(i,v){ if($(this).prop('checked')){ if(i0){ $('#datagrid-btable-ajax'+formId).find('tr').each(function(i,v){ if($(this).is(":visible")){ num++; } }) } return num; } /** * MC版本:v3.1.0 * * 获取渲染后的表头行tr的类名 * 返回值:类名数组 ***/ this.getTitleTrClass = function(){ var opt = { tType:'thead', elType:'tr', attrType:'cssClass', rowIndex:0 }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头行tr的样式 * 返回值:样式字符串 ***/ this.getTitleTrStyle = function(){ var opt = { tType:'thead', elType:'tr', attrType:'style', rowIndex:0 }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头行tr的html内容 * 返回值:html字符串 ***/ this.getTitleTrHtml = function(){ var opt = { tType:'thead', elType:'tr', attrType:'html', rowIndex:0 }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头行tr的自定义属性值 * 参数attrName:自定义属性名称 * 返回值:自定义属性值 ***/ this.getTitleTrAttr = function(attrName){ var opt = { tType:'thead', elType:'tr', attrType:'attr', rowIndex:0, attrKey:attrName }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头单元格td的类名 * 参数fieldNo:字段 * 返回值:类名数组 ***/ this.getTitleTdClass = function(fieldNo){ var opt = { tType:'thead', elType:'td', attrType:'cssClass', fieldNo:fieldNo, rowIndex:0 }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头单元格td的样式 * 参数fieldNo:字段 * 返回值:样式字符串 ***/ this.getTitleTdStyle = function(fieldNo){ var opt = { tType:'thead', elType:'td', attrType:'style', fieldNo:fieldNo, rowIndex:0 }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头单元格td的html内容 * 参数fieldNo:字段 * 返回值:html字符串 ***/ this.getTitleTdHtml = function(fieldNo){ var opt = { tType:'thead', elType:'td', attrType:'html', fieldNo:fieldNo, rowIndex:0 }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头单元格td的自定义属性值 * 参数fieldNo:字段 * 参数attrName:自定义属性名称 * 返回值:自定义属性值 ***/ this.getTitleTdAttr = function(fieldNo,attrName){ var opt = { tType:'thead', elType:'td', attrType:'attr', fieldNo:fieldNo, rowIndex:0, attrKey:attrName }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头单元格内容ui的类名 * 参数fieldNo:字段 * 返回值:类名数组 ***/ this.getTitleUiClass = function(fieldNo){ var opt = { tType:'thead', elType:'ui', attrType:'cssClass', fieldNo:fieldNo, rowIndex:0 }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头单元格内容ui的样式 * 参数fieldNo:字段 * 返回值:样式字符串 ***/ this.getTitleUiStyle = function(fieldNo){ var opt = { tType:'thead', elType:'ui', attrType:'style', fieldNo:fieldNo, rowIndex:0 }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头单元格内容ui的html内容 * 参数fieldNo:字段 * 返回值:html字符串 ***/ this.getTitleUiHtml = function(fieldNo){ var opt = { tType:'thead', elType:'ui', attrType:'html', fieldNo:fieldNo, rowIndex:0 }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表头单元格内容ui的自定义属性值 * 参数fieldNo:字段 * 参数attrName:自定义属性名称 * 返回值:自定义属性值 ***/ this.getTitleUiAttr = function(fieldNo,attrName){ var opt = { tType:'thead', elType:'ui', attrType:'attr', fieldNo:fieldNo, rowIndex:0, attrKey:attrName }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体行tr的类名 * 参数index:行索引 * 返回值:类名数组 ***/ this.getBodyTrClass = function(index){ var opt = { tType:'tbody', elType:'tr', attrType:'cssClass', rowIndex:index }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体行tr的样式 * 参数index:行索引 * 返回值:样式字符串 ***/ this.getBodyTrStyle = function(index){ var opt = { tType:'tbody', elType:'tr', attrType:'style', rowIndex:index }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体行tr的html内容 * 参数index:行索引 * 返回值:html字符串 ***/ this.getBodyTrHtml = function(index){ var opt = { tType:'tbody', elType:'tr', attrType:'html', rowIndex:index }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体行tr的自定义属性值 * 参数index:行索引 * 参数attrName:自定义属性名称 * 返回值:自定义属性值 ***/ this.getBodyTrAttr = function(index,attrName){ var opt = { tType:'tbody', elType:'tr', attrType:'attr', rowIndex:index, attrKey:attrName }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体单元格td的类名 * 参数index:行索引 * 参数fieldNo:字段 * 返回值:类名数组 ***/ this.getBodyTdClass = function(index,fieldNo){ var opt = { tType:'tbody', elType:'td', attrType:'cssClass', fieldNo:fieldNo, rowIndex:index }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体单元格td的样式 * 参数index:行索引 * 参数fieldNo:字段 * 返回值:样式字符串 ***/ this.getBodyTdStyle = function(index,fieldNo){ var opt = { tType:'tbody', elType:'td', attrType:'style', fieldNo:fieldNo, rowIndex:index }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体单元格td的html内容 * 参数index:行索引 * 参数fieldNo:字段 * 返回值:html字符串 ***/ this.getBodyTdHtml = function(index,fieldNo){ var opt = { tType:'tbody', elType:'td', attrType:'html', fieldNo:fieldNo, rowIndex:index }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体单元格td的自定义属性值 * 参数index:行索引 * 参数fieldNo:字段 * 参数attrName:自定义属性名称 * 返回值:自定义属性值 ***/ this.getBodyTdAttr = function(index,fieldNo,attrName){ var opt = { tType:'tbody', elType:'td', attrType:'attr', fieldNo:fieldNo, rowIndex:index, attrKey:attrName }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体单元格内容ui的类名 * 参数index:行索引 * 参数fieldNo:字段 * 返回值:类名数组 ***/ this.getBodyUiClass = function(index,fieldNo){ var opt = { tType:'tbody', elType:'ui', attrType:'cssClass', fieldNo:fieldNo, rowIndex:index }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体单元格内容ui的样式 * 参数index:行索引 * 参数fieldNo:字段 * 返回值:样式字符串 ***/ this.getBodyUiStyle = function(index,fieldNo){ var opt = { tType:'tbody', elType:'ui', attrType:'style', fieldNo:fieldNo, rowIndex:index }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体单元格内容ui的html内容 * 参数index:行索引 * 参数fieldNo:字段 * 返回值:html字符串 ***/ this.getBodyUiHtml = function(index,fieldNo){ var opt = { tType:'tbody', elType:'ui', attrType:'html', fieldNo:fieldNo, rowIndex:index }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的表体单元格内容ui的自定义属性值 * 参数index:行索引 * 参数fieldNo:字段 * 参数attrName:自定义属性名称 * 返回值:自定义属性值 ***/ this.getBodyUiAttr = function(index,fieldNo,attrName){ var opt = { tType:'tbody', elType:'ui', attrType:'attr', fieldNo:fieldNo, rowIndex:index, attrKey:attrName }; return this.getAttr(opt); } /** * MC版本:v3.1.0 * * 获取渲染后的字符串 * 参数tType:表格类型 thead-表头,tbody-表体 * 参数elType:元素类型 tr-行,td-单元格,ui-单元格内容 * 参数attrType:属性类型 cssClass-类名,style-样式,html-html内容,attr-自定义属性 * 参数fieldNo:字段 * 参数rowIndex:行数据索引 * 参数attrKey:自定义属性名称 ***/ this.getAttr = function(opt){ var tType = opt['tType'], elType = opt['elType'], attrType = opt['attrType'], fieldNo = opt['fieldNo'], rowIndex = opt['rowIndex']?opt['rowIndex']:0, attrKey = opt['attrKey']; if(isEmpty(tType) || isEmpty(elType) || isEmpty(attrType)){ return false; } if(tType == 'tbody' && isEmpty(rowIndex)){ return false; } if(attrType == 'attr' && isEmpty(attrKey)){ return false; } if((elType == 'td' || elType == 'ui') && isEmpty(fieldNo)){ return false; } var isLeftFixed = false; if($("#left-datagrid-htable"+formId).length>0){ isLeftFixed = true; } var lTable = null; if(isLeftFixed){ if(tType=='thead'){ lTable = $("#left-datagrid-htable"+formId); }else if(tType=='tbody'){ lTable = $("#left-datagrid-btable-ajax"+formId); } } var table = $("#datagrid-htable"+formId); if(tType=='thead'){ table = $("#datagrid-htable"+formId); }else if(tType=='tbody'){ table = $("#datagrid-btable-ajax"+formId); } if(elType=='tr'){ if(isLeftFixed && lTable){ var lTrDom = lTable.find('tr'); var trDom = table.find('tr'); if(lTrDom.length==0 || trDom.length==0 || trDom.length <= rowIndex){ return ''; } if(attrType == 'html'){ return {left:$(lTrDom[rowIndex]).html(),right:$(trDom[rowIndex]).html()}; }else if(attrType == 'attr'){ return $(trDom[rowIndex]).attr(attrKey); }else if(attrType == 'cssClass'){ return trDom[rowIndex].classList; } return $(trDom[rowIndex]).attr(attrType); } var trDom = table.find('tr'); if(trDom.length==0 || trDom.length <= rowIndex){ return ''; } if(attrType == 'cssClass'){ return trDom[rowIndex].classList; }else if(attrType == 'attr'){ return $(trDom[rowIndex]).attr(attrKey); }else if(attrType == 'html'){ return $(trDom[rowIndex]).html(); } return $(trDom[rowIndex]).attr(attrType); }else if(elType == 'td'){ var trDom = table.find('tr'); if(trDom.length==0 || trDom.length <= rowIndex){ return ''; } var tdDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]'); if(isLeftFixed && lTable && tdDom.length==0){ trDom = lTable.find('tr'); tdDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]'); } if(tdDom.length==0){ return ''; } if(attrType == 'cssClass'){ return tdDom[0].classList; }else if(attrType == 'attr'){ return $(tdDom).attr(attrKey); }else if(attrType == 'html'){ return $(tdDom).html(); } return $(tdDom).attr(attrType); }else if(elType == 'ui'){ var trDom = table.find('tr'); if(trDom.length==0 || trDom.length <= rowIndex){ return ''; } var uiDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]>span'); if(isLeftFixed && lTable && uiDom.length==0){ trDom = lTable.find('tr'); uiDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]>span'); } if(uiDom.length==0){ return ''; } if(attrType == 'cssClass'){ return uiDom[0].classList; }else if(attrType == 'attr'){ return $(uiDom).attr(attrKey); }else if(attrType == 'html'){ return $(uiDom).html(); } return $(uiDom).attr(attrType); } return ''; } /** * MC版本:v3.1.0 * * 绑定事件 * 参数tType:表格类型 thead-表头,tbody-表体 * 参数elType:元素类型 tr-行,td-单元格,ui-单元格内容 * 参数fieldNo:字段 * 参数rowIndex:行数据索引 * 参数event:要绑定的事件名称 * 参数func:绑定的事件触发函数 ***/ this.on = function(opt,func){ var tType = opt['tType'], elType = opt['elType'], fieldNo = opt['fieldNo'], rowIndex = opt['rowIndex']?opt['rowIndex']:0, event = opt['event']; if(func == undefined || func == null || typeof func != 'function'){ return false; } if(isEmpty(tType) || isEmpty(elType) || isEmpty(event)){ return false; } if(tType == 'tbody' && isEmpty(rowIndex)){ return false; } if((elType == 'td' || elType == 'ui') && isEmpty(fieldNo)){ return false; } var isLeftFixed = false; if($("#left-datagrid-htable"+formId).length>0){ isLeftFixed = true; } var lTable = null; if(isLeftFixed){ if(tType=='thead'){ lTable = $("#left-datagrid-htable"+formId); }else if(tType=='tbody'){ lTable = $("#left-datagrid-btable-ajax"+formId); } } var table = $("#datagrid-htable"+formId); if(tType=='thead'){ table = $("#datagrid-htable"+formId); }else if(tType=='tbody'){ table = $("#datagrid-btable-ajax"+formId); } if(elType=='tr'){ if(isLeftFixed && lTable){ var lTrDom = lTable.find('tr'); var trDom = table.find('tr'); if(lTrDom.length==0 || trDom.length==0 || trDom.length <= rowIndex){ return false; } $(lTrDom[rowIndex]).on(event,func); $(trDom[rowIndex]).on(event,func); return true; } var trDom = table.find('tr'); if(trDom.length==0){ return false; } $(trDom[rowIndex]).on(event,func); return true; }else if(elType == 'td'){ var trDom = table.find('tr'); if(trDom.length==0 || trDom.length <= rowIndex){ return false; } var tdDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]'); if(isLeftFixed && lTable && tdDom.length==0){ trDom = lTable.find('tr'); tdDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]'); } if(tdDom.length==0){ return false; } $(tdDom).on(event,func); return true; }else if(elType == 'ui'){ var trDom = table.find('tr'); if(trDom.length==0 || trDom.length <= rowIndex){ return false; } var uiDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]>span'); if(isLeftFixed && lTable && uiDom.length==0){ trDom = lTable.find('tr'); uiDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]>span'); } if(uiDom.length==0){ return false; } $(uiDom).on(event,func); return true; } return true; } /** * MC版本:v3.1.0 * * 解除绑定事件 * 参数tType:表格类型 thead-表头,tbody-表体 * 参数elType:元素类型 tr-行,td-单元格,ui-单元格内容 * 参数fieldNo:字段 * 参数rowIndex:行数据索引 * 参数event:要绑定的事件名称 * 参数func:绑定的事件触发函数 ***/ this.off = function(opt,func){ var tType = opt['tType'], elType = opt['elType'], fieldNo = opt['fieldNo'], rowIndex = opt['rowIndex']?opt['rowIndex']:0, event = opt['event']; if(func == undefined || func == null || typeof func != 'function'){ func = null; } if(isEmpty(tType) || isEmpty(elType) || isEmpty(event)){ return false; } if(tType == 'tbody' && isEmpty(rowIndex)){ return false; } if((elType == 'td' || elType == 'ui') && isEmpty(fieldNo)){ return false; } var isLeftFixed = false; if($("#left-datagrid-htable"+formId).length>0){ isLeftFixed = true; } var lTable = null; if(isLeftFixed){ if(tType=='thead'){ lTable = $("#left-datagrid-htable"+formId); }else if(tType=='tbody'){ lTable = $("#left-datagrid-btable-ajax"+formId); } } var table = $("#datagrid-htable"+formId); if(tType=='thead'){ table = $("#datagrid-htable"+formId); }else if(tType=='tbody'){ table = $("#datagrid-btable-ajax"+formId); } if(elType=='tr'){ if(isLeftFixed && lTable){ var lTrDom = lTable.find('tr'); var trDom = table.find('tr'); if(lTrDom.length==0 || trDom.length==0 || trDom.length <= rowIndex){ return false; } $(lTrDom[rowIndex]).off(event,func); $(trDom[rowIndex]).off(event,func); return true; } var trDom = table.find('tr'); if(trDom.length==0){ return false; } $(trDom[rowIndex]).off(event,func); return true; }else if(elType == 'td'){ var trDom = table.find('tr'); if(trDom.length==0 || trDom.length <= rowIndex){ return false; } var tdDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]'); if(isLeftFixed && lTable && tdDom.length==0){ trDom = lTable.find('tr'); tdDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]'); } if(tdDom.length==0 || trDom.length <= rowIndex){ return false; } $(tdDom).off(event,func); return true; }else if(elType == 'ui'){ var trDom = table.find('tr'); if(trDom.length==0 || trDom.length <= rowIndex){ return false; } var uiDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]>span'); if(isLeftFixed && lTable && uiDom.length==0){ trDom = lTable.find('tr'); uiDom = $(trDom[rowIndex]).find('td[name="noprintset_'+fieldNo+'"]>span'); } if(uiDom.length==0){ return false; } $(uiDom).off(event,func); return true; } return true; } /********************************提供给用户的方法end************************************/ } /** * MC版本:v3.1.0 * * 返回空串 */ function returnEmpty(obj){ if(obj == null || typeof(obj)=="undefined"){ return ""; }else{ return obj; } } /** * MC版本:v3.1.0 * * 判断是否为空、空字符串 */ function isEmpty(obj){ if(obj == null || typeof(obj)=="undefined" || (typeof obj == 'string' && obj=='')){ return true; } return false; }