关于公司common.jqgrid.js文件的研究(未完)

var pageGrid;
	$().ready(function(){

		var searchUrl = "<c:url value='assessmentSearch.action' />";
		var deleteUrl = "<c:url value='assessmentDelete.action' />";
		var previousUrl = "<c:url value='assessmentList.action' />";

		//构建表格
		pageGrid = {
			gridName : "assessmentListGrid",
			formName : "assessmentListForm",
			caption : "考核列表",
			pagerVar : "assessmentListPager",
			searchUrl : searchUrl,
			searchParameters : ['searchAssessmentName', 'searchState'],
			mutiSelect : false,
			colNames : ['考核名称',  '系统名称','发起日期','截至申诉日期', '状态','','','操作'],
			colModel : [
			            {name : 'assessmentName', index : 'assessmentName',width:'30%'},
			            {name : 'systemName', index : 'systemName' ,sortable:false,width:'20%'},
			            {name : 'submitTime', index : 'submitTime',formatter:"date", formatoptions: {newformat:'Y-m-d'},align:'right',width:'10%'},
			            {name : 'appealEndTiem', index : 'appealEndTiem',formatter:"date", formatoptions: {newformat:'Y-m-d'} ,align : 'right',width:'10%'},
				        {name : 'state', index : 'state',width:'10%'},
			            {name : 'stateEn', index : 'stateEn',hidden : true ,width: '10%'},
			            {name : 'createTime', index : 'createTime',hidden : true ,width: '10%'},
			            {name : 'operation', index : 'operation',sortable:false,width:'10%'}
					],
			exportColNames:[],
			exportColModel:[],
			exportFileName:"",
			sortName : "createTime",
			sortOrder : "desc",
			rowId : "id",
			pageCache : "${pageCache}"
		};

 

$.jqgridBuildPageGrid(pageGrid);

 

<form id="assessmentListForm" action="assessmentList.action" method="post">
	<!-- 导航 -->
	<div class="span-24 last">
		<w:nav type="top"/>
	</div>
	<!-- 查询栏 -->
	<div class="span-24 last">
		<fieldset>
			<legend>查询条件</legend>
			<table >
				<tr>
					<td width="10%" class="searchParameterTd">
						考核名称:
					</td>
					<td  width="40%">
						<s:textfield  cssClass="text" id="searchAssessmentName" name="searchAssessmentName"/>
					</td>
					<td width="10%"  class="searchParameterTd">
						状态:
					</td>
					<td  width="40%">
					<s:select id="searchState"  cssClass="select" name="searchState" list="stateList"   headerKey="" headerValue="请选择" listKey="key"  listValue="value"></s:select>
					</td >
				</tr>
			</table>
		</fieldset>
		<fieldset>  
			<input type="button" value="查询" name="searchButton" id="searchButton"/>
			<input type="button" value="重置" name="resetButton" id="resetButton"/>
			<input type="button" value="发起考核" name="createButton" id="createButton"/>	
		</fieldset>
	</div>
	<!-- 列表栏 -->
	<div class="span-24 last">
		<table id="assessmentListGrid"></table>
		<div id="assessmentListPager"></div>
		<div id="tblMasterMessage"></div>
	</div>
</form>

 

1、$.jqgridBuildPostData
2、$.jqgridSearch
3、$.jqgridSearchButtonClick

页面js调用:

//查询按钮
		$("#searchButton").click(function(){ 
			var startTime = $("#searchAppealStartTime").val();
			var endTime = $("#searchAppealEndTime").val();
			$.jqgridSearchButtonClick(pageGrid.gridName,pageGrid.searchParameters,searchUrl);
		});


common.jqgrid.js中对应的方法声明:

$.jqgridSearchButtonClick = function(gridName,searchParameters,searchUrl) {
	$.jqgridSearch(gridName,searchParameters,searchUrl,true);
};


 

$.jqgridSearch = function(gridName,searchParameters,searchUrl,isResetPage) {


	//这里需要根据表格的实际需要查询的内容设置
	var postData = $.jqgridBuildPostData(searchParameters);
	
	
	if(isResetPage == true) {
		eval("postData.pageCache=false");
		$("#" + gridName).jqGrid("appendPostData",postData);

		//每次提出新的查询都转到第一页
		$("#" + gridName).jqGrid("setGridParam",{page:1});
		//提交post并刷新表格
		$("#" + gridName).jqGrid("setGridParam",{url:searchUrl}).trigger("reloadGrid");
	}
	else {
		
		$("#" + gridName).jqGrid("appendPostData",postData);
		
		//刷新表格
		$("#" + gridName).jqGrid("setGridParam",{url:searchUrl}).trigger("reloadGrid");
	}
};


 

//按查询参数构建postData
$.jqgridBuildPostData = function(searchParameters) {
	//准备post数据
	var postData = new Object();
	
	//当前导出参数
	for(var i = 0 ; i < searchParameters.length; i++) {
		var name = searchParameters[i];
		var currentValue = $("#" + searchParameters[i]).attr('value');

	    eval("postData."+name+"=currentValue");
	}
	
	return postData;
};



$.jqgridPageButtonClick
$.jqgridDeleteButtonClick
$.jqgridDeleteButtonClick2

$._jqgridDeleteButtonClick

// 删除 ajax
		$("#deleteBtn").click(function(){
			$.jqgridDeleteButtonClick(messageGrid.gridName,messageGrid.searchParameters,deleteUrl)
		});

common.jqgrid.js中对应的方法声明:

$.jqgridDeleteButtonClick = function(gridName,searchParameters,deleteUrl) {
	var confirmDeleteStr = "确定删除所选条目?";
	var deleteSuccessStr = "删除成功";
	var alertSelectStr = "请选择要删除的条目";
	
	$.jqgridDeleteButtonClick2(gridName,searchParameters,deleteUrl,confirmDeleteStr,deleteSuccessStr,alertSelectStr);
};

 

//confirmDeleteStr是指确认删除的语句,deleteSuccessStr是删除成功语句,alertSelectStr是提示选择语句
$.jqgridDeleteButtonClick2 = function(gridName,searchParameters,deleteUrl,confirmDeleteStr,deleteSuccessStr,alertSelectStr) {
	var selectIds = $("#" + gridName).jqGrid('getGridParam','selarrrow');
	
	if (selectIds!=null && selectIds!="")	{
		selectIds = selectIds.join(",");
		$._jqgridDeleteButtonClick(gridName,searchParameters,deleteUrl,selectIds,confirmDeleteStr,deleteSuccessStr);
	} else{
		$.alert(alertSelectStr);
	}
};




$.jqgridSingleDeleteButtonClick

$.jqgridSingleDeleteButtonClick2

页面js调用:

$.singleDeleteButtonClick = function (rowId) {
			var deleteUrl = "<c:url value='assessmentDelete.action' />";
			$.jqgridSingleDeleteButtonClick2(pageGrid.gridName,pageGrid.searchParameters,deleteUrl,rowId,"是否确定删除所选考","删除成功");
			//$.jqgridSingleDeleteButtonClick(pageGrid.gridName,pageGrid.searchParameters,deleteUrl,rowId);
		}

common.jqgrid.js中对应的方法声明:

$.jqgridSingleDeleteButtonClick = function(gridName,searchParameters,deleteUrl,rowId) {
	var confirmDeleteStr = "确定删除所选条目?";
	var deleteSuccessStr = "删除成功";
	$.jqgridSingleDeleteButtonClick2(gridName,searchParameters,deleteUrl,rowId,confirmDeleteStr,deleteSuccessStr);
};
$.jqgridSingleDeleteButtonClick2 = function(gridName,searchParameters,deleteUrl,rowId,confirmDeleteStr,deleteSuccessStr) {
	$._jqgridDeleteButtonClick(gridName,searchParameters,deleteUrl,rowId,confirmDeleteStr,deleteSuccessStr);
};
//底层的删除函数
$._jqgridDeleteButtonClick = function(gridName,searchParameters,deleteUrl,selectIds,confirmDeleteStr,deleteSuccessStr) {
	if(confirm(confirmDeleteStr)) {
		//设置postData
		var postData = $.jqgridBuildPostData(searchParameters);
		eval("postData.selectIds=selectIds");
		$("#" + gridName).jqGrid("appendPostData",postData);
		postData = $("#" + gridName).jqGrid('getPostData');
		$.ajax({
			  type: 'POST',
			  url: deleteUrl,
			  data: postData,
			  dataType:"json",
			  success: function (response) {
					if(response.message == 'success'){
						$.alert(deleteSuccessStr);
						//刷新表格
						$("#" + gridName).jqGrid().trigger("reloadGrid");	
					}
					else {
						$.alert(response.message);
					}
			   }
		});
		
	}
};





$.jqgridDownload
$.jqgridExportButtonClick

// 导出   
		$.exportfile =function(rowId){
			var exportUrl = "<c:url value='/assessment/exportAssessment.action'/>";
			exportUrl = $.commonBuildUrl (exportUrl,"assessmentId="+rowId);
			$.jqgridExportButtonClick(pageGrid.gridName,pageGrid.searchParameters,exportUrl,pageGrid.exportColNames,pageGrid.exportColModel,pageGrid.exportFileName);
		};	

common.jqgrid.js中对应的方法声明:

$.jqgridExportButtonClick = function(gridName,searchParameters,exportUrl,exportColNames,exportColModel,exportFileName) {
	//准备post数据
	var postData = new Object();
	
	//当前导出参数
	for(var i = 0 ; i < searchParameters.length; i++) {
		var name = searchParameters[i];
		var currentValue = $("#" + searchParameters[i]).attr('value');

	    eval("postData."+name+"=currentValue");
	}
	
	//导出Excel列头
	for(var i = 0 ; i < exportColNames.length; i++) {
		var name = exportColNames[i];
	    eval("postData.exportColNames"+i+"=name");
	}
	
	//导出Excel列值
	for(var i = 0 ; i < exportColModel.length; i++) {
		var model = exportColModel[i];
	    eval("postData.exportColModel"+i+"=model");
	}	
	
	//导出文件名
	var fileName = exportFileName;
	eval("postData.fileName=fileName");
	
	$("#" + gridName).jqGrid("appendPostData",postData);
	postData = $("#" + gridName).jqGrid('getPostData');

	//调用下载方法,通过post方式发送参数到下载链接
	$.jqgridDownload(exportUrl, postData, "post", function(){});
};

 

//下载函数
$.jqgridDownload = function(url, data, method, callback){
	var inputs = "";
	var iframeX;
	var downloadInterval;
	if(url && data){
		// remove old iframe if has
		if($("#iframeX")) $("#iframeX").remove();
		// creater new iframe
		iframeX= $("<iframe src=\"[removed]false;\" name=\"iframeX\" id=\"iframeX\"></iframe>").appendTo("body").hide();
		if($.browser.msie){
			downloadInterval = setInterval(function(){
				// if loading then readyState is “loading” else readyState is “interactive”
				if(iframeX&& iframeX[0].readyState !=="loading"){
					callback();
					clearInterval(downloadInterval);
				}
			}, 23);
		} else {
			iframeX.load(function(){
				callback();
			});
		}

		//split params into form inputs
		$.each(data, function(p, val){
			inputs+="<input type=\"hidden\" name='"+ p +"' value='"+ val +"' />";
		});
		
		//create form to send request
		$("<form action='"+ url +"' method='"+ (method||"post") + "' target=\"iframeX\">"+inputs+"</form>\"").appendTo("body").submit().remove();
	};
};





$.jqgridLoadError
$.jqgridLoadComplete

$.jqgridGetAllRowData

//获取列表中所有的条目数据
        var allRowData = $.jqgridGetAllRowData("typeAndItemListGrid");




$.jqgridSetRowData
$.jqgridGetRowData

//向operation列加入按钮
		$.rowComplete = function(rowId){
			var rowData = $.jqgridGetRowData(pageGrid.gridName,rowId);
			var operationHtml = '';
			//根据状态向operation操作列中添加相应按钮
			if(rowData.stateEn == '${allocateState}'){
				operationHtml += "<input type='button' value='编辑' onclick='buttonEditClick(\"" + rowId + "\");'/>";
				operationHtml += "<input type='button' value='删除' onclick='$.singleDeleteButtonClick(\"" + rowId + "\")'/>";
				//operationHtml += "<input type='button' value='删除' onclick='$.jqgridSingleDeleteButtonClick2(\""+pageGrid.gridName+"\",\""+pageGrid.searchParameters+"\",\""+urldelete+"\",\""+rowId+"\",\"删除所选项\",\"删除成功\");'/>";
				
			} else {
				operationHtml += "<input type='button' value='查看' onclick='buttonLookClick(\"" + rowId + "\");'/>";
				if (rowData.stateEn == "${endState}")  {
					operationHtml += "<input type='button' value='导出' onclick= '$.exportfile(\""+rowId+"\")'/>";
				}  
			}
			$.jqgridSetRowData(pageGrid.gridName, rowId, {operation : operationHtml});
		}


common.jqgrid.js中对应的方法声明:

//设置一行数据
$.jqgridSetRowData = function (gridName,rowId,rowData) {
	$("#" + gridName).jqGrid('setRowData',rowId,rowData);
};
//获取一行数据
$.jqgridGetRowData = function (gridName,rowId) {
	return $("#" + gridName).jqGrid('getRowData',rowId);
};



$.jqgridAddRowData
$.jqgridClearGridData
$.jqgridReloadGridData
$.jqgridDeleteRowData
$.jqgridGenerateTempRowId
$.jqgridBuildPageGrid
$.jqgridSubGridRowComplete
$.jqgridSubGridReload
$.jqgridBuildSubGrid
$.jqgridSelectRow
$.jqgridResize
$.jqgridIframeResize
$.jqgridBuildNonePageGrid
$.jqgridReload
$.jqgridReloadWithOhterSearchUrl
$.jqgridLocalDataGridReload
$.jqgridLocalDataGridReloadWithOtherSearchUrl
$.jqgridBuildLocalDataGrid
$.localDataRowComplete
$.jqgridLocalDataDeleteButtonClick
$.jqgridLocalDataDeleteButtonClick2
$._jqgridLocalDataDeleteButtonClick
$.jqgridLocalDataSingleDeleteButtonClick
$.jqgridLocalDataSingleDeleteButtonClick2
$._jqgridLocalDataSingleDeleteButtonClick
$.jqgridSetLinkRow
$.jqgridSetLinkRowWithOpen

 

你可能感兴趣的:(关于公司common.jqgrid.js文件的研究(未完))