jQuery学习笔记--jqGrid开发最新代码分享

var commonQuery = '../common/entityList.action?entityName=Process';jQuery("#list").jqGrid ({
		rowNum : 10,
		pager : '#pager',
		viewrecords : true,
		multiselect: true,
		width: 540,
		height : defaultGridHeight + 30,
	   	url: commonQuery + '&queryConditions[\'ifCurVersion\']=2&queryConditions[\'state\']=2&queryConditions[\'processType\']=0',
		datatype : "json",
	   	jsonReader: { 
	      root:"dataRows", page:"page", total:"total", records:"records", repeatitems:false, id : "id"
	  	},
		colNames : [
    		'<s:property value="#processName" />'
    		, '<s:property value="#version" />'
    		, '<s:property value="#description" />'
    		, '<s:property value="#expectTime" />'
    	],
		colModel : [
    		{name:'processName', label:'<s:property value="#processName" />', index:'processName', sorttype:'text', align:'left', width:160}
    		, {name:'version', label:'<s:property value="#version" />', index:'version', sorttype:'float', align:'left', width:120}
    		, {name:'description', label:'<s:property value="#description" />', index:'description', sorttype:'text', align:'left', width:200}
    		, {name:'expectTime', label:'<s:property value="#expectTime" />', index:'expectTime', sorttype:'int', align:'left', width:120}
		],
		onSelectRow: function(rowid){  
			var rowData = $("#list").getRowData(rowid); 
			reValue[1] = rowData.processName;
			reValue[2] = rowData.version;
			reValue[3] = rowData.description;
			reValue[4] = rowData.expectTime;
		},
		gridComplete : function() {
			$("#_empty", "#list").addClass("nodrag nodrop");
			jQuery("#list").tableDnDUpdate();
			var ids=jQuery("#list").jqGrid('getDataIDs');
			for(var i=0;i<ids.length;i++)
			{
				var cl = ids[i];
				var rowdata=jQuery("#list").jqGrid('getRowData',cl);
				var expectTime=rowdata["expectTime"];
	    		expectTime=expectTime+"<s:text name='label.expectTime.unit' />";
	    		jQuery("#list").jqGrid('setRowData',ids[i],{expectTime:expectTime});
		    }
		}
	});
	//显示流程列表
	jQuery("#list").jqGrid('navGrid', "#pager", {
		edit:false, add:false, del:false, multipleSearch:false, search:false, refresh:false
	});
	jQuery("#setColumns").click(function() {
		jQuery("#list").jqGrid('setColumns');
	});
	//流程查询
	jQuery("#search").click(function() {
		refreshList();
		refreshStat();
	});
	function getId() {
		var id = jQuery("#list").jqGrid("getGridParam", "selrow");
		if (id)	{
			return id;
		} else {
			alert('<s:text name="message.alert.nonSelected" />');
			return null;
		}
	}
	//获取单元格的显示值
	function getCellValue(columnName, selectedId) {
		var id;
		if(selectedId)
			id = selectedId;
		else
			id = getId();
		
		if (id)	{
			return eval('jQuery("#list").jqGrid("getRowData", "' + id + '").' + columnName);
		} else {
			return null;
		}
	}
	function deleteRow(rowIndex) {
		var su = jQuery("#list").jqGrid('delRowData', rowIndex);
		if(su)
			alert("Succes. Write custom code to delete row from server");
		else
			alert("Allready deleted or not in list");
	}
	function addRow(rowIndex) {
		var datarow = {id:"99",invdate:"2007-09-01",name:"newRow",note:"<img src='images/user1.gif'/"};
		var su = jQuery("#list").jqGrid('addRowData', rowIndex, datarow);
		if(su)
			alert("Succes. Write custom code to update row in server");
		else
			alert("Can not update");
	}

更多详情:猛点这里!

你可能感兴趣的:(jQuery学习笔记--jqGrid开发最新代码分享)