DataGrid数据绑定

第一种:直接绑定数据源。

<table id="dgbuild" title="" class="easyui-datagrid"
		url="${pageContext.request.contextPath}/queryAllDormitory"
		style="width: 100%; height: 450px; overflow: scroll;"
		toolbar="#toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<th field="id" hidden="true"></th>
				<th field="buildName" style="width: 20%;">宿舍楼名称</th>
				<th field="sex" style="width: 15%;">类型名称</th>
				<th field="total" style="width: 20%;">宿舍容量</th>
				<th field="remainder" style="width: 20%;">剩余量</th>
				<th style="width: 20%;"
					data-options="field:'aaa',width:50,align:'center',formatter:formatOper">分配宿舍</th>

			</tr>
		</thead>
	</table>

通过Url获取json串的数据源,然后将json中对应的字段,绑定到field对应的字段上。

结果图:

第二种:通过js绑定数据源

<table id="schoolDg" class="easyui-datagrid" name="schoolDg"
				<%-- 				url="${pageContext.request.contextPath}/queryLeftSchool?buildType=女" --%>
				pagination="true"
				rownumbers="true" fitColumns="true" toolbar="#reToolbar"
				singleSelect="true">
				<thead>
					<tr>
						<th>学院</th>
						<th>学生类型</th>
						<th>未分配人数</th>
						<th>分配宿舍</th>
					</tr>
				</thead>
			</table>
我们通过js给上面的table绑定数据:

	//宿舍楼列表   (查询所有  + 有空缺的宿舍     的宿舍楼列表)
		function formatOper(val, row, index) {
			return '<span  class="icon-edit"   plain="true"  οnclick="setInstitution('
					+ index + ')">      </span>';
		}	
//弹出分配学院的页面     (查询所有     +未分配宿舍人员+ 性别   的学院列表信息)
	//弹出分配学院的页面     (查询所有     +未分配宿舍人员+ 性别   的学院列表信息)
		function setInstitution(index) {
			$('#dgbuild').datagrid('selectRow', index);
			var row = $('#dgbuild').datagrid('getSelected');
		
				$('#schoolDg')
						.datagrid(
								{
									'url' : "${pageContext.request.contextPath}/queryLeftSchool?buildType="
											+ row.sex + "&buildId=" + row.id,
									columns : [ [ {
										field : 'institutionName',
										title : '学院',
										width : '25%'
									}, {
										field : 'sex',
										title : '学生类型',
										width : '18%'
									}, {
										field : 'studentsCont',
										title : '未分配人数',
										width : '20%'
									}, {
										field : 'aaa',
										title : '分配宿舍',
										formatter : formatReOper,
										width : '20%'
									}, ] ]
								}

						);

			
		}	

结果图 :



3.小结

从两种获取的重点就是url。当我们url不够完整,也就是说还需要携带一些参数,而这种参数,往往能直接获取,这种情况我们不妨采用第二种方式。第二种方式较繁琐,但实用性更强。

 

DataGrid获取数据的两种方式,不通情况选择不通的方式,从而实现我们想要的。也正验证了提高班的一句话:方法总比困难多。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值