jQuery插件dataTables使用Ajax通过Action点击下一步传数据

wenmaomao 2012-02-01

1.前端js代码
1).<script src="/scm/js/jquery-1.3.2.js" type="text/javascript"></script>
2).<script type="text/javascript" language="javascript" src="jqtables/js /jquery.dataTables.js"></script>
$(function(){
				var oTable = $('#datatable').dataTable({
			        'bJQueryUI': true,
			        "bProcessing":true,
			     	"bServerSide": true,
			   		"iDisplayStart":0,
			   		 "iDisplayLength": 5,
			   		"sAjaxSource":"region_safe_home
_json.action?region.id=1",

			        "sAjaxDataProp":"applyInfoList",
			        "aoColumns": [
			            { "mDataProp": "id" },
			            { "mDataProp": "resource.resourceName" },
			            { "mDataProp": "operateTypeName" },
			            { "mDataProp": "applyUser" },
			            { "mDataProp": "statusName" },
			            { "mDataProp": "createTime"}
			        ],
			        'sPaginationType': 'full_numbers',
			        'bSort':false,
			    });
			});
 3).HTML代码中table的id为datatable
2.Action中
private int curPage;
	private String iTotalRecords; //向前端返回数据需要的JSON对象
	private String iTotalDisplayRecords;//向前端返回数据需要的JSON对象
	private int iDisplayLength;
	private int iDisplayStart;
	
	public String applyHome() throws ServiceException{
		return SUCCESS;
	}
	
	public String applyList() throws ServiceException{
		
		int displayLength = iDisplayLength;
		int displayStart = iDisplayStart ;
		
		applyInfoList = this.getApplyInfoManager().findApplyInfoByRegion(region);
		
		int totalNum = applyInfoList.size();
		
		int pageCount = totalNum/displayLength;
		int remainder = totalNum%displayLength;
		
		if(remainder != 0){
			pageCount = pageCount + 1;
		}
		
		iTotalRecords = totalNum+"";
		iTotalDisplayRecords = totalNum+"";
		
		curPage = displayStart/displayLength+1; 
		
		int startNum = displayStart;
		int endNum = 5;
		
		startNum = displayLength*(curPage-1);
		
		if(remainder != 0){
			if(curPage == pageCount){
				endNum = startNum + remainder;
			}else{
				endNum = startNum+displayLength;
			}			
		}else {
			endNum = startNum+displayLength;
		}
		
		applyInfoList = applyInfoList.subList(startNum, endNum);
		
		return SUCCESS;
	}
 

相关推荐

Web全栈笔记 / 0评论 2020-06-15