function TGridCommon(id, formName, headArgs, widthArgs, alignArgs, sortArgs, typeArgs) { var self = this; var gridObj; //grid object this.formName = formName; //form name this.id = id; //TGridCommon object id this.totalPageCount; //Total Count this.responseUrl; //Ajax Request Url this.over = false; this.menu = null; //Menu object this.pageShowCount = 15; var shield; // this.headArgs = headArgs; //Header this.widthArgs = widthArgs; //Width this.alignArgs = alignArgs; //Align this.sortArgs = sortArgs; //Sort this.typeArgs = typeArgs; //Type this.attHeaderArgs = []; this.skin; this.imageUrl; this.page; this.pageSwitch; this.condition; this.subGridArgs = []; this.request; this.sourceType; this.openUrl; this.openType; this.openSet; this.isDoubleClick = false; this.isShowHeader = false; this.searchVal = ""; this.multipleSearchVal = ""; this.isHiddenColumn = false; this.isOnEditCell = false; this.isOnCheckBox = false; this.isDBClickEvent = false; this.isOnEditCell = false; this.hiddenIndex; this.loadafter = false; this.pagerName; this.pagerInfo; this.isAttchHeader = false; this.isSort = false; this.sortValue; this.sortType; //find object this.$ = function (id) { return document.getElementById(id); }; //initialization grid this.initGrid = function () { self.gridObj = new dhtmlXGridObject(self.id); self.gridObj.setImagePath(self.imageUrl); self.gridObj.setSkin(self.skin); self.gridObj.setHeader(self.headArgs.toString()); self.gridObj.setInitWidths(self.widthArgs.toString()); self.gridObj.setColAlign(self.alignArgs.toString()); self.gridObj.setColSorting(self.sortArgs.toString()); self.gridObj.setColTypes(self.typeArgs.toString()); if (self.isShowHeader) { self.gridObj.setNoHeader(self.isShowHeader); } if (self.isHiddenColumn) { self.gridObj.setColumnHidden(self.hiddenIndex, true); } if (self.isAttchHeader) { self.gridObj.attachHeader(self.attHeaderArgs); } self.gridObj.enableAlterCss("odd_row", "even_row"); self.gridObj.init(); }; this.after = function () { }; this.sortEventFun = function () { }; this.reload = function () { self.initGrid(); self.bind(); }; //grid bind this.bind = function () { //self.responseUrl + "?handle=list&i_page&show_page="+self.pageShowCount.toString()+"&cur_page=1&condition="+self.condition //self.responseUrl + "?handle=list"+self.condition if (self.loadafter) { self.gridObj.load(self.request, self.after, self.sourceType); } else { self.gridObj.load(self.request, self.sourceType); } }; this.setAttachHeader = function (args) { self.attHeaderArgs = args; } this.loadinfo = function () { }; this.showHeader = function (isShow) { self.isShowHeader = isShow; }; this.setSortValue = function (sort, type) { self.sortValue = sort; self.sortType = type; }; this.hiddenColumn = function (index, isHidden) { self.isHiddenColumn = isHidden; self.hiddenIndex = index; } //json load request url this.setRequest = function (request) { self.request = request; }; this.getRequest = function () { return self.request; }; //source type this.setSourceType = function (strSourceType) { self.sourceType = strSourceType; }; //skin this.setSkin = function (strSkin) { self.skin = strSkin; }; //imageUrl this.setImageUrl = function (strImageUrl) { self.imageUrl = strImageUrl; }; //Response Url this.setResponseUrl = function (url) { self.responseUrl = url; }; this.setPageShowCount = function (ShowCount) { self.pageShowCount = ShowCount; } // this.setIsPage = function (isOpen) { self.pageSwitch = isOpen; }; //refresh grid this.refresh = function () { self.initGrid(); }; //load sub grid this.clickShowSubGrid = function (subGridObj) { self.gridObj.attachEvent("onRowDblClicked", function (rId, cInd) { subGridObj.bind(); }); }; this.getGridObj = function () { return self.gridObj; } this.setSubGrid = function (subGrid) { self.subGridArgs = subGrid; }; //window open url this.setOpenUrl = function (openUrl) { self.openUrl = openUrl; }; //window open type this.setOpenType = function (strType) { self.openType = strType; }; //window open set this.setOpenSet = function (strSet) { self.openSet = strSet; }; this.dbclickPop = function () { //set status self.isDoubleClick = true; self.gridObj.attachEvent("onRowDblClicked", function (rId, cInd) { window.open(self.openUrl + rId, self.openType, self.openSet); }); }; this.clickEvent = function () { // if(self.gridObj != null){ // // alert(); // }else{ // alert("Object is null"); // } }; this.dbclickEvent = function () { }; this.onEditEvent = function () { }; this.onCheckBox = function () { }; this.onEditCellEvent = function () { }; this.clickRefrash = function () { self.initGrid(); }; this.setPagerName = function (objName) { self.pagerName = objName; }; this.setPagerInfo = function (objInfo) { self.pagerInfo = objInfo; } this.setPagerCount = function (count) { self.pageShowCount = count; } this.getGridRowID = function (gridObj) { var selRowID = mygrid_recv.getSelectedRowId(); var selGroup = new Array(); if (selRowID.indexOf(",") > 0) { selGroup = selRowID.split(","); } else { if (selRowID != null) { selGroup.push(selRowID); } } return selGroup; }; this.enableMultiselect = function (bValue) { self.gridObj.enableMultiselect(bValue); }; this.getObjByClassName = function (eleClassName) { var getEleClass = []; //定义一个数组 var myclass = new RegExp("\\b" + eleClassName + "\\b"); //创建一个正则表达式对像 var elem = document.body.all.tags("DIV"); //获取文档里所有的元素 for (var h = 0; h < elem.length; h++) { var classes = elem[h].className; //获取class对像 if (myclass.test(classes)) { getEleClass.push(elem[h]); //正则比较,取到想要的CLASS对像 } } return getEleClass; //返回数组 } //get total page count this.getTotalPage = function () { var urlVal = self.responseUrl + "?handle=page&val=" + self.newGuid(); var loader = dhtmlxAjax.getSync(urlVal); var loadVal = loader.xmlDoc.responseText; }; //Get Guid this.newGuid = function () { var guid = ""; for (var i = 1; i <= 32; i++) { var n = Math.floor(Math.random() * 16.0).toString(16); guid += n; if ((i == 8) || (i == 12) || (i == 16) || (i == 20)) guid += "-"; } return guid.toUpperCase(); }; //初始化页面 this.initPage = function () { self.pager = new PagerView('pager'); var urlVal = self.responseUrl + "?handle=page&val=" + self.newGuid(); //alert(self.responseUrl + "?handle=page&val="+self.newGuid()); var loader = dhtmlxAjax.getSync(urlVal); var loadVal = loader.xmlDoc.responseText; self.totalPageCount = loadVal; self.pager.itemCount = self.totalPageCount; self.pager.size = self.pageShowCount; self.pager.index = 1; self.pager.onclick = function (index) { document.getElementById('info').innerHTML = '现在翻到第' + index + '页'; self.request = self.responseUrl + "?handle=list&show_page=" + self.pager.size.toString() + "&cur_page=" + index; setTimeout(function () { self.initGrid(); self.bind(); if (self.isDoubleClick) { self.dbclickPop(); } }, 300); }; self.pager.render(); }; this.initCommonPager = function (handleName, idQuery) { if (self.pagerName != null) { self.pager = new PagerView(self.pagerName); } else { self.pager = new PagerView('pager'); } var urlVal = ""; if (self.searchVal.length > 1) { //urlVal = self.responseUrl + "?handle=" + handleName + "page&search=" + escape(self.searchVal) + idQuery + "&val=" + self.newGuid(); if (self.multipleSearchVal.length > 1) { urlVal = self.responseUrl + "?handle=" + handleName + "page&search=" + escape(self.searchVal) + self.multipleSearchVal + idQuery + "&val=" + self.newGuid(); } else { urlVal = self.responseUrl + "?handle=" + handleName + "page&search=" + escape(self.searchVal) + idQuery + "&val=" + self.newGuid(); } } else { //urlVal = self.responseUrl + "?handle=" + handleName + "page" + idQuery + "&val=" + self.newGuid(); if (self.multipleSearchVal.length > 1) { urlVal = self.responseUrl + "?handle=" + handleName + "page" + self.multipleSearchVal + idQuery + "&val=" + self.newGuid(); } else { urlVal = self.responseUrl + "?handle=" + handleName + "page" + idQuery + "&val=" + self.newGuid(); } } var loader = dhtmlxAjax.getSync(urlVal); var loadVal = loader.xmlDoc.responseText; self.totalPageCount = loadVal; self.pager.itemCount = self.totalPageCount; self.pager.size = self.pageShowCount; self.pager.index = 1; self.pager.onclick = function (index) { if (self.pagerInfo != null) { document.getElementById(self.pagerInfo).innerHTML = '现在翻到第' + index + '页'; } else { document.getElementById('info').innerHTML = '现在翻到第' + index + '页'; } if (self.searchVal.length > 1) { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + idQuery + "&search=" + escape(self.searchVal); } else { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + idQuery; } setTimeout(function () { self.initGrid(); self.bind(); self.clickEvent(); if (self.isDoubleClick) { self.dbclickPop(); } if (self.isOnEditCell) { self.onEditEvent(); } if (self.isOnCheckBox) { self.onCheckBox(); } if (self.isOnEditCell) { self.onEditCellEvent(); } }, 300); }; self.pager.render(); } //初始化页面 this.initPageByHandle = function (handleName) { var lsurl = ""; self.pager = new PagerView('pager'); var urlVal = ""; if (self.searchVal.length > 1) { if (self.multipleSearchVal.length > 1) { urlVal = self.responseUrl + "?handle=" + handleName + "page&search=" + escape(self.searchVal) + self.multipleSearchVal + "&val=" + self.newGuid(); } else { urlVal = self.responseUrl + "?handle=" + handleName + "page&search=" + escape(self.searchVal) + "&val=" + self.newGuid(); } } else { if (self.multipleSearchVal.length > 1) { urlVal = self.responseUrl + "?handle=" + handleName + "page" + self.multipleSearchVal + "&val=" + self.newGuid(); } else { urlVal = self.responseUrl + "?handle=" + handleName + "page&val=" + self.newGuid(); } } var loader = dhtmlxAjax.getSync(urlVal); var loadVal = loader.xmlDoc.responseText; self.totalPageCount = loadVal; self.pager.itemCount = self.totalPageCount; self.pager.size = self.pageShowCount; self.pager.index = 1; self.pager.onclick = function (index) { document.getElementById('info').innerHTML = '现在翻到第' + index + '页'; if (self.searchVal.length > 1) { var tempSortValue = ""; var tempSortIndex = ""; if (self.sortValue != null && self.sortType != null) { tempSortValue = "&sort=" + self.sortValue; tempSortIndex = "&sortindex=" + self.sortType; // if(self.request.indexOf("&sort=") >= 0){ // var beginString = self.request.substr(0,self.request.indexOf("&sort=")); // var endString = self.request.substr(self.request.indexOf("&sort="),self.request.length - self.request.indexOf("&sort=")); // var midString = endString.substr(1,endString.length - 1); // var midSecondStr = ""; // if(midString.indexOf("&") >= 0){ // midSecondStr = midString.substr(midString.indexOf("&"),midString.length-midString.indexOf("&")); // } // // self.request = beginString+tempSortValue+midSecondStr; // } // // if(self.request.indexOf("&sortindex=") >= 0){ // var beginString = self.request.substr(0,self.request.indexOf("&sortindex=")); // var endString = self.request.substr(self.request.indexOf("&sortindex="),self.request.length - self.request.indexOf("&sortindex=")); // var midString = endString.substr(1,endString.length - 1); // var midSecondStr = ""; // if(midString.indexOf("&") >= 0){ // midSecondStr = midString.substr(midString.indexOf("&"),midString.length-midString.indexOf("&")); // } // // self.request = beginString+tempSortIndex+midSecondStr; // } lsurl = self.responseUrl + "?show_page=" + self.pager.size.toString() + "&cur_page=" + index + "&search=" + escape(self.searchVal) + tempSortValue + tempSortIndex; //self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + "&search=" + escape(self.searchVal) + tempSortValue + tempSortIndex; if (self.multipleSearchVal.length > 1) { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + "&search=" + escape(self.searchVal) + tempSortValue + tempSortIndex + self.multipleSearchVal; } else { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + "&search=" + escape(self.searchVal) + tempSortValue + tempSortIndex; } } else { lsurl = self.responseUrl + "?show_page=" + self.pager.size.toString() + "&cur_page=" + index + "&search=" + escape(self.searchVal); //self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + "&search=" + escape(self.searchVal); if (self.multipleSearchVal.length > 1) { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + "&search=" + escape(self.searchVal) + self.multipleSearchVal; } else { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + "&search=" + escape(self.searchVal); } } } else { var tempSortValue = ""; var tempSortIndex = ""; if (self.sortValue != null && self.sortType != null) { tempSortValue = "&sort=" + self.sortValue; tempSortIndex = "&sortindex=" + self.sortType; // if(self.request.indexOf("&sort=") >= 0){ // var beginString = self.request.substr(0,self.request.indexOf("&sort=")); // var endString = self.request.substr((self.request.indexOf("&sort=")),(self.request.length - self.request.indexOf("&sort="))); // var midString = endString.substr(1,endString.length - 1); // var midSecondStr = ""; // if(midString.indexOf("&") >= 0){ // midSecondStr = midString.substr(midString.indexOf("&"),midString.length-midString.indexOf("&")); // } // // self.request = beginString+tempSortValue+midSecondStr; // } // // if(self.request.indexOf("&sortindex=") >= 0){ // var beginString = self.request.substr(0,self.request.indexOf("&sortindex=")); // var endString = self.request.substr(self.request.indexOf("&sortindex="),self.request.length - self.request.indexOf("&sortindex=")); // var midString = endString.substr(1,endString.length - 1); // var midSecondStr = ""; // if(midString.indexOf("&") >= 0){ // midSecondStr = midString.substr(midString.indexOf("&"),midString.length-midString.indexOf("&")); // } // // self.request = beginString+tempSortIndex+midSecondStr; // } lsurl = self.responseUrl + "?show_page=" + self.pager.size.toString() + "&cur_page=" + index + tempSortValue + tempSortIndex; //self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + tempSortValue + tempSortIndex; if (self.multipleSearchVal.length > 1) { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + tempSortValue + tempSortIndex + self.multipleSearchVal; } else { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + tempSortValue + tempSortIndex; } } else { lsurl = self.responseUrl + "?show_page=" + self.pager.size.toString() + "&cur_page=" + index; //self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index; if (self.multipleSearchVal.length > 1) { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + self.multipleSearchVal; } else { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index; } } } setTimeout(function () { self.initGrid(); self.bind(); self.clickEvent(); self.onEditEvent(); if (self.isDoubleClick) { self.dbclickPop(); } if (self.isDBClickEvent) { self.dbclickEvent(); } if (self.isOnEditCell) { self.onEditCellEvent(); } if (self.isSort) { self.sortEventFun(); } if (self.isOnCheckBox) { self.onCheckBox(); } }, 300); }; self.pager.render(); }; //初始化页面 this.initPageByGID = function (handleName, idQuery) { self.pager = new PagerView('pager'); var urlVal = ""; if (self.searchVal.length > 1) { urlVal = self.responseUrl + "?handle=" + handleName + "page&search=" + escape(self.searchVal) + idQuery + "&val=" + self.newGuid(); //alert(self.responseUrl + "?handle=page&val="+self.newGuid()); } else { urlVal = self.responseUrl + "?handle=" + handleName + "page" + idQuery + "&val=" + self.newGuid(); } var loader = dhtmlxAjax.getSync(urlVal); var loadVal = loader.xmlDoc.responseText; self.totalPageCount = loadVal; self.pager.itemCount = self.totalPageCount; self.pager.size = self.pageShowCount; self.pager.index = 1; self.pager.onclick = function (index) { document.getElementById('info').innerHTML = '现在翻到第' + index + '页'; if (self.searchVal.length > 1) { //self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + idQuery + "&search=" + escape(self.searchVal); if (self.multipleSearchVal.length > 1) { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + idQuery + "&search=" + escape(self.searchVal) + self.multipleSearchVal; } else { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + idQuery + "&search=" + escape(self.searchVal); } } else { //self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + idQuery; if (self.multipleSearchVal.length > 1) { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + idQuery + self.multipleSearchVal; } else { self.request = self.responseUrl + "?handle=" + handleName + "&show_page=" + self.pager.size.toString() + "&cur_page=" + index + idQuery; } } setTimeout(function () { self.initGrid(); self.bind(); self.clickEvent(); if (self.isDoubleClick) { self.dbclickPop(); } if (self.isOnEditCell) { self.onEditEvent(); } if (self.isOnCheckBox) { self.onCheckBox(); } if (self.isOnEditCell) { self.onEditCellEvent(); } }, 300); }; self.pager.render(); }; //save grid column setting change(include: name,width,index) this.saveColumnSetting = function () { var colCount = this.gridObj.getColumnsNum(); var jsonFeeObj = ""; jsonFeeObj = "{\"$type\":\"DSWeb.Models.JsonColumnGroupEntity, DSWeb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\",\"ShowCount\":" + pageShowCount + ",\"JsonColumnEntities\":["; var tempGroupJson = ""; for (var i = 0; i < colCount; i++) { var tempJson = ""; var rId = this.gridObj.getRowId(i); tempJson += "\"$type\":\"DSWeb.Models.JsonColumnEntity, DSWeb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\","; tempJson += "\"col1\":\"\","; //gid tempJson += "\"col2\":\"" + i.toString() + "\","; //column name tempJson += "\"col3\":\"" + this.gridObj.getColumnLabel(i) + "\","; //column description tempJson += "\"col4\":\"" + i.toString() + "\","; //index tempJson += "\"col5\":\"" + this.gridObj.getColWidth(i) + "\","; //width tempJson += "\"col6\":-1"; tempJson = "{" + tempJson + "}"; if (i == colCount - 1) { tempGroupJson += tempJson; } else { tempGroupJson += tempJson + ","; } } jsonFeeObj += tempGroupJson; jsonFeeObj += "]}"; $("hid_setting").value = jsonFeeObj; jsonFeeObj = null; //alert(jsonFeeObj); var myForm = document.getElementById("form1"); myForm.submit(); }; this.initMenu = function (id) { this.$(id).oncontextmenu = function (ev) { showMenu(ev); return false; }; document.onmousedown = function () { if (!self.over) hideMenu(); }; }; //显示右键菜单 this.showMenu = function () { self.menu = null; ev = ev || window.event; hideMenu(); var e = ev.srcElement || ev.target; if (e.tagName == "TH") return; var x = ev.pageX || ev.clientX + document.documentElement.scrollLeft; var y = ev.pageY || ev.clientY + document.documentElement.scrollTop; self.menu = document.createElement("DIV"); self.menu.className = "menu"; self.menu.style.left = x + 4 + "px"; self.menu.style.top = y + "px"; document.body.appendChild(self.menu); //alert(e.parentNode.getElementsByTagName("DIV")[1].innerHTML); var dvGroup = e.parentNode.getElementsByTagName("DIV"); var dvGroupCount = dvGroup.length; var id = ""; if (dvGroupCount == 1) { id = dvGroup[0].innerHTML; } if (id.trim().length < 1) { hideMenu(); return; } var sname = document.location.pathname.substring(7, location.pathname.length).toString(); var s = "