You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/js/jquery/js/JPaging.js

472 lines
19 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

JPaging = window.JPaging = {
params:{
g_el:[],
g_header_data:{},
g_header_cell_mclass:"cellHeader",//列表Title列主样式
g_header_cell_class:{},//列表Title列附加样式 (列名:样式名)
g_header_sort:[],//哪些列需要排序 (列名:样式名)
g_header_current_sort:[],//当前排序字段和排序方式["username","ASC"]
g_call_fun:"GoPage('indexPage',CurrSort)",//页面分页主方法默认值 为GoPage();
g_cellFuncs:[],
g_dvbody:"dvGridContent",//列表内容的样式
g_body_group:[],//是否分组,如果分组请写上分组的ID和Value
g_body_data:[],//列表内容
g_convert_chk_cell:["gid"],//要生成复选框的列
g_last_cell_width:20,//表头最后一列的宽度
g_body_height:250,//整个列表内容高度
g_total:0,//每页记录数
g_pageSize:20,//每页记录数
g_pageIndex:1,
g_loading:'Loading...',//Loading
g_bShowPager:true
},
init:function(s){
this._Loading(true);
jQuery.extend(this.params, s);
this.g_render();
this._Loading(false);
},
g_render:function(){
var el = this.params.g_el;
$("#"+el).html("");
var haderData = this.params.g_header_data;
var hader_cell_mclass = this.params.g_header_cell_mclass;
var _cellFuncs = this.params.g_cellFuncs;
var hader_cell_class = this.params.g_header_cell_class;
var header_sort = this.params.g_header_sort;
var header_current_sort = this.params.g_header_current_sort;
var dv_body_class=this.params.g_dvbody;
var convert_chk_cell=this.params.g_convert_chk_cell;
var body_group=this.params.g_body_group;
var body_data=this.params.g_body_data;
var total=this.params.g_total;
var pageIndex=this.params.g_pageIndex;
var bShowPager = this.params.g_bShowPager;
$.each(el,function(k,v){
var dv_g = v; tb_header=v+"_tb_header";tb_header_row=v+"_tb_header_row";dvBody=v+"dvbody";dvPagerID=v+"pager";
$("#"+dv_g).addClass("dv_grid");
$("#"+dv_g).append("<table id=\""+tb_header+"\" class=\"grid\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr id=\""+tb_header_row+"\"></tr></table>");
$.each(haderData,function(i,n){
h_c_c= hader_cell_mclass;
$.each(hader_cell_class,function(ck,cv){
if( ck == i) {h_c_c +=" "+cv;}
});
$.each(convert_chk_cell,function(convertK,convertV){
if( convertV == i) {n ="<input name=\"ckb_All_"+convertV+"\" id=\"ckb_All_"+convertV+"\" onclick=\"JPaging._CheckAll('"+convertV+"');\" type=\"checkbox\" class=\"chk\"/>"; }
});
var td_id = tb_header+"_id_"+i;
var tdClick = "";
var strSort="";
$.each(header_sort,function(hsK,hsV){
if(hsV==i){
sortField=i;
sequence="ASC";
if(header_current_sort[0]==i){
sequence=header_current_sort[1]=="ASC" ? "DESC":"ASC";
}else{
sequence=header_current_sort[1]=="ASC" ? "ASC":"DESC";
}
sort_Params = "['"+sortField+"','"+sequence+"']";
tdClick=" onclick=\"JPaging._GoPage('','"+sortField+"','"+sequence+"')\"";
if(header_current_sort[0]==i && header_current_sort[1]=="ASC"){
strSort="<span class=\"grid-sort-Asc\"></span>";
}else if(header_current_sort[0]==i && header_current_sort[1]=="DESC"){
strSort="<span class=\"grid-sort-Desc\"></span>";
}
}
});
var SortTitle = (tdClick!=""?"title=\"Click to Sort\"":"");
var g_h_c = "<td id=\""+td_id+"\" class=\""+h_c_c+"\">"+
"<span class=\"grid-resize\"><font></font></span>"+ strSort +
"<span class=\"grid-header-Text\" "+tdClick+"><span style=\"cursor:pointer;\" "+SortTitle+">"+n+"</span></span>" +
"</td>";
$("#"+tb_header_row).append(g_h_c);
});
$("#"+tb_header_row).append("<td class=\""+h_c_c+"\" style=\"width:15px\"></td>");
$("#"+dv_g).append("<div id=\""+dvBody+"\" class=\""+dv_body_class+"\"></div>");
var group_table_id = new Array();
if(body_group.length>0){
$.each(body_group,function(group_K,group_V){
dataList = body_data[group_K];
if(dataList!=null && dataList.length>0){
group_id=dvBody+"_group"+group_K;
group_tb_id=dvBody+"_"+group_K;
group_table_id.push(group_tb_id);
$("#"+dvBody).append("<div id=\""+group_id+"\" class=\"grid_group_title\"><div onclick=\"JPaging.grid_groupTree_clickevent('"+group_id+"','"+group_tb_id+"');\" class=\"grid-group-treemin\"></div>"+group_V+"</div>");
$("#"+group_id).after("<table id=\""+group_tb_id+"\" class=\"grid\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"></table>");
$.each(dataList,function(dK,dV){
trID = group_tb_id+"tr"+dK;
$("#"+group_tb_id).append("<tr id=\""+trID+"\"></tr>");
$.each(haderData,function(haderKey,haderVal){/* 根据头生成列 */
var bExist = false;
var tdContent = "";
$.each(dV,function(dK_C,dV_C){
if(haderKey==dK_C){
tdContent = dV_C;
bExist = true;
$.each(convert_chk_cell,function(convertK,convertV){
if( convertV == dK_C) tdContent ="<input name=\"ckb_"+convertV+"\" id=\"ckb_"+convertV+"\" onclick=\"JPaging._selCheck(this,'"+dK_C+"');\" type=\"checkbox\" value=\"" + dV_C + "\"/>";
});
$.each(_cellFuncs,function(cellFuncsKey,cellFuncsVal){
if( cellFuncsKey == haderKey){
if (typeof cellFuncsVal == 'function') tdContent = (cellFuncsVal(dV));
}
});
}
});
if(!bExist){
$.each(_cellFuncs,function(cellFuncsKey,cellFuncsVal){
if( cellFuncsKey == haderKey){
if (typeof cellFuncsVal == 'function') tdContent = (cellFuncsVal(dV));
}
});
}
$("#"+trID).append("<td><div class=\"grid-cell-content\">"+tdContent+"</div></td>");
});
});
}
});
}else{
//不分组
group_tb_id=dvBody+"_table";
group_table_id.push(group_tb_id);
$("#"+dvBody).append("<table id=\""+group_tb_id+"\" class=\"grid\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"></table>");
$.each(body_data,function(dK,dV){/* 内容行 */
trID = group_tb_id+"tr"+dK;
$("#"+group_tb_id).append("<tr id=\""+trID+"\"></tr>");
$.each(haderData,function(haderKey,haderVal){/* 根据头生成列 */
var bExist = false;
var tdContent = "";
$.each(dV,function(dK_C,dV_C){
if(haderKey==dK_C){
tdContent = dV_C;
bExist = true;
$.each(convert_chk_cell,function(convertK,convertV){
if( convertV == dK_C) tdContent ="<input name=\"ckb_"+convertV+"\" id=\"ckb_"+convertV+"\" onclick=\"JPaging._selCheck(this,'"+dK_C+"');\" type=\"checkbox\" value=\"" + dV_C + "\"/>";
});
$.each(_cellFuncs,function(cellFuncsKey,cellFuncsVal){
if( cellFuncsKey == haderKey){
if (typeof cellFuncsVal == 'function') tdContent = (cellFuncsVal(dV));
}
});
}
});
if(!bExist){
$.each(_cellFuncs,function(cellFuncsKey,cellFuncsVal){
if( cellFuncsKey == haderKey){
if (typeof cellFuncsVal == 'function') tdContent = (cellFuncsVal(dV));
}
});
}
$("#"+trID).append("<td><div class=\"grid-cell-content\">"+tdContent+"</div></td>");
});
});
}
if(bShowPager){
var htmlPager = JPaging.grid_render_pager(total,pageIndex);
if($("#"+dvPagerID).html()==null){
$("#"+dv_g).after("<div class=\"x-toolbar\" id=\""+dvPagerID+"\">"+htmlPager+"</div>");
}else{
$("#"+dvPagerID).html(htmlPager);
}
}
$.each($("#"+tb_header_row+">td"),function(){
$(this).hover(
function () {
$(this).addClass("cellHeaderOver");
},
function () {
$(this).removeClass("cellHeaderOver");
}
);
});
$.each($(".grid-resize"),function(){JPaging.drag(this,group_table_id)});
JPaging.ReSizeDvContentWidth(tb_header,[dvBody]);//分组DIV与标题表宽度相同
JPaging.ReSizeWidth(tb_header,group_table_id);//内容表与标题表宽度相同
JPaging.SubCell_Width(tb_header,group_table_id);//内容中的列与表头相同
JPaging.rowStyle(group_table_id);//添加隔行样式
//alert($("#"+dv_g).html());
$(window).resize(function(){
JPaging.ReSizeDvContentWidth(tb_header,[dvBody]);//分组DIV与标题表宽度相同
JPaging.ReSizeWidth(tb_header,group_table_id);//内容表与标题表宽度相同
JPaging.SubCell_Width(tb_header,group_table_id);//内容中的列与表头相同
JPaging.rowStyle(group_table_id);//添加隔行样式
});
});
},
grid_render_pager : function(_total, _pageIndex){
var pageSize = this.params.g_pageSize;
var iTxtPageID = "txtiPage"+this.params.g_el;
var pagecount = (_total % pageSize == 0) ? parseInt(_total / pageSize) : parseInt((_total / pageSize) + 1);
var btnFirst = this.btnPager("x-btn-text "+(_pageIndex == 1 ? "x-tbar-page-first-disabled" : "x-tbar-page-first"),"First Page", 1);
var btnPrevious = this.btnPager("x-btn-text "+(_pageIndex > 1 ? "x-tbar-page-prev" : "x-tbar-page-prev-disabled"), "Previous Page", ((parseInt(_pageIndex) - 1) < 1 ? 0 : (parseInt(_pageIndex) - 1)));
var btnNext = this.btnPager("x-btn-text "+((_total != 0 && _pageIndex < pagecount) ? "x-tbar-page-next" : "x-tbar-page-next-disabled"), "Next Page", ((parseInt(_pageIndex)+1 ) > pagecount ? 0 : (parseInt(_pageIndex) + 1)));
var btnLast = this.btnPager("x-btn-text "+((_total != 0 && _pageIndex < pagecount) ? "x-tbar-page-last" : "x-tbar-page-last-disabled"), "Last Page", pagecount);
var btnRefresh = this.btnPager("x-btn-text "+((_total != 0) ? "x-tbar-loading" : "x-tbar-loading-disabled"), "Refresh", _pageIndex);
var startRow = pageSize*(_pageIndex-1);
var endRow = ((startRow + pageSize) > _total) ? _total : (startRow + pageSize);
var strPager = " <table cellSpacing=\"0\"><tbody>" + "<tr>" + "<td>" + btnFirst + "</td>" + "<td>" + btnPrevious + "</td>" + "<td><span class=\"sep\"></span></td>" + "<td><span class=\"ytb-text\">Page</span></td>" + "<td><input onKeyPress=\"event.returnValue=JPaging.goToPage("+ pagecount +",'"+iTxtPageID+"');\" name=\""+iTxtPageID+"\" id=\""+iTxtPageID+"\" class=\"x-tbar-page-number\" title=\"Enter PageIndex\" value=\"" + _pageIndex + "\" size=\"3\"></td>" + "<td><span class=\"ytb-text\">of " + pagecount + "&nbsp;</span></td>" + "<td><span class=\"sep\"></span></td>" + "<td>" + btnNext + "</td>" + "<td>" + btnLast + "</td>" + "<td><span class=\"sep\"></span></td>" + "<td>" + btnRefresh + "</td>" + "</tr>" + "</tbody></table>" + "<div class=\"x-paging-info\" id=\"layer\"> Displaying topics " + startRow + " - " + endRow + " of " + _total + "</div>";
return strPager;
},
btnPager:function (classname, tips, iPage) {
var click = (iPage != 0) ? "onclick=\"JPaging._GoPage(" + iPage + ",'','')\"" : "";
var strHtml = "<div style=\"width:16px;height:16px;cursor:pointer;\" " + click + " title=\"" + tips + "\" class=\"" + classname + "\">&nbsp;</div>";
return strHtml;
},
goToPage:function(maxPage,eleID){
if ((event.keyCode != 13) && (event.keyCode != 10)) {
return ((event.keyCode >= 48) && (event.keyCode <= 57));
} else {
var iPage = $("#"+eleID).val();
if (iPage < 1) {
iPage = 1;
}
if (iPage > maxPage) {
iPage = maxPage;
}
JPaging._GoPage(iPage,'','');
}
},
grid_groupTree_clickevent:function(dv_id,tb_id){
if($("#"+dv_id+">div").attr("class")=="grid-group-treemin"){
$("#"+dv_id+">div").attr("class","grid-group-treeexp");
$("#"+tb_id).hide("fast");
}else{
$("#"+dv_id+">div").attr("class","grid-group-treemin");
$("#"+tb_id).show("fast");
}
},
rowStyle:function(arrSubTb){
for(key in arrSubTb){
grid = document.getElementById(arrSubTb[key]);
$("#"+arrSubTb[key]).find("tr").hover(
function () {
$(this).addClass("Row4");
},
function () {
$(this).removeClass("Row4");
}
);
for(currRowNum=0;currRowNum<grid.rows.length;currRowNum++){
if(currRowNum%3==0){
if(currRowNum%6==0){
grid.rows[currRowNum].className = "Row2";
}else{
grid.rows[currRowNum].className = "Row1";
}
}else{
grid.rows[currRowNum].className = "Row3";
}
}
}
},
Pager_Width : function(EL){
if(window.ActiveXObject){
return EL.offsetWidth;
}else{
return parseInt(EL.offsetWidth)- parseInt(EL.cellPadding)*2-0;//-2
}
},
ReSizeWidth : function(headerID,arrTargetID){
headerEL = document.getElementById(headerID);
target_width = JPaging.Pager_Width(headerEL);
for(key in arrTargetID){
$("#"+arrTargetID[key]).css("width",target_width-this.params.g_last_cell_width+2);
}
},
SubCell_Width : function(headerID,arrSubTb){
headerEL = document.getElementById(headerID);
for(var i=0;i<headerEL.rows[0].cells.length-1;i++) {
cell_w = headerEL.rows[0].cells[i].offsetWidth;
for(key in arrSubTb){
$("#"+arrSubTb[key]).find("td:nth-child("+parseInt(i+1)+")").css({"width":cell_w});
}
}
},
ReSizeDvContentWidth : function(headerID,arrDvContentID){
headerEL = document.getElementById(headerID);
target_width = JPaging.Pager_Width(headerEL);
for(key in arrDvContentID){
$("#"+arrDvContentID[key]).css("width",target_width);
$("#"+arrDvContentID[key]).css({"overflow-x":"hidden","overflow-y":"scroll","height":this.params.g_body_height});//scroll
}
},
_selCheck:function (obj,suffix) {
if (obj.checked == true) {
$(obj).parent().parent().parent().addClass("Row5");
} else {
$(obj).parent().parent().parent().removeClass("Row5");
}
},
_CheckAll : function(suffix){
if($("#ckb_All_"+suffix).attr("checked")==true){
$("input[type='checkbox'][id='ckb_"+suffix+"']").each(function(){
if($(this).attr("checked")!=true){
$(this).click();
}
});
}else{
$("input[type='checkbox'][id='ckb_"+suffix+"']").each(function(){
if($(this).attr("checked")==true){
$(this).click();
}
});
}
},
_GetCheckValue:function(suffix,eleID){
var selValue = "";
if(suffix==null || suffix=='undefined' || suffix==''){
suffix="gid";
}
$("input:checked[type='checkbox'][id='ckb_"+suffix+"']").each(function(){
selValue += $(this).attr("value")+",";
});
if(selValue!=""){
selValue = selValue.substring(0,selValue.length-1);
if(eleID!=null && eleID!='undefined' && eleID!=''){
$("#"+eleID).val(selValue);
}
}
return selValue;
},
_GoPage : function(_indexPage,_sortField,_sequence){
var call_fun = this.params.g_call_fun;
_indexPage = (_indexPage=='' || _indexPage==null || _indexPage=='undefined')?this.params.g_pageIndex:_indexPage;
if(_sortField==''|| _sortField==null || _sortField=='undefined'){
_currSort=this.params.g_header_current_sort;
if(_currSort.length>0){
_sort_Params = "['"+_currSort[0]+"','"+_currSort[1]+"']"
}else{
_sort_Params = "[]";
}
}else{
_sequence = (_sequence=='' || _sequence==null || _sequence=='undefined')?"ASC":_sequence;
_sort_Params = "['"+_sortField+"','"+_sequence+"']";
}
call_fun=call_fun.replace("indexPage",_indexPage).replace("CurrSort",_sort_Params);
//$("#dvInfo").append(call_fun+"<br>");
eval(call_fun);
},
_Loading:function(_bshow){
_topELE = function(ele){
var _e;
try{
_e = top.document.getElementById(ele);
}catch(e){
_e = document.getElementById(ele);
}
return _e ;
}
_topCreateELE = function(ele){
var _e;
try{
_e = top.document.createElement(ele);
}catch(e){
_e = document.createElement(ele);
}
return _e ;
}
if(_bshow){
var loadingMessage=JPaging.params.g_loading;
var disabledZone = _topELE("disabledZone");
if (!disabledZone) {
disabledZone = _topCreateELE("div");
disabledZone.setAttribute("id", "disabledZone");
disabledZone.className = "loading";
disabledZone.style.position = "absolute";
disabledZone.style.width = "60px";
disabledZone.style.height = "18px";
disabledZone.style.zIndex = "1000";
disabledZone.style.background = "red";
disabledZone.style.textAlign = "center";
disabledZone.style.verticalAlign = "middle";
disabledZone.style.color = "#FFFFFF";
if(top.location.href==location.href){
disabledZone.style.left = document.body.clientWidth / 2 - 30;
disabledZone.style.top = "0px";
}else{
disabledZone.style.right = "0px";
disabledZone.style.top = "50px";
}
top.document.body.appendChild(disabledZone);
var messageZone = top.document.createElement("div");
messageZone.setAttribute("id", "messageZone");
disabledZone.appendChild(messageZone);
var text = top.document.createTextNode(loadingMessage);
messageZone.appendChild(text);
} else {
_topELE("messageZone").innerHTML = loadingMessage;
disabledZone.style.visibility = "visible";
}
}else{
_topELE("disabledZone").style.visibility= "hidden";
}
},
drag:function(o,tableList){
o.p_p_c_gw=function(index)/*取得o.parentNode.parentNode.cells的宽度兼容IE6和Firefox*/{
if(window.ActiveXObject){
return o.parentNode.parentNode.cells[o.parentNode.cellIndex+index].offsetWidth;
}else{
return parseInt(o.parentNode.parentNode.cells[o.parentNode.cellIndex+index].offsetWidth)-
parseInt(o.parentNode.parentNode.parentNode.parentNode.cellPadding)*2-0;//-2
}
}
o.p_p_p_sw=function(index,w)/*设置所有行的第index个单元格为w*/{
var el = JPaging.params.g_el;
for(headerKey in el){
$("#"+el[key]).find("td:nth-child("+parseInt(index+1)+")").css({"width":w});
}
for(key in tableList){
$("#"+tableList[key]).find("td:nth-child("+parseInt(index+1)+")").css({"width":w});
}
};
o.firstChild.onmousedown=function(){return false;};
o.onclick=function(){return false;};
o.onmousedown=function(a){
var d=document;if(!a)a=window.event;
var lastX=a.clientX;
var watch_dog=o.p_p_c_gw(0)+o.p_p_c_gw(1);//有时候拖拽过快表格会变大至于为什么会这样我也不清楚。watch_dog是为了保证表格不会变大
if(o.setCapture)
o.setCapture();
else if(window.captureEvents)
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
//
d.onmousemove=function(a){
if(!a)a=window.event;
//$("#dvSpan").html(watch_dog-o.p_p_c_gw(0));
if(o.p_p_c_gw(0)+o.p_p_c_gw(1)>watch_dog){
o.p_p_p_sw(o.parentNode.cellIndex+1,watch_dog-o.p_p_c_gw(0));
return;
}
var t=a.clientX-lastX;//out.innerHTML=t;//$("#dvSpan").html(o.parentNode.parentNode.cells[o.parentNode.cellIndex].style.width);
if(t>0) {//right
if(parseInt(o.parentNode.parentNode.cells[o.parentNode.cellIndex+1].style.width)-t<20)
return;
o.p_p_p_sw(o.parentNode.cellIndex,o.p_p_c_gw(0)+t);
o.p_p_p_sw(o.parentNode.cellIndex+1,o.p_p_c_gw(1)-t);
} else {//left
if(parseInt(o.parentNode.parentNode.cells[o.parentNode.cellIndex].style.width)+t<20)
return;
o.p_p_p_sw(o.parentNode.cellIndex,o.p_p_c_gw(0)+t);
o.p_p_p_sw(o.parentNode.cellIndex+1,o.p_p_c_gw(1)-t);
}
lastX=a.clientX;
};
d.onmouseup=function(){
if(o.releaseCapture)
o.releaseCapture();
else if(window.captureEvents)
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
d.onmousemove=null;
d.onmouseup=null;
};
};
}
};