All Downloads are FREE. Search and download functionalities are using the official Maven repository.

public.component.assets.custom.jquery.loyGrid.js Maven / Gradle / Ivy

There is a newer version: 3.0.1.11
Show newest version
/*
 * Copyright   Loy Fu. 付厚俊
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
function pickDate(cellvalue, options, cell) {
	setTimeout(function() {
		$(cell).find('input[type=text]').datepicker({
			format : 'yyyy-mm-dd',
			autoclose : true,
		    language: 'zh-CN'
		});
	}, 0);
}

function  getTableHtml(tableId,removeCols){
	if(!removeCols){
		removeCols = [0,1,2];
	}
	var $table = $('#'+tableId);
	var headerHtml = [""];
	var $htable = $('.ui-jqgrid-htable',$("#gbox_"+tableId));
	var $headerTable = $('th',$htable).each(function(index){
		if($.inArray(index, removeCols) == -1){
			headerHtml.push(""+$(this).text()+"");
		}
	});
	headerHtml.push("");
	var html =  $table.html();
	var $newHtml  = $(html);
	$('tr',$table).each(function(){
		headerHtml.push("");
		$(this).find('td').each(function(index){
			if($.inArray(index, removeCols)==-1){
				var text = $(this).text();
				headerHtml.push(''+text+'');
			}
		});
		headerHtml.push("");
	});
	html = ""+headerHtml.join("")+"
"; return html; } function searchBoxHideShown($container,grid){ $('#search_box',$container).on('shown.ace.widget', function(e) { $('.chosen-container',$('#search_box',$container)).each(function() { var $this = $(this); $this.css({'width': $this.parent().width()}); }); var searchConditionHeight = $('.widget-body',$('#search_box',$container)).height(); grid.setGridHeight(getGridDefaultHeight()-searchConditionHeight); }); $('#search_box',$container).on('hide.ace.widget', function(e) { var searchConditionHeight = $('.widget-body',$('#search_box',$container)).height(); grid.setGridHeight(getGridDefaultHeight()); }); } function exportExcel(url,tableId,removeCols){ var html = getTableHtml(tableId,removeCols); var $exportForm = $('#exportForm'); if($exportForm.length == 0){ var form = ""; $exportForm = $(form); $('body').append($exportForm); }else{ exportForm.action = url; $('input[name="html"]',$exportForm).val(html); } exportForm.submit(); } function getFitGridWidth(w){ // var v = window.screen.width; // if(v<1024){ // if(w){ // return w; // } // return v; // } return $(".page-content").width(); } function errorTextFormat (data) { if(data.status == 401){ top.location.href ="login"; return; } if(data.status == 403){ return [false,$.i18n.prop('no_permission')]; } return [false,data.statusText]; } function getFormatoptions(baseUrl,accessCodePrefix){ var formatoptions = { keys:true, editformbutton:hasPermission(accessCodePrefix,"update"), editbutton:hasPermission(accessCodePrefix,"update"), delbutton : hasPermission(accessCodePrefix,"delete"), editOptions:{ recreateForm: true, url:baseUrl+'update', closeOnEscape: true, closeAfterAdd: true, viewPagerButtons: true, closeAfterEdit: true, beforeShowForm: function(form){ style_edit_form(form); }, errorTextFormat:errorTextFormat, afterSubmit:afterSubmit }, delOptions : { recreateForm: true, errorTextFormat:errorTextFormat, afterSubmit : afterSubmit, url:baseUrl+'del', beforeShowForm: function(form){ style_delete_form(form); } } }; return formatoptions; } function getGridDefaultHeight(){ if(HomeGlobal && HomeGlobal.gridDefaultHeight){ return HomeGlobal.gridDefaultHeight; } return 350; } function afterSubmit (response, postdata) { result = $.parseJSON(response.responseText); if(result && !result.success){ if(result.errorCode == 'not_login'){ top.location.href ='login'; } return[false,result.msg] ; } return [true,''] ; } function style_edit_form(form) { //enable datepicker on "sdate" field and switches for "stock" field form.find("input[ctype='date']").datepicker({format:'yyyy-mm-dd' , autoclose:true}); //form.find('input[name=stock]').addClass('ace ace-switch ace-switch-5').after(''); //don't wrap inside a label element, the checkbox value won't be submitted (POST'ed) //.addClass('ace ace-switch ace-switch-5').wrap('
') } }; var mAdd = { closeOnEscape: true, closeAfterAdd: true, viewPagerButtons: true, recreateForm: true, //url:"/user/add", beforeShowForm : function(form) { style_edit_form(form); }, afterSubmit : afterSubmit, errorTextFormat:errorTextFormat }; var mDel ={ //delete record form recreateForm: true, //url:"/user/del", afterSubmit : afterSubmit, errorTextFormat:errorTextFormat, beforeShowForm : function(e) { var form = $(e[0]); if(form.data('styled')) return false; form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('
') style_delete_form(form); form.data('styled', true); }, onClick : function(e) { //alert(1); } }; var mSearch = { //search form recreateForm: true, errorTextFormat:errorTextFormat, afterShowSearch: function(e){ var form = $(e[0]); form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('
') style_search_form(form); }, afterRedraw: function(){ style_search_filters($(this)); }, multipleSearch: true, /** multipleGroup:true, showQuery: true */ }; var mView = { //view record form recreateForm: true, errorTextFormat:errorTextFormat, beforeShowForm: function(e){ var form = $(e[0]); form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('
') } }; var mExcel = { errorTextFormat:errorTextFormat }; var setting = { cellEdit:false, datatype: "json", scrollOffset:20, height: getGridDefaultHeight()+'', shrinkToFit:window.screen.width>=HomeGlobal.BIG_SCREEN?true:false, //toppager: true, pagerpos:'center', viewrecords : true, rowNum:10, rownumbers: true, rowList:[10,20,30], altRows: true, //toppager: true, multiselect: true, //multikey: "ctrlKey", multiboxonly: true, autowidth: true, sortable:false, //width:getFitGridWidth(), getFitGridWidth:function(){ return getFitGridWidth(); }, jsonReader: { root: "data.content", total: "data.totalPages",//总页数 page: "data.number",//当前页 records: "data.totalElements",//记录总数 repeatitems: false }, prmNames : { page:"page", // 表示请求页码的参数名称 rows:"size", // 表示请求行数的参数名称 sort: "orderProperty", // 表示用于排序的列名的参数名称 order: "direction", // 表示采用的排序方式的参数名称 //search:"_search", // 表示是否是搜索请求的参数名称 //nd:"nd", // 表示已经发送请求的次数的参数名称 //id:"id", // 表示当在编辑数据模块中发送数据时,使用的id的名称 //oper:"oper", // operation参数名称 //editoper:"edit", // 当在edit模式中提交数据时,操作的名称 //addoper:"add", // 当在add模式中提交数据时,操作的名称 //deloper:"del", // 当在delete模式中提交数据时,操作的名称 //subgridid:"id", // 当点击以载入数据到子表时,传递的数据名称 npage: null //totalrows:"totalrows" // 表示需从Server得到总共多少行数据的参数名称,参见jqGrid选项中的rowTotal }, loadError:function (xhr,st,err){ $.loy.statusErrorShow(xhr.status); }, loadComplete : function(data) { loadComplete(data); }, gridComplete:function(){ var $jqGrid = $(this); var width = setting.getFitGridWidth(); if(width == 0){ setTimeout(function() { $jqGrid.jqGrid('setGridWidth', setting.getFitGridWidth()); }, 20); }else{ $jqGrid.jqGrid('setGridWidth', setting.getFitGridWidth()); } }, onInitGrid:function(){ var $jqGrid = $(this); $(window).on('resize.jqGrid', function() { $jqGrid.loyGrid('setGridWidth', setting.getFitGridWidth()); }); var parent_column = $jqGrid.closest('[class*="col-"]'); $(document).on('settings.ace.jqGrid', function(ev, event_name, collapsed) { if (event_name === 'sidebar_collapsed' || event_name === 'main_container_fixed') { setTimeout(function() { $jqGrid.jqGrid('setGridWidth', setting.getFitGridWidth()); }, 10); } }); $(document).on('mainTabClick', function(ev) { setTimeout(function() { $jqGrid.jqGrid('setGridWidth', setting.getFitGridWidth()); }, 0); }); } } $.extend($.jgrid.defaults, setting || {}); $.fn.loyGrid = $.fn.extend($.fn.jqGrid,{ navGrid : function (elem, o, pEdit,pAdd,pDel,pSearch, pView,pExcel) { o = $.extend({ position : "left", closeOnEscape : true, beforeRefresh : null, afterRefresh : null, alertwidth : 200, alertheight : 'auto', alerttop: null, alertleft: null, alertzIndex : null, baseUrl:null, //cloneToTop: true, edit: true, editicon : 'ace-icon fa fa-pencil blue', add: true, addicon : 'ace-icon fa fa-plus-circle purple', del: true, delicon : 'ace-icon fa fa-trash-o red', search: false, searchicon : 'ace-icon fa fa-search orange', refresh: true, refreshicon : 'ace-icon fa fa-refresh green', view: false, viewicon : 'ace-icon fa fa-search-plus grey', excel:true, excelicon:'ace-icon fa fa-file-excel-o green', refreshstate:'current' }, $.jgrid.nav, o ||{}); //o = $.extend(mo,o); return this.each(function() { if(this.nav) {return;} var alertIDs = {themodal: 'alertmod_' + this.p.id, modalhead: 'alerthd_' + this.p.id,modalcontent: 'alertcnt_' + this.p.id}, $t = this, twd, tdw; if(!$t.grid || typeof elem !== 'string') {return;} if ($("#"+alertIDs.themodal)[0] === undefined) { if(!o.alerttop && !o.alertleft) { if (window.innerWidth !== undefined) { o.alertleft = window.innerWidth; o.alerttop = window.innerHeight; } else if (document.documentElement !== undefined && document.documentElement.clientWidth !== undefined && document.documentElement.clientWidth !== 0) { o.alertleft = document.documentElement.clientWidth; o.alerttop = document.documentElement.clientHeight; } else { o.alertleft=1024; o.alerttop=768; } o.alertleft = o.alertleft/2 - parseInt(o.alertwidth,10)/2; o.alerttop = o.alerttop/2-25; } $.jgrid.createModal(alertIDs, "
"+o.alerttext+"
", { gbox:"#gbox_"+$.jgrid.jqID($t.p.id), jqModal:true, drag:true, resize:true, caption:o.alertcap, top:o.alerttop, left:o.alertleft, width:o.alertwidth, height: o.alertheight, closeOnEscape:o.closeOnEscape, zIndex: o.alertzIndex }, "#gview_"+$.jgrid.jqID($t.p.id), $("#gbox_"+$.jgrid.jqID($t.p.id))[0], true ); } var clone = 1, i, onHoverIn = function () { if (!$(this).hasClass('ui-state-disabled')) { $(this).addClass("ui-state-hover"); } }, onHoverOut = function () { $(this).removeClass("ui-state-hover"); }; if(o.cloneToTop && $t.p.toppager) {clone = 2;} for(i = 0; i"), sep = "", pgid, elemids; if(i===0) { pgid = elem; elemids = $t.p.id; if(pgid === $t.p.toppager) { elemids += "_top"; clone = 1; } } else { pgid = $t.p.toppager; elemids = $t.p.id+"_top"; } if($t.p.direction === "rtl") {$(navtbl).attr("dir","rtl").css("float","right");} if (o.add && hasPermission(o.accessCodePrefix,"save")) { pAdd = pAdd || {}; pAdd = $.extend(pAdd,mAdd); if(!pAdd.url && o.baseUrl){ pAdd.url = o.baseUrl+"/save"; } tbd = $(""); $(tbd).append("
"+o.addtext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.addtitle || "",id : pAdd.id || "add_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { if ($.isFunction( o.addfunc )) { o.addfunc.call($t); } else { $($t).jqGrid("editGridRow","new",pAdd); } } return false; }).hover(onHoverIn, onHoverOut); tbd = null; } if (o.edit && hasPermission(o.accessCodePrefix,"update")) { tbd = $(""); pEdit = pEdit ||{}; var pEdit = $.extend(pEdit,mEdit); if(!pEdit.url && o.baseUrl){ pEdit.url = o.baseUrl+"/update"; } $(tbd).append("
"+o.edittext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.edittitle || "",id: pEdit.id || "edit_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { var sr = $t.p.selrow; if (sr) { if($.isFunction( o.editfunc ) ) { o.editfunc.call($t, sr); } else { $($t).jqGrid("editGridRow",sr,pEdit); } } else { $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true}); $("#jqg_alrt").focus(); } } return false; }).hover(onHoverIn, onHoverOut); tbd = null; } if (o.view && hasPermission(o.accessCodePrefix,"detail")) { tbd = $(""); pView = pView || {}; pView = $.extend(pView,mView); $(tbd).append("
"+o.viewtext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.viewtitle || "",id: pView.id || "view_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { var sr = $t.p.selrow; if (sr) { if($.isFunction( o.viewfunc ) ) { o.viewfunc.call($t, sr); } else { $($t).jqGrid("viewGridRow",sr,pView); } } else { $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true}); $("#jqg_alrt").focus(); } } return false; }).hover(onHoverIn, onHoverOut); tbd = null; } if (o.del && hasPermission(o.accessCodePrefix,"delete")) { tbd = $(""); pDel = pDel || {}; pDel = $.extend(pDel,mDel); if(!pDel.url && o.baseUrl){ pDel.url = o.baseUrl+"/del"; } $(tbd).append("
"+o.deltext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.deltitle || "",id: pDel.id || "del_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { var dr; if($t.p.multiselect) { dr = $t.p.selarrrow; if(dr.length===0) {dr = null;} } else { dr = $t.p.selrow; } if(dr){ if($.isFunction( o.delfunc )){ o.delfunc.call($t, dr); }else{ $($t).jqGrid("delGridRow",dr,pDel); } } else { $.jgrid.viewModal("#"+alertIDs.themodal,{gbox:"#gbox_"+$.jgrid.jqID($t.p.id),jqm:true});$("#jqg_alrt").focus(); } } return false; }).hover(onHoverIn, onHoverOut); tbd = null; } if (o.excel && hasPermission(o.accessCodePrefix,"excel")) { tbd = $(""); pExcel = pExcel ||{}; var pExcel = $.extend(pExcel,mExcel); if(!pExcel.url && o.baseUrl){ pExcel.url = o.baseUrl+"/excel"; } $(tbd).append("
"+o.exceltext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.exceltitle || "",id: pExcel.id || "excel_"+elemids}) .click(function(){ if($.isFunction( o.excelfunc )) { o.excelfunc.call($t, pExcel); } else { tableId = $.jgrid.jqID($t.p.id); exportExcel(pExcel.url,tableId,pExcel.removeCols); } }).hover(onHoverIn, onHoverOut); tbd = null; } if(o.add || o.edit || o.del || o.view) {$("tr",navtbl).append(sep);} if (o.search) { tbd = $(""); pSearch = pSearch || {}; pSearch = $.extend(mSearch,pSearch); $(tbd).append("
"+o.searchtext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.searchtitle || "",id:pSearch.id || "search_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { if($.isFunction( o.searchfunc )) { o.searchfunc.call($t, pSearch); } else { $($t).jqGrid("searchGrid",pSearch); } } return false; }).hover(onHoverIn, onHoverOut); if (pSearch.showOnLoad && pSearch.showOnLoad === true) { $(tbd,navtbl).click(); } tbd = null; } if (o.refresh) { tbd = $(""); $(tbd).append("
"+o.refreshtext+"
"); $("tr",navtbl).append(tbd); $(tbd,navtbl) .attr({"title":o.refreshtitle || "",id: "refresh_"+elemids}) .click(function(){ if (!$(this).hasClass('ui-state-disabled')) { if($.isFunction(o.beforeRefresh)) {o.beforeRefresh.call($t);} $t.p.search = false; $t.p.resetsearch = true; try { if( o.refreshstate !== 'currentfilter') { var gID = $t.p.id; $t.p.postData.filters =""; try { $("#fbox_"+$.jgrid.jqID(gID)).jqFilter('resetFilter'); } catch(ef) {} if($.isFunction($t.clearToolbar)) {$t.clearToolbar.call($t,false);} } } catch (e) {} switch (o.refreshstate) { case 'firstpage': $($t).trigger("reloadGrid", [{page:1}]); break; case 'current': case 'currentfilter': $($t).trigger("reloadGrid", [{current:true}]); break; } if($.isFunction(o.afterRefresh)) {o.afterRefresh.call($t);} } return false; }).hover(onHoverIn, onHoverOut); tbd = null; } tdw = $(".ui-jqgrid").css("font-size") || "11px"; $('body').append(""); twd = $(navtbl).clone().appendTo("#testpg2").width(); $("#testpg2").remove(); $(pgid+"_"+o.position,pgid).append(navtbl); if($t.p._nvtd) { if(twd > $t.p._nvtd[0] ) { $(pgid+"_"+o.position,pgid).width(twd); $t.p._nvtd[0] = twd; } $t.p._nvtd[1] = twd; } tdw =null;twd=null;navtbl =null; this.nav = true; } }); } }); })(jQuery);




© 2015 - 2025 Weber Informatics LLC | Privacy Policy