详解DataGrid使用的方法(重要)

本文详细介绍了如何使用EasyUI的DataGrid组件。首先讲解了如何通过静态HTML和ajax请求创建DataGrid,展示了json数据的使用。接着,通过API创建DataGrid,并添加了工具栏功能,包括添加、删除、修改和查询操作。此外,还讨论了分页查询的实现,涉及服务端响应的json结构调整。最后,提到了取派员管理功能,包括批量删除和修改操作的前后端实现步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.将静态HTML渲染为DataGrid样式

<!-- 方式一:将静态HTML渲染为datagrid样式 -->
	<table class="easyui-datagrid">
		<thead>
			<tr>
				<th data-options="field:'id'">编号</th>
				<th data-options="field:'name'">姓名</th>
				<th data-options="field:'age'">年龄</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>001</td>
				<td>小明</td>
				<td>90</td>
			</tr>
			<tr>
				<td>002</td>
				<td>老王</td>
				<td>3</td>
			</tr>
		</tbody>
	</table>

2、发送ajax请求获取json数据创建datagrid     提供json文件 

<!-- 方式二:发送ajax请求获取json数据创建datagrid -->
    <table data-options="url:'${pageContext.request.contextPath }/json/datagrid_data.json'" 
            class="easyui-datagrid">
        <thead>
            <tr>
                <th data-options="field:'id'">编号</th>
                <th data-options="field:'name'">姓名</th>
                <th data-options="field:'age'">年龄</th>
            </tr>
        </thead>
    </table>

2、使用easyUI提供的API创建datagrid(掌握)

<!-- 方式三:使用easyUI提供的API创建datagrid -->
    <script type="text/javascript">
        $(function(){
            //页面加载完成后,创建数据表格datagrid
            $("#mytable").datagrid({
                //定义标题行所有的列
                columns:[[
                 {title:'编号',field:'id',checkbox:true},
                 {title:'姓名',field:'name'},
                 {title:'年龄',field:'age'},
                 {title:'地址',field:'address'}
                 ]],
                //指定数据表格发送ajax请求的地址
                url:'${pageContext.request.contextPath }/json/datagrid_data.json',
                rownumbers:true,
                singleSelect:true,
                //定义工具栏
                toolbar:[
                 {text:'添加',iconCls:'icon-add',
                      //为按钮绑定单击事件
                      handler:function(){
                          alert('add...');
                      }
                 },
                 {text:'删除',iconCls:'icon-remove'},
                 {text:'修改',iconCls:'icon-edit'},
                 {text:'查询',iconCls:'icon-search'}
          

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值