FlexiGrid支持shift多选

27 篇文章 0 订阅

在前面几章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
							}
						}

代码多贴了一下上下文,便于往文件中添加。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值