easyUI datagrid自定义添加列 (点击事件)

本文介绍如何在easyUI的datagrid中自定义添加包含操作按钮的列,如删除功能,通过JS实现。

有列表 想添加一个操作列  类似删除之类的  


<table class="easyui-datagrid" title="编码列表" style="width:500px; min-height: 0px;" id="Hsdata">
                                    <thead>
                                        <tr>
                                            <th data-options="field:'HsCode',width:100">编码</th>
                                            <th data-options="field:'StartDate',width:150">开始日期</th>
                                            <th data-options="field:'EndDate',width:150,align:'结束日期'">结束日期</th>
                                            <th data-options="field:'IsImporter',width:100,align:'是否进口数据'">是否进口数据</th>
                                            <th data-options="field:'IsDemoData',width:100">是否演示数据</th>
                                            <th data-options="field:'Id',width:100,formatter:  rowformater,onClickRow:delHsCode">操作</th>
                                        </tr>
                                    </thead>
                                </table>

通过formatter方法给Jquery easyui 的datagrid 每行增加操作链接


 //删除
        function rowformater(value, row, index) {
            return '<a href="#" onclick="delHsCode(' + index + ')">删除</a>';          
        }



上面这个方法在其他博客里看的不全  别人的是:
return '<a href="'+row["ID"]+'">修改</a>';  
  我改了一下 在onclick方法中绑定方法 因为如果用之前的传value row index 三个参数会导致自动触发 所以改动了一下

function delHsCode(index) {
            $('#Hsdata').datagrid('selectRow', index);
            var row = $('#Hsdata').datagrid('getSelected');
            if (row.Id != null && row.Id !== undefined)
            alert(row.Id);
        }

以下为效果图:






评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值