13 lines
59 KiB
JavaScript
13 lines
59 KiB
JavaScript
/**
|
|
* jQuery.bsgrid v1.38 by @Baishui2004
|
|
* Copyright 2014 Apache v2 License
|
|
* https://github.com/baishui2004/jquery.bsgrid
|
|
*/
|
|
|
|
String.prototype.startWith=function(a){if(a==null||a==""||this.length==0||a.length>this.length){return false}else{return this.substr(0,a.length)==a}};String.prototype.endWith=function(a){if(a==null||a==""||this.length==0||a.length>this.length){return false}else{return this.substring(this.length-a.length)==a}};String.prototype.replaceAll=function(a,b){return this.replace(new RegExp(a,"gm"),b)};function StringBuilder(){if(arguments.length){this.append.apply(this,arguments)}}StringBuilder.prototype=function(){var c=Array.prototype.join,d=Array.prototype.slice,a=/\{(\d+)\}/g,b=function(){return c.call(this,"")};return{constructor:StringBuilder,length:0,append:Array.prototype.push,appendFormat:function(e){var g=0,f=d.call(arguments,1);this.append(a.test(e)?e.replace(a,function(h,j){return f[j]}):e.replace(/\?/g,function(){return f[g++]}));return this},size:function(){return this.toString().length},toString:b,valueOf:b}}();
|
|
$.bsgrid={param:function(c,b){if(b==undefined){b=false}if(!b){return $.param(c)}var d=new StringBuilder();if(c instanceof Array){$.each(c,function(f,e){d.append("&"+e.name+"=");d.append(encodeURIComponent(encodeURIComponent(e.value)))})}else{for(var a in c){d.append("&"+a+"=");d.append(encodeURIComponent(encodeURIComponent(c[a])))}}return d.length>0?d.toString().substring(1):""},getKeysString:function(c,a){if(a==undefined){a=","}var d=new StringBuilder();if(c instanceof Array){$.each(c,function(f,e){if((d.toString()+a).indexOf(a+e.name+a)==-1){d.append(a+e.name)}})}else{for(var b in c){d.append(a+b)}}return d.length>0?d.toString().substring(1):""},forcePushPropertyInObject:function(b,a,c){if(b.hasOwnProperty(a)){b[a+"_f"]=c}else{b[a]=c}},adaptAttrOrProp:function(b,d,c){var a=parseInt($.fn.jquery.substring(0,$.fn.jquery.indexOf(".",2)).replace(".",""));if(c==undefined){if(a>=16){return b.prop(d)}else{return b.attr(d)}}else{if(a>=16){b.prop(d,c)}else{b.attr(d,c)}}},alert:function(a){alert(a)}};
|
|
(function(a){a.fn.bsgrid_paging={defaults:{loopback:false,pageSize:20,pageSizeSelect:false,pageSizeForGrid:[5,10,20,25,50,100,200,500],pageIncorrectTurnAlert:true,pagingLittleToolbar:false,pagingBtnClass:"pagingBtn",pagingMinWidth:"auto",pagingBtnShowState:{select:true,first:true,prev:true,next:true,last:true,gotoBtn:true,refresh:true}},pagingObjs:{},init:function(h,g){var d={settings:a.extend(true,{},a.fn.bsgrid_paging.defaults,g),pagingId:h,totalRowsId:h+"_totalRows",totalPagesId:h+"_totalPages",curPageId:h+"_curPage",gotoPageInputId:h+"_gotoPageInput",gotoPageId:h+"_gotoPage",refreshPageId:h+"_refreshPage",pageSizeId:h+"_pageSize",firstPageId:h+"_firstPage",prevPageId:h+"_prevPage",nextPageId:h+"_nextPage",lastPageId:h+"_lastPage",startRowId:h+"_startRow",endRowId:h+"_endRow",totalRows:0,totalPages:0,curPage:1,curPageRowsNum:0,startRow:0,endRow:0};if(g.pageSizeForGrid!=undefined){d.settings.pageSizeForGrid=g.pageSizeForGrid}var b={options:d,page:function(i){a.fn.bsgrid_paging.page(i,d)},getCurPage:function(){return a.fn.bsgrid_paging.getCurPage(d)},refreshPage:function(){a.fn.bsgrid_paging.refreshPage(d)},firstPage:function(){a.fn.bsgrid_paging.firstPage(d)},prevPage:function(){a.fn.bsgrid_paging.prevPage(d)},nextPage:function(){a.fn.bsgrid_paging.nextPage(d)},lastPage:function(){a.fn.bsgrid_paging.lastPage(d)},gotoPage:function(i){a.fn.bsgrid_paging.gotoPage(d,i)},createPagingToolbar:function(){return a.fn.bsgrid_paging.createPagingToolbar(d)},setPagingToolbarEvents:function(){a.fn.bsgrid_paging.setPagingToolbarEvents(d)},dynamicChangePagingButtonStyle:function(){a.fn.bsgrid_paging.dynamicChangePagingButtonStyle(d)},setPagingValues:function(j,i){a.fn.bsgrid_paging.setPagingValues(j,i,d)}};a.fn.bsgrid_paging.pagingObjs[h]=b;a("#"+h).append(b.createPagingToolbar());if(d.settings.pageSizeSelect){if(a.inArray(d.settings.pageSize,d.settings.pageSizeForGrid)==-1){d.settings.pageSizeForGrid.push(d.settings.pageSize)}d.settings.pageSizeForGrid.sort(function(j,i){return j-i});var f=new StringBuilder();for(var e=0;e<d.settings.pageSizeForGrid.length;e++){var c=d.settings.pageSizeForGrid[e];f.append('<option value="'+c+'">'+c+"</option>")}a("#"+d.pageSizeId).html(f.toString()).val(d.settings.pageSize)}b.setPagingToolbarEvents();return b},getPagingObj:function(c){var b=a.fn.bsgrid_paging.pagingObjs[c];return b?b:null},page:function(c,b){var d=a.fn.bsgrid.getGridObj(b.settings.gridId);d.options.settings.pageSize=b.settings.pageSize;a.fn.bsgrid.page(c,d.options)},getCurPage:function(b){var c=a("#"+b.curPageId).html();return c==""?1:c},refreshPage:function(b){a.fn.bsgrid_paging.page(a.fn.bsgrid_paging.getCurPage(b),b)},firstPage:function(b){var c=a.fn.bsgrid_paging.getCurPage(b);if(c<=1){a.fn.bsgrid_paging.incorrectTurnAlert(b,a.bsgridLanguage.isFirstPage);return}a.fn.bsgrid_paging.page(1,b)},prevPage:function(b){var c=a.fn.bsgrid_paging.getCurPage(b);if(c<=1){if(b.settings.loopback&&b.totalPages>0){a.fn.bsgrid_paging.page(b.totalPages,b);return}else{a.fn.bsgrid_paging.incorrectTurnAlert(b,a.bsgridLanguage.isFirstPage);return}}a.fn.bsgrid_paging.page(parseInt(c)-1,b)},nextPage:function(b){var c=a.fn.bsgrid_paging.getCurPage(b);if(c>=b.totalPages){if(b.settings.loopback&&c>0){a.fn.bsgrid_paging.page(1,b);return}else{a.fn.bsgrid_paging.incorrectTurnAlert(b,a.bsgridLanguage.isLastPage);return}}a.fn.bsgrid_paging.page(parseInt(c)+1,b)},lastPage:function(b){var c=a.fn.bsgrid_paging.getCurPage(b);if(c>=b.totalPages){a.fn.bsgrid_paging.incorrectTurnAlert(b,a.bsgridLanguage.isLastPage);return}a.fn.bsgrid_paging.page(b.totalPages,b)},gotoPage:function(b,c){if(c==undefined){c=a("#"+b.gotoPageInputId).val()}if(a.trim(c)==""||isNaN(c)){a.fn.bsgrid_paging.alert(a.bsgridLanguage.needInteger)}else{if(parseInt(c)<1||parseInt(c)>b.totalPages){a.fn.bsgrid_paging.alert(a.bsgridLanguage.needRange(1,b.totalPages))}else{a("#"+b.gotoPageInputId).val(c);a.fn.bsgrid_paging.page(parseInt(c),b)}}},incorrectTurnAlert:function(b,c){if(b.settings.pageIncorrectTurnAlert){a.fn.bsgrid_paging.alert(c)}},alert:function(c){try{a.bsgrid.alert(c)}catch(b){alert(c)}},createPagingToolbar:function(b){var e=new StringBuilder();var c=b.settings.pagingLittleToolbar;e.append('<table class="bsgridPaging'+(c?" pagingLittleToolbar":"")+(b.settings.pageSizeSelect?"":" noPageSizeSelect")+'"');if(b.settings.pagingMinWidth!="auto"){e.append(' style="width: '+b.settings.pagingMinWidth+' !important"')}e.append(">");e.append("<tr>");var f=b.settings.pagingBtnShowState;if(b.settings.pageSizeSelect&&f.select){e.append("<td>"+a.bsgridLanguage.pagingToolbar.pageSizeDisplay(b.pageSizeId,c)+"</td>")}e.append("<td>"+a.bsgridLanguage.pagingToolbar.currentDisplayRows(b.startRowId,b.endRowId,c)+"</td>");e.append("<td>"+a.bsgridLanguage.pagingToolbar.totalRows(b.totalRowsId)+"</td>");var d=b.settings.pagingBtnClass;e.append("<td>");if(f.first){e.append('<input class="'+d+' firstPage" type="button" id="'+b.firstPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.firstPage)+'" />')}if(f.first&&f.prev){e.append(" ")}if(f.prev){e.append('<input class="'+d+' prevPage" type="button" id="'+b.prevPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.prevPage)+'" />')}e.append("</td>");e.append("<td>"+a.bsgridLanguage.pagingToolbar.currentDisplayPageAndTotalPages(b.curPageId,b.totalPagesId)+"</td>");e.append("<td>");if(f.next){e.append('<input class="'+d+' nextPage" type="button" id="'+b.nextPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.nextPage)+'" />')}if(f.next&&f.last){e.append(" ")}if(f.last){e.append('<input class="'+d+' lastPage" type="button" id="'+b.lastPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.lastPage)+'" />')}e.append("</td>");if(f.gotoBtn){e.append('<td class="gotoPageInputTd">');e.append('<input class="gotoPageInput" type="text" id="'+b.gotoPageInputId+'" />');e.append("</td>");e.append('<td class="gotoPageButtonTd">');e.append('<input class="'+d+' gotoPage" type="button" id="'+b.gotoPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.gotoPage)+'" />');e.append("</td>")}if(f.refresh){e.append('<td class="refreshPageTd">');e.append('<input class="'+d+' refreshPage" type="button" id="'+b.refreshPageId+'" value="'+(c?"":a.bsgridLanguage.pagingToolbar.refreshPage)+'" />');e.append("</td>")}e.append("</tr>");e.append("</table>");return e.toString()},setPagingToolbarEvents:function(b){if(b.settings.pageSizeSelect){a("#"+b.pageSizeId).change(function(){b.settings.pageSize=parseInt(a(this).val());a(this).trigger("blur");a.fn.bsgrid_paging.page(1,b)})}a("#"+b.firstPageId).click(function(){a.fn.bsgrid_paging.firstPage(b)});a("#"+b.prevPageId).click(function(){a.fn.bsgrid_paging.prevPage(b)});a("#"+b.nextPageId).click(function(){a.fn.bsgrid_paging.nextPage(b)});a("#"+b.lastPageId).click(function(){a.fn.bsgrid_paging.lastPage(b)});a("#"+b.gotoPageInputId).keyup(function(c){if(c.which==13){a.fn.bsgrid_paging.gotoPage(b)}});a("#"+b.gotoPageId).click(function(){a.fn.bsgrid_paging.gotoPage(b)});a("#"+b.refreshPageId).click(function(){a.fn.bsgrid_paging.refreshPage(b)})},dynamicChangePagingButtonStyle:function(b){var c="disabledCls";if(b.curPage<=1){a("#"+b.firstPageId).addClass(c);a("#"+b.prevPageId).addClass(c)}else{a("#"+b.firstPageId).removeClass(c);a("#"+b.prevPageId).removeClass(c)}if(b.curPage>=b.totalPages){a("#"+b.nextPageId).addClass(c);a("#"+b.lastPageId).addClass(c)}else{a("#"+b.nextPageId).removeClass(c);a("#"+b.lastPageId).removeClass(c)}},setPagingValues:function(i,g,f){i=Math.max(i,1);var b=f.settings.pageSize;var h=parseInt(g/b);h=parseInt((g%b==0)?h:h+1);var e=(i*b<g)?b:(g-(i-1)*b);var d=(i-1)*b+1;var c=d+e-1;d=e<=0?0:d;c=e<=0?0:c;f.totalRows=g;f.totalPages=h;f.curPage=i;f.curPageRowsNum=e;f.startRow=d;f.endRow=c;a("#"+f.totalRowsId).html(f.totalRows);a("#"+f.totalPagesId).html(f.totalPages);a("#"+f.curPageId).html(f.curPage);a("#"+f.startRowId).html(f.startRow);a("#"+f.endRowId).html(f.endRow);a.fn.bsgrid_paging.dynamicChangePagingButtonStyle(f)}}})(jQuery);
|
|
(function($){$.fn.bsgrid={version:"1.38-preview",defaults:{dataType:"json",dataTrim:true,ajaxType:"post",localData:false,url:"",otherParames:false,autoLoad:true,pageAll:false,showPageToolbar:true,pageSize:20,pageSizeSelect:false,pageSizeForGrid:[5,10,20,25,50,100,200,500],pageIncorrectTurnAlert:true,multiSort:false,displayBlankRows:true,lineWrap:false,stripeRows:false,rowHoverColor:false,rowSelectedColor:true,pagingLittleToolbar:false,pagingToolbarAlign:"right",pagingBtnClass:"pagingBtn",displayPagingToolbarOnlyMultiPages:false,isProcessLockScreen:true,longLengthAotoSubAndTip:true,colsProperties:{align:"center",maxLength:40,indexAttr:"w_index",sortAttr:"w_sort",alignAttr:"w_align",lengthAttr:"w_length",renderAttr:"w_render",hiddenAttr:"w_hidden",tipAttr:"w_tip"},requestParamsName:{pageSize:"pageSize",curPage:"curPage",sortName:"sortName",sortOrder:"sortOrder"},beforeSend:function(options,XMLHttpRequest){},complete:function(options,XMLHttpRequest,textStatus){},processUserdata:function(userdata,options){},event:{selectRowEvent:false,unselectRowEvent:false,customRowEvents:{},customCellEvents:{}},extend:{initGridMethods:{},beforeRenderGridMethods:{},renderPerColumnMethods:{},renderPerRowMethods:{},afterRenderGridMethods:{}},additionalBeforeRenderGrid:function(parseSuccess,gridData,options){},additionalRenderPerColumn:function(record,rowIndex,colIndex,tdObj,trObj,options){},additionalRenderPerRow:function(record,rowIndex,trObj,options){},additionalAfterRenderGrid:function(parseSuccess,gridData,options){}},gridObjs:{},init:function(gridId,settings){if(!$("#"+gridId).hasClass("bsgrid")){$("#"+gridId).addClass("bsgrid")}var options={settings:$.extend(true,{},$.fn.bsgrid.defaults,settings),gridId:gridId,noPagingationId:gridId+"_no_pagination",pagingOutTabId:gridId+"_pt_outTab",pagingId:gridId+"_pt",sortName:"",sortOrder:"",otherParames:settings.otherParames,totalRows:0,totalPages:0,curPage:1,curPageRowsNum:0,startRow:0,endRow:0};if($("#"+gridId).find("thead").length==0){$("#"+gridId).prepend("<thead></thead>");$("#"+gridId).find("tr:lt("+($("#"+gridId+" tr").length-$("#"+gridId+" tfoot tr").length)+")").appendTo($("#"+gridId+" thead"))}if($("#"+gridId).find("tbody").length==0){$("#"+gridId+" thead").after("<tbody></tbody>")}if($("#"+gridId).find("tfoot").length==0){$("#"+gridId).append('<tfoot style="display: none;"></tfoot>')}options.columnsModel=$.fn.bsgrid.initColumnsModel(options);if(settings.pageSizeForGrid!=undefined){options.settings.pageSizeForGrid=settings.pageSizeForGrid}options.settings.dataType=options.settings.dataType.toLowerCase();if(options.settings.pageSizeSelect){if($.inArray(options.settings.pageSize,options.settings.pageSizeForGrid)==-1){options.settings.pageSizeForGrid.push(options.settings.pageSize)}options.settings.pageSizeForGrid.sort(function(a,b){return a-b})}var gridObj={options:options,getCondition:function(){return $.fn.bsgrid.getPageCondition(options.curPage,options)},getPageCondition:function(curPage){return $.fn.bsgrid.getPageCondition(curPage,options)},page:function(curPage){$.fn.bsgrid.page(curPage,options)},search:function(params){$.fn.bsgrid.search(options,params)},loadGridData:function(dataType,gridData){$.fn.bsgrid.loadGridData(dataType,gridData,options)},loadRowData:function(record,rowIndex,trObj){$.fn.bsgrid.loadRowData(options,record,rowIndex,trObj)},reloadLocalData:function(localData){$.fn.bsgrid.reloadLocalData(localData,options)},getPageSize:function(){return options.settings.pageSize},getTotalRows:function(){return options.totalRows},getTotalPages:function(){return options.totalPages},getCurPage:function(){return options.curPage},getCurPageRowsNum:function(){return options.curPageRowsNum},getStartRow:function(){return options.startRow},getEndRow:function(){return options.endRow},getSortName:function(){return options.sortName},getSortOrder:function(){return options.sortOrder},getRows:function(){return $.fn.bsgrid.getRows(options)},getRow:function(row){return $.fn.bsgrid.getRow(row,options)},getRowCells:function(row){return $.fn.bsgrid.getRowCells(row,options)},getColCells:function(col){return $.fn.bsgrid.getColCells(col,options)},getCell:function(row,col){return $.fn.bsgrid.getCell(row,col,options)},getSelectedRow:function(){return $.fn.bsgrid.getSelectedRow(options)},getSelectedRowIndex:function(){return $.fn.bsgrid.getSelectedRowIndex(options)},selectRow:function(row){return $.fn.bsgrid.selectRow(row,options)},unSelectRow:function(){return $.fn.bsgrid.unSelectRow(options)},getUserdata:function(){return $.fn.bsgrid.getUserdata(options)},getRowRecord:function(rowObj){return $.fn.bsgrid.getRowRecord(rowObj)},getAllRecords:function(){return $.fn.bsgrid.getAllRecords(options)},getRecord:function(row){return $.fn.bsgrid.getRecord(row,options)},getRecordIndexValue:function(record,index){return $.fn.bsgrid.getRecordIndexValue(record,index,options)},getColumnValue:function(row,index){return $.fn.bsgrid.getColumnValue(row,index,options)},getCellRecordValue:function(row,col){return $.fn.bsgrid.getCellRecordValue(row,col,options)},sort:function(obj){$.fn.bsgrid.sort(obj,options)},getGridHeaderObject:function(){return $.fn.bsgrid.getGridHeaderObject(options)},getColumnModel:function(colIndex){return $.fn.bsgrid.getColumnModel(colIndex,options)},appendHeaderSort:function(){$.fn.bsgrid.appendHeaderSort(options)},setGridBlankBody:function(){return $.fn.bsgrid.setGridBlankBody(options)},createPagingOutTab:function(){$.fn.bsgrid.createPagingOutTab(options)},clearRowData:function(rowIndex){$.fn.bsgrid.clearRowData(rowIndex,options)},clearGridBodyData:function(){$.fn.bsgrid.clearGridBodyData(options)},getPagingObj:function(){return $.fn.bsgrid.getPagingObj(options)},refreshPage:function(){$.fn.bsgrid.refreshPage(options)},firstPage:function(){$.fn.bsgrid.firstPage(options)},prevPage:function(){$.fn.bsgrid.prevPage(options)},nextPage:function(){$.fn.bsgrid.nextPage(options)},lastPage:function(){$.fn.bsgrid.lastPage(options)},gotoPage:function(goPage){$.fn.bsgrid.gotoPage(options,goPage)},initPaging:function(){return $.fn.bsgrid.initPaging(options)},setPagingValues:function(){$.fn.bsgrid.setPagingValues(options)}};$.fn.bsgrid.gridObjs[gridId]=gridObj;if(options.settings.pageAll||options.settings.pageSize<1){options.settings.pageAll=true;options.settings.pageSize=0}gridObj.appendHeaderSort();gridObj.createPagingOutTab();if(!options.settings.showPageToolbar){$("#"+options.pagingId).hide();$("#"+options.pagingOutTabId).hide()}if(!options.settings.pageAll){gridObj.pagingObj=gridObj.initPaging();try{var minWidth=$.trim($("#"+options.pagingId).children().width());minWidth=minWidth==""?0:parseInt(minWidth);if(minWidth!=0){$("#"+gridId).css("min-width",minWidth+16);$("#"+options.pagingOutTabId).css("min-width",minWidth+16)}$("#"+options.pagingOutTabId).width($("#"+gridId).width());$(window).resize(function(){$("#"+options.pagingOutTabId).width($("#"+gridId).width())})}catch(e){}}if(options.settings.isProcessLockScreen){$.fn.bsgrid.addLockScreen(options)}try{$.fn.bsgrid.extendInitGrid.initGridExtendOptions(gridId,options)}catch(e){}for(var key in options.settings.extend.initGridMethods){options.settings.extend.initGridMethods[key](gridId,options)}if(options.settings.autoLoad){setTimeout(function(){gridObj.page(1)},10)}else{gridObj.setGridBlankBody()}return gridObj},initColumnsModel:function(options){var columnsModel=[];$.fn.bsgrid.getGridHeaderObject(options).each(function(){var headObj=$(this);var colsProperties=options.settings.colsProperties;var columnModel={};columnModel.sortName="";columnModel.sortOrder="";var sortInfo=$.trim(headObj.attr(colsProperties.sortAttr));if(sortInfo.length!=0){var sortInfoArray=sortInfo.split(",");columnModel.sortName=$.trim(sortInfoArray[0]);columnModel.sortOrder=$.trim(sortInfoArray.length>1?sortInfoArray[1]:"")}columnModel.index=$.trim(headObj.attr(colsProperties.indexAttr));columnModel.render=$.trim(headObj.attr(colsProperties.renderAttr));columnModel.tip=$.trim(headObj.attr(colsProperties.tipAttr));var maxLen=$.trim(headObj.attr(colsProperties.lengthAttr));columnModel.maxLen=maxLen.length!=0?parseInt(maxLen):colsProperties.maxLength;var align=$.trim(headObj.attr(colsProperties.alignAttr));columnModel.align=align==""?colsProperties.align:align;columnModel.hidden=$.trim(headObj.attr(colsProperties.hiddenAttr));columnsModel.push(columnModel)});return columnsModel},getGridObj:function(gridId){var obj=$.fn.bsgrid.gridObjs[gridId];return obj?obj:null},buildData:{gridData:function(type,curPage,data){if(type=="json"||type=="jsonp"){return $.fn.bsgrid.buildJsonData.gridData(curPage,data)}else{if(type=="xml"){return $.fn.bsgrid.buildXmlData.gridData(curPage,data)}}return false}},parseData:{success:function(type,gridData){if(type=="json"||type=="jsonp"){return $.fn.bsgrid.parseJsonData.success(gridData)}else{if(type=="xml"){return $.fn.bsgrid.parseXmlData.success(gridData)}}return false},totalRows:function(type,gridData){if(type=="json"||type=="jsonp"){return $.fn.bsgrid.parseJsonData.totalRows(gridData)}else{if(type=="xml"){return $.fn.bsgrid.parseXmlData.totalRows(gridData)}}return false},curPage:function(type,gridData){if(type=="json"||type=="jsonp"){return $.fn.bsgrid.parseJsonData.curPage(gridData)}else{if(type=="xml"){return $.fn.bsgrid.parseXmlData.curPage(gridData)}}return false},data:function(type,gridData){if(type=="json"||type=="jsonp"){return $.fn.bsgrid.parseJsonData.data(gridData)}else{if(type=="xml"){return $.fn.bsgrid.parseXmlData.data(gridData)}}return false},userdata:function(type,gridData){if(type=="json"||type=="jsonp"){return $.fn.bsgrid.parseJsonData.userdata(gridData)}else{if(type=="xml"){return $.fn.bsgrid.parseXmlData.userdata(gridData)}}return false},getDataLen:function(type,gridData){if(type=="json"||type=="jsonp"||type=="xml"){return $.fn.bsgrid.parseData.data(type,gridData).length}return 0},getRecord:function(type,data,row){if(type=="json"||type=="jsonp"){return $.fn.bsgrid.parseJsonData.getRecord(data,row)}else{if(type=="xml"){return $.fn.bsgrid.parseXmlData.getRecord(data,row)}}return false},getColumnValue:function(type,record,index){if(type=="json"||type=="jsonp"){return $.fn.bsgrid.parseJsonData.getColumnValue(record,index)}else{if(type=="xml"){return $.fn.bsgrid.parseXmlData.getColumnValue(record,index)}}return false}},buildJsonData:{gridData:function(curPage,data){return{success:true,totalRows:data.length,curPage:curPage,data:data}}},parseJsonData:{success:function(json){return json.success},totalRows:function(json){return json.totalRows},curPage:function(json){return json.curPage},data:function(json){return json.data},userdata:function(json){return json.userdata},getRecord:function(data,row){return data[row]},getColumnValue:function(record,index){return record[index]}},buildXmlData:{gridData:function(curPage,data){return'<?xml version="1.0" encoding="UTF-8"?><gridData><success>true</success><totalRows>'+$("<xml>"+data+"</xml>").find("row").length+"</totalRows><curPage>"+curPage+"</curPage><data>"+data+"</data></gridData>"}},parseXmlData:{success:function(xml){return $.trim($(xml).find("gridData success").text())=="true"},totalRows:function(xml){return parseInt($(xml).find("gridData totalRows").text())},curPage:function(xml){return parseInt($(xml).find("gridData curPage").text())},data:function(xml){return $(xml).find("gridData data row")},userdata:function(xml){return $(xml).find("gridData userdata")},getRecord:function(data,row){return data.eq(row)},getColumnValue:function(record,index){return record.find(index).text()}},getPageCondition:function(curPage,options){var params=new StringBuilder();if(options.otherParames==false){}else{if((typeof options.otherParames).toLowerCase()=="string"||options.otherParames instanceof String){params.append("&"+options.otherParames)}else{if(options.otherParames instanceof Array){$.each(options.otherParames,function(i,objVal){params.append("&"+objVal.name+"="+objVal.value)})}else{for(var key in options.otherParames){params.append("&"+key+"="+options.otherParames[key])}}}}var condition=params.length==0?"":params.toString().substring(1);condition+=(condition.length==0?"":"&")+options.settings.requestParamsName.pageSize+"="+options.settings.pageSize+"&"+options.settings.requestParamsName.curPage+"="+curPage+"&"+options.settings.requestParamsName.sortName+"="+options.sortName+"&"+options.settings.requestParamsName.sortOrder+"="+options.sortOrder;return condition},search:function(options,params){if(params!=undefined){options.otherParames=params}else{options.otherParames=false}$.fn.bsgrid.page(1,options)},page:function(curPage,options){if($.trim(curPage)==""||isNaN(curPage)){$.fn.bsgrid.alert($.bsgridLanguage.needInteger);return}var dataType=options.settings.dataType;if(options.settings.localData!=false){if(dataType=="json"||dataType=="jsonp"){$.fn.bsgrid.loadGridData(dataType,$.fn.bsgrid.buildData.gridData(dataType,curPage,options.settings.localData),options)}else{if(dataType=="xml"){$.fn.bsgrid.loadGridData(dataType,"<xml>"+$.fn.bsgrid.buildData.gridData(dataType,curPage,options.settings.localData)+"</xml>",options)}}return}$.ajax({type:options.settings.ajaxType,url:options.settings.url,data:$.fn.bsgrid.getPageCondition(curPage,options),dataType:dataType,beforeSend:function(XMLHttpRequest){if(options.settings.isProcessLockScreen){$.fn.bsgrid.lockScreen(options)}options.settings.beforeSend(options,XMLHttpRequest)},complete:function(XMLHttpRequest,textStatus){options.settings.complete(options,XMLHttpRequest,textStatus);if(options.settings.isProcessLockScreen){$.fn.bsgrid.unlockScreen(options)}},success:function(gridData,textStatus){$.fn.bsgrid.loadGridData(dataType,gridData,options)},error:function(XMLHttpRequest,textStatus,errorThrown){$.fn.bsgrid.alert($.bsgridLanguage.errorForSendOrRequestData)}})},loadGridData:function(dataType,gridData,options){var parseSuccess=$.fn.bsgrid.parseData.success(dataType,gridData);for(var key in options.settings.extend.beforeRenderGridMethods){options.settings.extend.beforeRenderGridMethods[key](parseSuccess,gridData,options)}options.settings.additionalBeforeRenderGrid(parseSuccess,gridData,options);if(parseSuccess){var userdata=$.fn.bsgrid.parseData.userdata(dataType,gridData);$.fn.bsgrid.storeUserdata(userdata,options);options.settings.processUserdata(userdata,options);var totalRows=parseInt($.fn.bsgrid.parseData.totalRows(dataType,gridData));var curPage=parseInt($.fn.bsgrid.parseData.curPage(dataType,gridData));curPage=Math.max(curPage,1);if(options.settings.pageAll){curPage=1;options.settings.pageSize=totalRows;$("#"+options.noPagingationId).html(totalRows)}var pageSize=options.settings.pageSize;var totalPages=parseInt(totalRows/pageSize);totalPages=parseInt((totalRows%pageSize==0)?totalPages:totalPages+1);var curPageRowsNum=$.fn.bsgrid.parseData.getDataLen(dataType,gridData);curPageRowsNum=curPageRowsNum>pageSize?pageSize:curPageRowsNum;curPageRowsNum=(curPage*pageSize<totalRows)?curPageRowsNum:(totalRows-(curPage-1)*pageSize);var startRow=(curPage-1)*pageSize+1;var endRow=startRow+curPageRowsNum-1;startRow=curPageRowsNum<=0?0:startRow;endRow=curPageRowsNum<=0?0:endRow;options.totalRows=totalRows;options.totalPages=totalPages;options.curPage=curPage;options.curPageRowsNum=curPageRowsNum;options.startRow=startRow;options.endRow=endRow;if(!options.settings.pageAll){$.fn.bsgrid.setPagingValues(options)}if(!options.settings.showPageToolbar||(options.settings.displayPagingToolbarOnlyMultiPages&&totalPages<=1)){$("#"+options.pagingId).hide();$("#"+options.pagingOutTabId).hide()}else{$("#"+options.pagingOutTabId).show();$("#"+options.pagingId).show()}var gridRows=$.fn.bsgrid.setGridBlankBody(options);if(curPageRowsNum!=0){var data=$.fn.bsgrid.parseData.data(dataType,gridData);var dataLen=data.length;gridRows.each(function(i){var trObj=$(this);var record=null;if(i<curPageRowsNum&&i<dataLen){record=$.fn.bsgrid.parseData.getRecord(dataType,data,dataLen!=totalRows?i:startRow+i-1)}$.fn.bsgrid.loadRowData(options,record,i,trObj)})}}else{$.fn.bsgrid.alert($.bsgridLanguage.errorForRequestData)}for(var key in options.settings.extend.afterRenderGridMethods){options.settings.extend.afterRenderGridMethods[key](parseSuccess,gridData,options)}options.settings.additionalAfterRenderGrid(parseSuccess,gridData,options)},loadRowData:function(options,record,rowIndex,trObj){if(trObj==undefined){trObj=$.fn.bsgrid.getRow(rowIndex,options)}var columnsModel=options.columnsModel;var dataType=options.settings.dataType;var dataTrim=options.settings.dataTrim;trObj.find("td").each(function(j){var tdObj=$(this);if(record!=null){var index=columnsModel[j].index;var render=columnsModel[j].render;if(render!=""){var render_method=eval(render);var render_html=render_method(record,rowIndex,j,options);tdObj.html(render_html)}else{if(index!=""){var value=$.fn.bsgrid.parseData.getColumnValue(dataType,record,index);value=dataTrim?$.trim(value):(value==null?"":value);if(columnsModel[j].tip=="true"){$.fn.bsgrid.columnTip(tdObj,value,record)}if(options.settings.longLengthAotoSubAndTip){$.fn.bsgrid.longLengthSubAndTip(tdObj,value,columnsModel[j].maxLen,record)}else{tdObj.html(value)}}}}else{tdObj.html(" ")}for(var key in options.settings.extend.renderPerColumnMethods){var renderPerColumn_html=options.settings.extend.renderPerColumnMethods[key](record,rowIndex,j,tdObj,trObj,options);if(renderPerColumn_html!=null&&renderPerColumn_html!=false){tdObj.html(renderPerColumn_html)}}options.settings.additionalRenderPerColumn(record,rowIndex,j,tdObj,trObj,options);for(var key in options.settings.event.customCellEvents){tdObj.bind(key,{record:record,rowIndex:rowIndex,colIndex:j,tdObj:tdObj,trObj:trObj,options:options},function(event){options.settings.event.customCellEvents[key](event.data.record,event.data.rowIndex,event.data.colIndex,event.data.tdObj,event.data.trObj,event.data.options)})}});$.fn.bsgrid.storeRowData(rowIndex,record,options);for(var key in options.settings.extend.renderPerRowMethods){options.settings.extend.renderPerRowMethods[key](record,rowIndex,trObj,options)}options.settings.additionalRenderPerRow(record,rowIndex,trObj,options);for(var key in options.settings.event.customRowEvents){trObj.bind(key,{record:record,rowIndex:rowIndex,trObj:trObj,options:options},function(event){options.settings.event.customRowEvents[key](event.data.record,event.data.rowIndex,event.data.trObj,event.data.options)})}},reloadLocalData:function(localData,options){options.settings.localData=localData;$.fn.bsgrid.page(1,options)},addRowsClickEvent:function(options){$("#"+options.gridId+" tbody").delegate("tr:lt("+options.curPageRowsNum+")","click",function(){var trObj=$(this);if(trObj.hasClass("selected")){$.fn.bsgrid.unSelectRow(options)}else{$.fn.bsgrid.selectRow($.fn.bsgrid.getRows(options).index(trObj),options)}})},getRows:function(options){return $("#"+options.gridId+" tbody tr")},getRow:function(row,options){return $.fn.bsgrid.getRows(options).eq(row)},getRowCells:function(row,options){return $.fn.bsgrid.getRow(row,options).find("td")},getColCells:function(col,options){return $.fn.bsgrid.getRows(options).find("td:nth-child("+(col+1)+")")},getCell:function(row,col,options){return $.fn.bsgrid.getRowCells(row,options).eq(col)},getSelectedRow:function(options){return $.fn.bsgrid.getRows(options).filter(".selected")},getSelectedRowIndex:function(options){return $.fn.bsgrid.getRows(options).index($.fn.bsgrid.getSelectedRow(options))},selectRow:function(row,options){$.fn.bsgrid.unSelectRow(options);var trObj=$.fn.bsgrid.getRow(row,options);trObj.addClass("selected");if(options.settings.rowSelectedColor){trObj.addClass("selected_color")}if(!!options.settings.event.selectRowEvent){options.settings.event.selectRowEvent($.fn.bsgrid.getRowRecord(trObj),row,trObj,options)}},unSelectRow:function(options){var row=$.fn.bsgrid.getSelectedRowIndex(options);if(row!=-1){var trObj=$.fn.bsgrid.getRow(row,options);trObj.removeClass("selected").removeClass("selected_color");if(!!options.settings.event.unselectRowEvent){options.settings.event.unselectRowEvent($.fn.bsgrid.getRowRecord(trObj),row,trObj,options)}}},getUserdata:function(options){$("#"+options.gridId).data("userdata")},storeUserdata:function(userdata,options){$("#"+options.gridId).data("userdata",userdata)},getRowRecord:function(rowObj){var record=rowObj.data("record");return record==undefined?null:record},storeRowData:function(row,record,options){$.fn.bsgrid.getRow(row,options).data("record",record)},getAllRecords:function(options){var records=[];$.fn.bsgrid.getRows(options).each(function(){var record=$.fn.bsgrid.getRowRecord($(this));if(record!=null){records[records.length]=record}});return records},getRecord:function(row,options){return $.fn.bsgrid.getRowRecord($.fn.bsgrid.getRow(row,options))},getRecordIndexValue:function(record,index,options){if(record==null){return""}else{var value=$.fn.bsgrid.parseData.getColumnValue(options.settings.dataType,record,index);return options.settings.dataTrim?$.trim(value):(value==null?"":value)}},getColumnValue:function(row,index,options){var record=$.fn.bsgrid.getRecord(row,options);return $.fn.bsgrid.getRecordIndexValue(record,index,options)},getCellRecordValue:function(row,col,options){var index=$.trim($.fn.bsgrid.getColumnModel(col,options).index);if(index==""){return""}else{return $.fn.bsgrid.getColumnValue(row,index,options)}},sort:function(obj,options){options.sortName="";options.sortOrder="";var aObj=obj.find("a");var field=$(aObj).attr("sortName");var columnsModel=options.columnsModel;$.fn.bsgrid.getGridHeaderObject(options).each(function(i){var sortName=columnsModel[i].sortName;if(sortName!=""){var headObj=$(this);var sortOrder=$.fn.bsgrid.getSortOrder(headObj,options);if(!options.settings.multiSort&&sortName!=field){headObj.find("a").attr("class","sort sort-view")}else{if(sortName==field){if(sortOrder==""){sortOrder="desc"}else{if(sortOrder=="desc"){sortOrder="asc"}else{if(sortOrder=="asc"){sortOrder=""}}}headObj.find("a").attr("class","sort sort-"+(sortOrder==""?"view":sortOrder))}if(sortOrder!=""){options.sortName=($.trim(options.sortName)=="")?sortName:(options.sortName+","+sortName);options.sortOrder=($.trim(options.sortOrder)=="")?sortOrder:(options.sortOrder+","+sortOrder)}}}});$.fn.bsgrid.refreshPage(options)},getSortOrder:function(obj,options){var sortOrder=$.trim(obj.find("a").attr("class"));if(sortOrder=="sort sort-view"){sortOrder=""}else{if(sortOrder=="sort sort-asc"){sortOrder="asc"}else{if(sortOrder=="sort sort-desc"){sortOrder="desc"}else{sortOrder=""}}}return sortOrder},getGridHeaderObject:function(options){return $("#"+options.gridId+" thead tr:last").find("th")},getColumnModel:function(colIndex,options){return options.columnsModel[colIndex]},appendHeaderSort:function(options){var columnsModel=options.columnsModel;$.fn.bsgrid.getGridHeaderObject(options).each(function(i){if(columnsModel[i].sortName!=""){var sortName=columnsModel[i].sortName;var sortOrder=columnsModel[i].sortOrder;var sortHtml='<a href="javascript:void(0);" sortName="'+sortName+'" class="sort ';if(sortOrder!=""&&(sortOrder=="desc"||sortOrder=="asc")){options.sortName=($.trim(options.sortName)=="")?sortName:(options.sortName+","+sortName);options.sortOrder=($.trim(options.sortOrder)=="")?sortOrder:(options.sortOrder+","+sortOrder);sortHtml+="sort-"+sortOrder}else{sortHtml+="sort-view"}sortHtml+='"> </a>';$(this).append(sortHtml).find(".sort").click(function(){$.fn.bsgrid.sort($(this).parent("th"),options)})}})},setGridBlankBody:function(options){var gridBody=$("#"+options.gridId+" tbody");gridBody.html("");var header=$.fn.bsgrid.getGridHeaderObject(options);var columnsModel=options.columnsModel;for(var hi=0;hi<header.length;hi++){if(columnsModel[hi].hidden=="true"){header.eq(hi).css("display","none")}}var rowSb="";if(options.settings.pageSize>0){var trSb=new StringBuilder();trSb.append("<tr>");for(var hi=0;hi<header.length;hi++){trSb.append('<td style="text-align: '+columnsModel[hi].align+";");if(columnsModel[hi].hidden=="true"){trSb.append(" display: none;")}trSb.append('"');if(!options.settings.lineWrap){trSb.append(' class="lineNoWrap"')}else{trSb.append(' class="lineWrap"')}trSb.append("> </td>")}trSb.append("</tr>");rowSb=trSb.toString()}var curPageRowsNum=options.settings.pageSize;if(!options.settings.displayBlankRows){curPageRowsNum=options.endRow-options.startRow+1;curPageRowsNum=options.endRow>0?curPageRowsNum:0}var rowsSb=new StringBuilder();if(curPageRowsNum==0){rowsSb.append('<tr><td colspan="'+header.length+'">'+$.bsgridLanguage.noDataToDisplay+"</td></tr>")}else{for(var pi=0;pi<curPageRowsNum;pi++){rowsSb.append(rowSb)}}gridBody.html(rowsSb.toString());var gridRows=$.fn.bsgrid.getRows(options);if(curPageRowsNum!=0){if(options.settings.stripeRows){gridRows.filter(":even").addClass("even_index_row")}if(options.settings.rowHoverColor){gridRows.hover(function(){$(this).addClass("row_hover")},function(){$(this).removeClass("row_hover")})}}$.fn.bsgrid.addRowsClickEvent(options);return gridRows},createPagingOutTab:function(options){var pagingOutTabSb=new StringBuilder();pagingOutTabSb.append('<table id="'+options.pagingOutTabId+'" class="bsgridPagingOutTab" style="display: none;"><tr><td align="'+options.settings.pagingToolbarAlign+'">');if(options.settings.pageAll){pagingOutTabSb.append($.bsgridLanguage.noPagingation(options.noPagingationId)+" ")}pagingOutTabSb.append("</td></tr></table>");$("#"+options.gridId).after(pagingOutTabSb.toString())},clearRowData:function(rowIndex,options){$.fn.bsgrid.getRowCells(rowIndex,options).html(" ");$.fn.bsgrid.storeRowData(rowIndex,null,options)},clearGridBodyData:function(options){$.fn.bsgrid.getRows(options).each(function(i){$(this).find("td").html(" ");$.fn.bsgrid.storeRowData(i,null,options)})},addLockScreen:function(options){if($(".bsgrid.lockscreen").length==0){var lockScreenHtml=new StringBuilder();lockScreenHtml.append('<div class="bsgrid lockscreen" times="0">');lockScreenHtml.append("</div>");lockScreenHtml.append('<div class="bsgrid loading_div">');lockScreenHtml.append('<table><tr><td><center><div class="bsgrid loading"><span>  </span> '+$.bsgridLanguage.loadingDataMessage+" <center></div></td></tr></table>");lockScreenHtml.append("</div>");$("body").append(lockScreenHtml.toString())}},lockScreen:function(options){$(".bsgrid.lockscreen").attr("times",parseInt($(".bsgrid.lockscreen").attr("times"))+1);if($(".bsgrid.lockscreen").css("display")=="none"){$(".bsgrid.lockscreen").show();$(".bsgrid.loading_div").show()}},unlockScreen:function(options){$(".bsgrid.lockscreen").attr("times",parseInt($(".bsgrid.lockscreen").attr("times"))-1);if($(".bsgrid.lockscreen").attr("times")=="0"){setTimeout(function(){$(".bsgrid.lockscreen").hide();$(".bsgrid.loading_div").hide()},50)}},columnTip:function(tdObj,value,record){tdObj.attr("title",value)},alert:function(msg){try{$.bsgrid.alert(msg)}catch(e){alert(msg)}},longLengthSubAndTip:function(tdObj,value,maxLen,record){var tip=false;if(value.length>maxLen){try{if(value.indexOf("<")<0||value.indexOf(">")<2||$(value).text().length==0){tip=true}}catch(e){tip=true}}if(tip){tdObj.html(value.substring(0,maxLen-3)+"...");$.fn.bsgrid.columnTip(tdObj,value,record)}else{tdObj.html(value)}},getPagingObj:function(options){return $.fn.bsgrid.getGridObj(options.gridId).pagingObj},refreshPage:function(options){if(!options.settings.pageAll){$.fn.bsgrid.getPagingObj(options).refreshPage()}else{$.fn.bsgrid.page(1,options)}},firstPage:function(options){$.fn.bsgrid.getPagingObj(options).firstPage()},prevPage:function(options){$.fn.bsgrid.getPagingObj(options).prevPage()},nextPage:function(options){$.fn.bsgrid.getPagingObj(options).nextPage()},lastPage:function(options){$.fn.bsgrid.getPagingObj(options).lastPage()},gotoPage:function(options,goPage){$.fn.bsgrid.getPagingObj(options).gotoPage(goPage)},initPaging:function(options){$("#"+options.pagingOutTabId+" td").attr("id",options.pagingId);return $.fn.bsgrid_paging.init(options.pagingId,{gridId:options.gridId,pageSize:options.settings.pageSize,pageSizeSelect:options.settings.pageSizeSelect,pageSizeForGrid:options.settings.pageSizeForGrid,pageIncorrectTurnAlert:options.settings.pageIncorrectTurnAlert,pagingLittleToolbar:options.settings.pagingLittleToolbar,pagingBtnClass:options.settings.pagingBtnClass})},setPagingValues:function(options){$.fn.bsgrid.getPagingObj(options).setPagingValues(options.curPage,options.totalRows)}}})(jQuery);
|
|
(function($){$.fn.bsgrid.defaults.extend.settings={supportGridEdit:false,supportGridEditTriggerEvent:"rowClick",supportColumnMove:false,searchConditionsContainerId:"",fixedGridHeader:false,fixedGridHeight:"320px",gridEditConfigs:{text:{build:function(edit,value,record,rowIndex,colIndex,tdObj,trObj,options){return value+'<input class="bsgrid_editgrid_edit" type="'+edit+'" value="'+value+'"/>'},val:function(formObj){return formObj.val()}},checkbox:{build:function(edit,value,record,rowIndex,colIndex,tdObj,trObj,options){return value+'<input class="bsgrid_editgrid_checkbox" type="'+edit+'" value="'+value+'"/>'},val:function(formObj){return formObj.val()}},textarea:{build:function(edit,value,record,rowIndex,colIndex,tdObj,trObj,options){return value+'<textarea class="bsgrid_editgrid_edit">'+value+"</textarea>"},val:function(formObj){return formObj.val()}}}};$.fn.bsgrid.defaults.extend.settings.gridEditConfigs.hidden=$.fn.bsgrid.defaults.extend.settings.gridEditConfigs.text;$.fn.bsgrid.defaults.extend.settings.gridEditConfigs.password=$.fn.bsgrid.defaults.extend.settings.gridEditConfigs.text;$.fn.bsgrid.defaults.extend.settings.gridEditConfigs.radio=$.fn.bsgrid.defaults.extend.settings.gridEditConfigs.text;$.fn.bsgrid.defaults.extend.settings.gridEditConfigs.button=$.fn.bsgrid.defaults.extend.settings.gridEditConfigs.text;$.extend(true,$.fn.bsgrid.defaults.colsProperties,{lineNumberAttr:"w_num",checkAttr:"w_check",editAttr:"w_edit",aggAttr:"w_agg"});$.fn.bsgrid.defaults.event.customCellEditEvents={};$.fn.bsgrid.extendInitGrid={};$.fn.bsgrid.extendBeforeRenderGrid={};$.fn.bsgrid.extendRenderPerRow={};$.fn.bsgrid.extendRenderPerColumn={};$.fn.bsgrid.extendAfterRenderGrid={};$.fn.bsgrid.extendOtherMethods={};$.fn.bsgrid.extendInitGrid.initGridExtendOptions=function(gridId,options){var columnsModel=options.columnsModel;var colsProperties=options.settings.colsProperties;$.fn.bsgrid.getGridHeaderObject(options).each(function(i){columnsModel[i].lineNumber=$.trim($(this).attr(colsProperties.lineNumberAttr));columnsModel[i].check=$.trim($(this).attr(colsProperties.checkAttr));columnsModel[i].edit=$.trim($(this).attr(colsProperties.editAttr))});if($("#"+options.gridId+" tfoot tr td["+colsProperties.aggAttr+"!='']").length!=0){$("#"+options.gridId+" tfoot tr td").each(function(i){columnsModel[i].aggName="";columnsModel[i].aggIndex="";var aggInfo=$.trim($(this).attr(colsProperties.aggAttr));if(aggInfo.length!=0){var aggInfoArray=aggInfo.split(",");columnsModel[i].aggName=aggInfoArray[0].toLocaleLowerCase();columnsModel[i].aggIndex=aggInfoArray.length>1?aggInfoArray[1]:""}})}if($.fn.bsgrid.getGridHeaderObject(options).filter("["+colsProperties.lineNumberAttr+"$='line']").length!=0){options.settings.extend.afterRenderGridMethods.renderLineNumber=$.fn.bsgrid.extendAfterRenderGrid.renderLineNumber}if($.fn.bsgrid.getGridHeaderObject(options).filter("["+colsProperties.checkAttr+"='true']").length!=0){options.settings.extend.initGridMethods.initGridCheck=$.fn.bsgrid.extendInitGrid.initGridCheck;options.settings.extend.renderPerColumnMethods.renderCheck=$.fn.bsgrid.extendRenderPerColumn.renderCheck;options.settings.extend.afterRenderGridMethods.addCheckChangedEvent=$.fn.bsgrid.extendAfterRenderGrid.addCheckChangedEvent}if(options.settings.extend.settings.supportGridEdit){options.settings.extend.renderPerColumnMethods.renderForm=$.fn.bsgrid.extendRenderPerColumn.renderForm;options.settings.extend.afterRenderGridMethods.addGridEditEvent=$.fn.bsgrid.extendAfterRenderGrid.addGridEditEvent;options.settings.extend.afterRenderGridMethods.setOptionsFirstRowClone=$.fn.bsgrid.extendAfterRenderGrid.setOptionsFirstRowClone;var gridObj=$.fn.bsgrid.getGridObj(gridId);gridObj.activeGridEditMode=function(){return $.fn.bsgrid.defaults.extend.activeGridEditMode(options)};gridObj.getChangedRowsIndexs=function(){return $.fn.bsgrid.defaults.extend.getChangedRowsIndexs(options)};gridObj.getChangedRowsOldRecords=function(){return $.fn.bsgrid.defaults.extend.getChangedRowsOldRecords(options)};gridObj.getRowsChangedColumnsValue=function(){return $.fn.bsgrid.defaults.extend.getRowsChangedColumnsValue(options)};gridObj.deleteRow=function(row){$.fn.bsgrid.defaults.extend.deleteRow(row,options)};gridObj.addNewEditRow=function(){$.fn.bsgrid.defaults.extend.addNewEditRow(options)}}if(options.settings.extend.settings.supportColumnMove){options.settings.extend.initGridMethods.initColumnMove=$.fn.bsgrid.extendInitGrid.initColumnMove}if(options.settings.extend.settings.fixedGridHeader){options.settings.extend.initGridMethods.initFixedHeader=$.fn.bsgrid.extendOtherMethods.initFixedHeader;options.settings.extend.afterRenderGridMethods.fixedHeader=function(parseSuccess,gridData,options){$.fn.bsgrid.extendOtherMethods.fixedHeader(false,options)}}if($.trim(options.settings.extend.settings.searchConditionsContainerId)!=""){options.settings.extend.initGridMethods.initSearchConditions=$.fn.bsgrid.extendInitGrid.initSearchConditions}if($("#"+options.gridId+" tfoot td["+colsProperties.aggAttr+"!='']").length!=0){options.settings.extend.afterRenderGridMethods.aggregation=$.fn.bsgrid.extendAfterRenderGrid.aggregation}};$.fn.bsgrid.extendInitGrid.initGridCheck=function(gridId,options){$.fn.bsgrid.getGridHeaderObject(options).each(function(hi){if(options.columnsModel[hi].check=="true"){if($.trim($(this).html())==""){$(this).html('<input class="bsgrid_editgrid_check" type="checkbox"/>')}$(this).find("input[type=checkbox]").change(function(){var checked=$.bsgrid.adaptAttrOrProp($(this),"checked")?true:false;$.bsgrid.adaptAttrOrProp($.fn.bsgrid.getRows(options).find("td:nth-child("+(hi+1)+")>input[type=checkbox]"),"checked",checked)})}});var gridObj=$.fn.bsgrid.getGridObj(gridId);gridObj.getCheckedRowsIndexs=function(){return $.fn.bsgrid.defaults.extend.getCheckedRowsIndexs(options)};gridObj.getCheckedRowsRecords=function(){return $.fn.bsgrid.defaults.extend.getCheckedRowsRecords(options)};gridObj.getCheckedValues=function(index){return $.fn.bsgrid.defaults.extend.getCheckedValues(index,options)}};$.fn.bsgrid.extendInitGrid.initSearchConditions=function(gridId,options){var conditionsHtml=new StringBuilder();conditionsHtml.append('<select class="bsgrid_conditions_select">');var params={};$.fn.bsgrid.getGridHeaderObject(options).each(function(i){var index=options.columnsModel[i].index;var text=$.trim($(this).text());if(index!=""&&text!=""&&$.trim(params[index])==""){params[index]=text}});for(var key in params){conditionsHtml.append('<option value="'+key+'">'+params[key]+"</option>")}conditionsHtml.append("</select>");conditionsHtml.append(" ");conditionsHtml.append('<input type="text" class="bsgrid_conditions_input" />');$("#"+options.settings.extend.settings.searchConditionsContainerId).html(conditionsHtml.toString());$("#"+options.settings.extend.settings.searchConditionsContainerId+" select.bsgrid_conditions_select").change(function(){$(this).next("input.bsgrid_conditions_input").attr("name",$(this).val())}).trigger("change")};$.fn.bsgrid.extendInitGrid.initColumnMove=function(gridId,options){if($("#"+options.gridId+" thead tr").length!=1){return}$("#"+options.gridId).css({"table-layout":"fixed"});var headObj=$.fn.bsgrid.getGridHeaderObject(options);var headLen=headObj.length;headObj.each(function(i){var obj=this;$(obj).bind("selectstart",function(){return false});$(obj).css("-moz-user-select","none");$(obj).mousedown(function(){bindDownData(obj,i,headLen)});$(obj).mousemove(function(e){e=e||event;var left=$(obj).offset().left;var nObj=0,nLeft=0;if(i!=headLen-1){nObj=$(obj).next();nLeft=nObj.offset().left}var mObj=obj;if(i!=headLen-1&&e.clientX-nLeft>-10){mObj=nObj}if((i!=0&&e.clientX-left<10)||(i!=headLen-1&&e.clientX-nLeft>-10)){$(obj).css({cursor:"e-resize"});if($.trim($(obj).data("ex_mousedown"))!="mousedown"){return}var mWidth=$(mObj).width();var newMWidth=mWidth-e.clientX+$(mObj).offset().left;var preMWidth=$(mObj).prev().width();var preNewMWidth=preMWidth+e.clientX-$(mObj).offset().left;if(parseInt(newMWidth)>19&&parseInt(preNewMWidth)>19){$(mObj).width(newMWidth).prev().width(preNewMWidth)}}else{$(mObj).css({cursor:"default"});releaseDownData(obj,i,headLen)}});$(obj).mouseup(function(){releaseDownData(obj,i,headLen)});$(obj).mouseout(function(e){e=e||event;var objOffect=$(obj).offset();if(objOffect.top>e.clientY||objOffect.top+$(obj).height()<e.clientY){releaseDownData(obj,i,headLen)}});function bindDownData(obj,i,headLen){if(i!=0){$(obj).prev().data("ex_mousedown","mousedown")}$(obj).data("ex_mousedown","mousedown");if(i!=headLen-1){$(obj).next().data("ex_mousedown","mousedown")}}function releaseDownData(obj,i,headLen){if(i!=0){$(obj).prev().data("ex_mousedown","")}$(obj).data("ex_mousedown","");if(i!=headLen-1){$(obj).next().data("ex_mousedown","")}}})};$.fn.bsgrid.extendRenderPerColumn.renderCheck=function(record,rowIndex,colIndex,tdObj,trObj,options){var columnModel=options.columnsModel[colIndex];if(columnModel.check=="true"){var value=$.fn.bsgrid.getRecordIndexValue(record,columnModel.index,options);return'<input class="bsgrid_editgrid_check" type="checkbox" value="'+value+'"/>'}return false};$.fn.bsgrid.extendRenderPerColumn.renderForm=function(record,rowIndex,colIndex,tdObj,trObj,options){var columnModel=options.columnsModel[colIndex];var edit=columnModel.edit;var value=$.fn.bsgrid.getRecordIndexValue(record,columnModel.index,options);var tdHtml=" ";if(edit in options.settings.extend.settings.gridEditConfigs){tdHtml=options.settings.extend.settings.gridEditConfigs[edit].build(edit,value,record,rowIndex,colIndex,tdObj,trObj,options)}else{return false}tdObj.html(tdHtml);tdObj.find(":input").addClass("bsgrid_editgrid_hidden");for(var key in options.settings.event.customCellEditEvents){tdObj.find(":input").each(function(){var formObj=$(this);formObj.bind(key,{formObj:formObj,record:record,rowIndex:rowIndex,colIndex:colIndex,tdObj:tdObj,trObj:trObj,options:options},function(event){options.settings.event.customCellEditEvents[key](event.data.formObj,event.data.record,event.data.rowIndex,event.data.colIndex,event.data.tdObj,event.data.trObj,event.data.options)})})}return false};$.fn.bsgrid.extendAfterRenderGrid.renderLineNumber=function(parseSuccess,gridData,options){$.fn.bsgrid.getGridHeaderObject(options).each(function(i){var num=options.columnsModel[i].lineNumber;if(num=="line"||num=="total_line"){$.fn.bsgrid.getRows(options).find("td:nth-child("+(i+1)+")").each(function(li){$(this).html((num=="line")?(li+1):(li+options.startRow))})}})};$.fn.bsgrid.extendAfterRenderGrid.addCheckChangedEvent=function(parseSuccess,gridData,options){$.fn.bsgrid.getGridHeaderObject(options).each(function(hi){if(options.columnsModel[hi].check=="true"){var checkboxObj=$(this).find("input[type=checkbox]");var checkboxObjs=$.fn.bsgrid.getRows(options).find("td:nth-child("+(hi+1)+")>input[type=checkbox]");checkboxObjs.change(function(){var allCheckboxObjs=$.fn.bsgrid.getRows(options).find("td:nth-child("+(hi+1)+")>input[type=checkbox]");var checked=$.bsgrid.adaptAttrOrProp(checkboxObj,"checked")?true:false;if(!checked&&allCheckboxObjs.filter(":checked").length==allCheckboxObjs.length){$.bsgrid.adaptAttrOrProp(checkboxObj,"checked",true)}else{if(checked&&allCheckboxObjs.filter(":checked").length!=allCheckboxObjs.length){$.bsgrid.adaptAttrOrProp(checkboxObj,"checked",false)}}})}})};$.fn.bsgrid.extendAfterRenderGrid.addGridEditEvent=function(parseSuccess,gridData,options){var gridObj=$.fn.bsgrid.getGridObj(options.gridId);$.fn.bsgrid.getRows(options).each(function(){var columnsModel=options.columnsModel;$(this).find("td").each(function(ci){if(columnsModel[ci].edit!=""){$(this).find(":input").change(function(){var rowObj=$(this).parent("td").parent("tr");var isNew=$.trim(rowObj.data("ex_new"));var value=gridObj.getRecordIndexValue(gridObj.getRowRecord(rowObj),columnsModel[ci].index);value=(isNew=="true"?"":value);if($.trim($(this).val())!=value){$(this).addClass("bsgrid_editgrid_change")}else{$(this).removeClass("bsgrid_editgrid_change")}rowObj.data("ex_change",rowObj.find(".bsgrid_editgrid_change").length)})}});if(options.settings.extend.settings.supportGridEditTriggerEvent==""){$(this).find(".bsgrid_editgrid_hidden").each(function(){showCellEdit(this)})}else{if(options.settings.extend.settings.supportGridEditTriggerEvent=="rowClick"){$(this).click(function(){$(this).find(".bsgrid_editgrid_hidden").each(function(){showCellEdit(this)})})}else{if(options.settings.extend.settings.supportGridEditTriggerEvent=="rowDoubleClick"){$(this).dblclick(function(){$(this).find(".bsgrid_editgrid_hidden").each(function(){showCellEdit(this)})})}else{if(options.settings.extend.settings.supportGridEditTriggerEvent=="cellClick"){$(this).find(".bsgrid_editgrid_hidden").each(function(){var formObj=this;$(formObj).parent("td").click(function(){showCellEdit(formObj)})})}else{if(options.settings.extend.settings.supportGridEditTriggerEvent=="cellDoubleClick"){$(this).find(".bsgrid_editgrid_hidden").each(function(){var formObj=this;$(formObj).parent("td").dblclick(function(){showCellEdit(formObj)})})}}}}}});function showCellEdit(formObj){var cloneObj=$(formObj).removeClass("bsgrid_editgrid_hidden").clone(true);$(formObj).parent("td").html(cloneObj)}};$.fn.bsgrid.extendAfterRenderGrid.aggregation=function(parseSuccess,gridData,options){var gridObj=$.fn.bsgrid.getGridObj(options.gridId);var columnsModel=options.columnsModel;$("#"+options.gridId+" tfoot tr td["+options.settings.colsProperties.aggAttr+"!='']").each(function(i){if(columnsModel[i].aggName!=""){var aggName=columnsModel[i].aggName;var val=null;if(aggName=="count"){val=options.curPageRowsNum}else{if(aggName=="countnotnone"||aggName=="sum"||aggName=="avg"||aggName=="max"||aggName=="min"||aggName=="concat"){if(aggName=="countnotnone"){val=0}var valHtml=new StringBuilder();$.fn.bsgrid.getRows(options).filter(":lt("+options.curPageRowsNum+")").each(function(ri){var rval=gridObj.getColumnValue(ri,columnsModel[i].aggIndex);if(rval==""){}else{if(aggName=="countnotnone"){val=(val==null?0:val)+1}else{if(aggName=="sum"||aggName=="avg"){if(!isNaN(rval)){val=(val==null?0:val)+parseFloat(rval)}}else{if(aggName=="max"||aggName=="min"){if(!isNaN(rval)&&(val==null||(aggName=="max"&&parseFloat(rval)>val)||(aggName=="min"&&parseFloat(rval)<val))){val=parseFloat(rval)}}else{if(aggName=="concat"){valHtml.append(rval)}}}}}});if(aggName=="avg"&&val!=null){val=val/options.curPageRowsNum}else{if(aggName=="concat"){val=valHtml.toString()}}}else{if(aggName=="custom"){val=eval(columnsModel[i].aggIndex)(gridObj,options)}}}val=val==null?"":val;$(this).html(val)}})};$.fn.bsgrid.extendAfterRenderGrid.setOptionsFirstRowClone=function(parseSuccess,gridData,options){options.firstRowClone=$.fn.bsgrid.getRow(0,options).clone(true)};$.fn.bsgrid.defaults.extend.getCheckedRowsIndexs=function(options){var rowIndexs=[];$.fn.bsgrid.getRows(options).each(function(i){if($(this).find("td>input:checked").length==1){rowIndexs[rowIndexs.length]=i}});return rowIndexs};$.fn.bsgrid.defaults.extend.getCheckedRowsRecords=function(options){var records=[];$.each($.fn.bsgrid.defaults.extend.getCheckedRowsIndexs(options),function(i,rowIndex){records[records.length]=$.fn.bsgrid.getRecord(rowIndex,options)});return records};$.fn.bsgrid.defaults.extend.getCheckedValues=function(index,options){var values=[];$.each($.fn.bsgrid.defaults.extend.getCheckedRowsRecords(options),function(i,record){values[values.length]=$.fn.bsgrid.getRecordIndexValue(record,index,options)});return values};$.fn.bsgrid.defaults.extend.activeGridEditMode=function(options){if(!options.settings.extend.settings.supportGridEdit){return}$.fn.bsgrid.getRows(options).find("td .bsgrid_editgrid_hidden").each(function(){var cloneObj=$(this).removeClass("bsgrid_editgrid_hidden").clone(true);$(this).parent("td").html(cloneObj)})};$.fn.bsgrid.defaults.extend.getChangedRowsIndexs=function(options){var rowIndexs=[];$.fn.bsgrid.getRows(options).each(function(i){var cellChangedNumStr=$.trim($(this).data("ex_change"));if(!isNaN(cellChangedNumStr)&&parseInt(cellChangedNumStr)>0){rowIndexs[rowIndexs.length]=i}});return rowIndexs};$.fn.bsgrid.defaults.extend.getChangedRowsOldRecords=function(options){var records=[];$.each($.fn.bsgrid.defaults.extend.getChangedRowsIndexs(options),function(i,rowIndex){records[records.length]=$.fn.bsgrid.getRecord(rowIndex,options)});return records};$.fn.bsgrid.defaults.extend.getRowsChangedColumnsValue=function(options){var values={};$.each($.fn.bsgrid.defaults.extend.getChangedRowsIndexs(options),function(i,rowIndex){values["row_"+rowIndex]={};$.fn.bsgrid.getRows(options).filter(":eq("+rowIndex+")").find("td").each(function(ci){if($(this).find(".bsgrid_editgrid_change").length>0){values["row_"+rowIndex][options.columnsModel[ci].index]=options.settings.extend.settings.gridEditConfigs[options.columnsModel[ci].edit].val($(this).find(".bsgrid_editgrid_change"))}})});return values};$.fn.bsgrid.defaults.extend.deleteRow=function(row,options){$.fn.bsgrid.getRow(row,options).remove()};$.fn.bsgrid.defaults.extend.addNewEditRow=function(options){var gridObj=$.fn.bsgrid.getGridObj(options.gridId);$("#"+options.gridId+" tbody").prepend(options.firstRowClone.clone(true));gridObj.getRowCells(0).each(function(colIndex){var columnModel=options.columnsModel[colIndex];if(columnModel.render!=""){var render_method=eval(columnModel.render);var render_html=render_method(null,0,colIndex,options);$(this).html(render_html)}else{if(columnModel.edit!="textarea"){$(this).children().val("")}else{$(this).children().text("")}$(this).html($(this).children().removeClass("bsgrid_editgrid_change").clone(true)).removeAttr("title")}});gridObj.getRow(0).data("record",null).data("ex_new","true")};$.fn.bsgrid.extendOtherMethods.fixedHeader=function(iFirst,options){var gridObj=$("#"+options.gridId);var gridFixedDivObj=$("#"+options.gridId+"_fixedDiv");if($.trim(gridFixedDivObj.data("ex_fixedGridLock"))=="lock"){return}gridFixedDivObj.data("ex_fixedGridLock","lock");var headTrNum=$("#"+options.gridId+" thead tr").length;if(!iFirst){headTrNum=headTrNum/2;$("#"+options.gridId+" thead tr:lt("+headTrNum+")").remove()}var fixedGridHeight=getSize(options.settings.extend.settings.fixedGridHeight);if(fixedGridHeight<gridObj.height()){gridFixedDivObj.height(fixedGridHeight).animate({scrollTop:"0px"},0);gridObj.width(gridFixedDivObj.width()-18)}else{gridFixedDivObj.height(gridObj.height());gridObj.width(gridFixedDivObj.width()-1)}$("#"+options.gridId+" thead tr:lt("+headTrNum+")").clone(true).prependTo("#"+options.gridId+" thead");$("#"+options.gridId+" thead tr:lt("+headTrNum+")").css({"z-index":10,position:"fixed"}).width($("#"+options.gridId+" thead tr:last").width());$("#"+options.gridId+" thead tr:lt("+headTrNum+")").each(function(i){var position=$("#"+options.gridId+" thead tr:eq("+(headTrNum+i)+")").position();$(this).css({top:position.top-getSize($(this).find("th").css("border-top-width")),left:position.left})});$("#"+options.gridId+" thead tr:gt("+(headTrNum-1)+")").each(function(ri){$(this).find("th").each(function(i){var thObj=$(this);$("#"+options.gridId+" thead tr:eq("+ri+") th:eq("+i+")").height(thObj.height()+((ri==headTrNum-1)?2:1)*getSize(thObj.css("border-top-width"))).width(thObj.width()+getSize(thObj.css("border-left-width")))})});gridFixedDivObj.data("ex_fixedGridLock","");function getSize(sizeStr){sizeStr=$.trim(sizeStr).toLowerCase().replace("px","");var sizeNum=parseFloat(sizeStr);return isNaN(sizeNum)?0:sizeNum}};$.fn.bsgrid.extendOtherMethods.initFixedHeader=function(gridId,options){$("#"+gridId).wrap('<div id="'+gridId+'_fixedDiv"></div>');$("#"+gridId+"_fixedDiv").data("ex_fixedGridLock","").css({padding:0,"border-width":0,width:"98%","overflow-y":"auto","margin-bottom":"-1px"});$("#"+gridId).css({width:"auto"});$("#"+gridId+"_pt_outTab").css({"border-top-width":"1px"});$.fn.bsgrid.extendOtherMethods.fixedHeader(true,options);$(window).resize(function(){$.fn.bsgrid.extendOtherMethods.fixedHeader(false,options)})}})(jQuery);
|
|
(function(a){a.bsgrid_export={defaults:{url:"",exportFileName:"export",colsProperties:{width:100,align:"center",exportAttr:"w_export",indexAttr:"w_index",widthAttr:"width",alignAttr:"w_align"},colWidthPercentmultiplier:14,requestParamsName:{exportFileName:"exportFileName",colNames:"dataNames",colIndexs:"dataIndexs",colWidths:"dataLengths",colAligns:"dataAligns"}},doExport:function(h,o,d){if(o==undefined){o={}}var c={};if(d==undefined){d={}}a.extend(true,c,a.bsgrid_export.defaults,d);var n="",g="",m="",j="";for(var f=0;f<h.length;f++){if(a.trim(h.eq(f).attr(c.colsProperties.exportAttr))!="false"){n=n+","+a.trim(h.eq(f).text());g=g+","+a.trim(h.eq(f).attr(c.colsProperties.indexAttr));var l=a.trim(h.eq(f).attr(c.colsProperties.widthAttr)).toLocaleLowerCase();var e=c.colsProperties.width;if(isNaN(l)){if(l.endWith("px")){e=parseInt(l.replace("px",""))}else{if(l.endWith("%")){l=l.replace("%","");if(!isNaN(l)){e=c.colWidthPercentmultiplier*parseInt(l)}}}}m=m+","+e;var k=a.trim(h.eq(f).attr(c.colsProperties.alignAttr));if(k==""){k=c.colsProperties.align}j=j+","+k}}var b;if((typeof o).toLowerCase()=="string"||o instanceof String){b=(o.startWith("&")?o.substring(1):o)}else{b=a.bsgrid.param(o,true)}document.location.href=c.url+(c.url.indexOf("?")<0?"?":"&")+c.requestParamsName.exportFileName+"="+encodeURIComponent(encodeURIComponent(c.exportFileName))+"&"+c.requestParamsName.colNames+"="+encodeURIComponent(encodeURIComponent(n.substring(1)))+"&"+c.requestParamsName.colIndexs+"="+g.substring(1)+"&"+c.requestParamsName.colWidths+"="+m.substring(1)+"&"+c.requestParamsName.colAligns+"="+j.substring(1)+(b.length==0?"":("&"+b))}}})(jQuery);
|