easyui datagrid自定义按钮列,最后操作列

目前小菜总结了两种方法:

一、datagrid绑定数据列是通过HTML设置好的

                <table id="dg" title="用户管理" style="width: 700px;table-layout:fixed; height: 300px" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10">
                    <thead>
                        <tr>
                            <th field="no" width="80">用户账号</th>
                            <th field="level" width="100">级别</th>
                            <th field="userName" width="80">姓名</th>
                            <th field="phone" width="80" align="right">电话</th>
                            <th field="Email" width="80" align="right">邮箱</th>
                            <th field="explain" width="100" align="right">备注</th>
                            <th field="opera" width="110" data-options="formatter:editDelete">操作列</th>
                        </tr>
                    </thead>
                </table>
JS通过AJAX向后台得到JSON数据,通过$('#userName').combobox('loadData', optionstring)绑定,所有代码easyui教程里都有

添加按钮“操作列”多了一个(data-options="formatter:editDelete")属性,在JS需要添加一个方法即可

function editDelete(val, row, index) {
    return '<a href="#" οnclick="a()">编辑</a>';
}

val:是当前单元格内容

row:是当前行对象(所有内容)

index:是当前行索引下标值


二、datagrid绑定数据列是通过JS设置好的
$(document).ready(function () {
  4                $("#table_Data").datagrid({
  5                    toolbar: '#myToolbar',
  6                    url: urlAshx,
  7                    queryParams: { "action": "carlist" },
  8                    method: 'post',
  9                    width: 'auto', 10                    
 12                    singleSelect: true,
 13                    fitColumns: false,
 14                    pagination: true,                  
 18                    rownumbers: true,
 19                    loadMsg: "正在加载数据...",
 20                    columns: [[
 21                        { filed: 'ID', title: '编号', width: 120, hidden: true },
 22                        { filed: 'Name', title: '车辆名称', width: 120, align: 'center' },
 23                        { filed: 'Type', title: '型号', width: 120, align: 'center' },
 24                        { filed: 'LicenseTag', title: '牌号', width: 120, align: 'center' },
 25                        { filed: 'Color', title: '座位数', width: 120, align: 'center' },
 26                        { filed: 'Seats', title: '颜色', width: 120, align: 'center' },
 27                        { filed: 'Remarks', title: '备注', width: 920, align: 'center' },
 28                        {
 29                            filed: 'Action', title: '操作', width: 550, align: 'center', formatter: function (value, row, index) {
 30                                alert(row.Name);
 31                                var Action = "<a href='javascript:void(0);' οnclick='Edit(" + row.ID + ")'>修改</a>\
 32                                              | <a href='javascript:void(0);' οnclick='Delete(" + row.ID + ")'>删除</a>";
 33                                return Action;
 34                            }
 35                        }
 36                    ]]
 42                });
 43 });
绑定数据后即可

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 22
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值