使用jQuery EasyUI删除datagrid中的子行

使用jQuery EasyUI删除datagrid中的子行,jquery,datagrid,delete-row,jquery-easyui,Jquery,Datagrid,Delete Row,Jquery Easyui,我在我的项目中使用jQuery EasyUI,我需要删除Datagrid中的子行,但我不知道如何在Datagrid中找到此记录 下面是执行该任务的布局和代码片段 使用子项创建datagrid: <script type="text/javascript"> $(function() { $('#dg').datagrid({ view: detailview, detai

我在我的项目中使用jQuery EasyUI,我需要删除Datagrid中的子行,但我不知道如何在Datagrid中找到此记录

下面是执行该任务的布局和代码片段

使用子项创建datagrid:

<script type="text/javascript">
$(function() {
                $('#dg').datagrid({
                    view: detailview,
                    detailFormatter: function(index, row) {
                        return '<div style="padding:2px;"><table class="ddvclass" id="ddv"></table></div>';
                    },
                    onExpandRow: function(index, row) {
                        var ddv = $('#dg').datagrid('getRowDetail', index).find('table.ddvclass');
                        ddv.datagrid({
                            url: 'get_sub_items.php?itemid=' + row.PROD_ID,
                            fitColumns: true,
                            singleSelect: true,
                            rownumbers: true,
                            loadMsg: '',
                            height: 'auto',
                            columns: [[
                                    {field: 'SUBPROD_ID', title: 'ID', width: 80},
                                    {field: 'SUBPROD_NOME', title: 'Sub product', width: 80},
                                    {field: 'SUBPROD_DESCR', title: 'Description', width: 100},
                                    {field: 'action', title: 'Action', width: 35, align: 'center',
                                        formatter: function(value, row, index) {
                                            var a = '<a href="#" style="color: black;" onclick="deleteSubItems(this)"><b>Delete</b></a>';
                                            return a;
                                        }
                                    }
                                ]],
                            onResize: function() {
                                $('#dg').datagrid('fixDetailRowHeight', index);
                            },
                            onLoadSuccess: function() {
                                setTimeout(function() {
                                    $('#dg').datagrid('fixDetailRowHeight', index);
                                }, 0);
                            }
                        });
                        $('#dg').datagrid('fixDetailRowHeight', index);
                    }
                });
            });
</script>

$(函数(){
$('#dg')。数据网格({
视图:详细视图,
detailFormatter:函数(索引,行){
返回“”;
},
onExpandRow:函数(索引,行){
var ddv=$('#dg').datagrid('getRowDetail',index.).find('table.ddvclass');
数据网格({
url:'get_sub_items.php?itemid='+row.PROD_ID,
菲特:是的,
singleSelect:true,
行数:对,
loadMsg:“”,
高度:“自动”,
栏目:[[
{字段:'subpod_ID',标题:'ID',宽度:80},
{字段:'子产品名称',标题:'子产品',宽度:80},
{字段:'subpod_DESCR',标题:'Description',宽度:100},
{字段:'action',标题:'action',宽度:35,对齐:'center',
格式化程序:函数(值、行、索引){
var a=“”;
返回a;
}
}
]],
onResize:function(){
$('#dg').datagrid('fixDetailRowHeight',index);
},
onload成功:函数(){
setTimeout(函数(){
$('#dg').datagrid('fixDetailRowHeight',index);
}, 0);
}
});
$('#dg').datagrid('fixDetailRowHeight',index);
}
});
});
删除分项

function deleteSubItems(target) {
            $.messager.confirm('Confirmation', 'Are you sure?', function(r) {
                if (r) {
                    var row = $('#ddv').datagrid('getSelected');    <<<<<<<< HOW GET AND DELETE SUB ITEM (SUB ROW)? THIS IS NOT WORKING.
                    $.post('delete_sub_items.php', {id: row.SUBITEM_ID}, function(result) {
                        if (result.success) {
                            $('#ddv').datagrid('reload');
                        } else {
                            $.messager.show({
                                title: 'Erro',
                                msg: result.msg
                            });
                        }
                    }, 'json');
                }
            });
        }
函数删除子项(目标){
$.messager.confirm('Confirmation','you sure',function(r){
if(r){

var row=$('#ddv')。datagrid('getSelected');使用

在以下
onLoadSuccess
中,您可以添加事件处理程序,如下所示:

handler: function(){
    ddv.edatagrid('destroyRow');
}
onLoadSuccess: function() {
    setTimeout(function() {
        $('#dg').datagrid('fixDetailRowHeight', index);
    }, 0);
    $(this).datagrid('getPanel').find('.easyui-linkbutton').each(function(){
        $(this).linkbutton({
            onClick:function(){
                var id = $(this).attr('row-id');
// destroy using your delete function excluding var row line.
//$.post('delete_sub_items.php', {id: id},....
            }
        })
    })
}
您需要在url下面包含销毁url

ddv.edatagrid({
         url: 'get_sub_items.php?itemid=' + row.PROD_ID,
         destroyUrl: 'delete_sub_items.php',
但还有另一种解决方案,即使用您的方法:尝试以下方法:

function formatDetail(value,row){
    return '<a href="#" class="easyui-linkbutton" 
    iconCls="icon-remove"  row-id="'+row.id+'">Delete</a>';
}
最后,您必须更改您的onLoadSuccess,如下所示:

handler: function(){
    ddv.edatagrid('destroyRow');
}
onLoadSuccess: function() {
    setTimeout(function() {
        $('#dg').datagrid('fixDetailRowHeight', index);
    }, 0);
    $(this).datagrid('getPanel').find('.easyui-linkbutton').each(function(){
        $(this).linkbutton({
            onClick:function(){
                var id = $(this).attr('row-id');
// destroy using your delete function excluding var row line.
//$.post('delete_sub_items.php', {id: id},....
            }
        })
    })
}