加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

FlexiGrid支持shift多选

发布时间:2020-12-15 04:02:01 所属栏目:百科 来源:网络整理
导读:在前面几章Flexigrid处理的基础上,处理了支持shift多选的功能,增加的代码标注了“//处理shfit多选 add by danielinbiti” 主要增加了三部分代码 第一部分 (function ($) {$.addFlex = function (t,p) {if (t.grid) return false; //return if already exis

在前面几章Flexigrid处理的基础上,处理了支持shift多选的功能,增加的代码标注了“//处理shfit多选 add by danielinbiti”

主要增加了三部分代码

第一部分

(function ($) {
	$.addFlex = function (t,p) {
		if (t.grid) return false; //return if already exist
		p = $.extend({ //apply default properties
			height: 200,//default height
			width: 'auto',//auto width
			striped: true,//apply odd even stripes
			novstripe: false,minwidth: 30,//min width of columns
			minheight: 80,//min height of columns
			resizable: true,//allow table resizing
			url: false,//URL if using data from AJAX
			dwrAction:function(){},method: 'POST',//data sending method
			dataType: 'xml',//type of data for AJAX,either xml or json
			errormsg: 'Connection Error',usepager: false,nowrap: true,page: 1,//current page
			total: 1,//total pages
			useRp: true,//use the results per page select box
			rp: 15,//results per page
			rpOptions: [10,15,20,30,50],//allowed per-page values 
			title: false,pagestat: 'Displaying {from} to {to} of {total} items',pagetext: 'Page',outof: 'of',findtext: 'Find',procmsg: 'Processing,please wait ...',query: '',qtype: '',isColSel:true,nomsg: 'No items',minColToggle: 1,//minimum allowed column to be hidden
			showToggleBtn: true,//show or hide column toggle popup
			hideOnSubmit: true,autoload: true,blockOpacity: 0.5,preProcess: false,onDragCol: false,onToggleCol: false,onChangeSort: false,onSuccess: false,onError: false,onRowClick:function(){return true},//add by jej
			onSubmit: false //using a custom populate function
		},p);
		$(t).show() //show if hidden
			.attr({
				cellPadding: 0,cellSpacing: 0,border: 0
			}) //remove padding and spacing
			.removeAttr('width'); //remove width properties
		//create grid class
		isEditing = false;
		isShiftMulti = false;  //处理shfit多选 add by danielinbiti
		shiftSelRowIndex = -1; //处理shfit多选 add by danielinbiti
		$('body').keydown(function (e) { //处理shfit多选 add by danielinbiti
				if (e.keyCode == 16) {  
					isShiftMulti=true;  
				}
		});
		$('body').keyup(function (e) { //处理shfit多选 add by danielinbiti
				if (e.keyCode ==16) {
					isShiftMulti=false;
					shiftSelRowIndex = -1;
				}
		})

第二部分

getSelectRowsToGrid: function(){//处理shfit多选 add by danielinbiti
				//add by jej
				var rtnList = new Array();
				var objRows = $('.trSelected',$(t));
				if(objRows!=null){
					for(var i=0;i<objRows.length;i++){
						 var row = objRows[i];
						 var arr = new Array();
						 for(var j=0;j<row.cells.length;j++){
						 	   if(isEditing && p.colModel[j].isEdit){
						 	   	  var td = row.cells[j];
	    				  	  var div = $('div',$(td));
	    				  	  var inputbox = $('input',$(div[0]));
	    				  	  if(inputbox.length>0){
											 arr[j] = inputbox[0].value;
									  }
								 }else{
						       var value = row.cells[j].innerText;
						       value=value.replace(/^n+|n+$/g,"");
						       arr[j] = value;
					       }
					   }
					   rtnList[rtnList.length] = arr;
				  }
				}
				return rtnList;
			}

第三部分

addRowProp: function () {
				var _self = this;
				$('tbody tr',g.bDiv).each(function () {
					$(this).click(function (e) {
						var obj = (e.target || e.srcElement);
						if (obj.href || obj.type) return true;
						$(this).toggleClass('trSelected');
						if (p.singleSelect) $(this).siblings().removeClass('trSelected');
						if(p.onRowClick && typeof(p.onRowClick)=='function'){
							  var rowObj = _self.getRows();
							  p.onRowClick(rowObj,e);
						}
					}).mousedown(function (e) {
						if (e.shiftKey) {
							$(this).toggleClass('trSelected');
							g.multisel = true;
							this.focus();
							$(g.gDiv).noSelect();
							if(isShiftMulti && !p.singleSelect){ //处理shfit多选 add by danielinbiti
								  _self.selectRowByIndexArea($(this)[0].rowIndex,shiftSelRowIndex); //处理shfit多选 add by danielinbiti
								  shiftSelRowIndex = $(this)[0].rowIndex; //处理shfit多选 add by danielinbiti
							}
						}
代码多贴了一下上下文,便于往文件中添加。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读