jqGrid删除已传递ID的行

时间:2014-11-21 07:40:30

标签: jquery jqgrid

我的jqGrid脚本:

<script type="text/javascript">

var delete_task_url = "/controller/deleteRecordAction";
var gr = jQuery("#grid").jqGrid('getGridParam','selrow');
jQuery("#grid").jqGrid({
    url:call_url,
        datatype: "json",
    height: 'auto',
    rowNum: 20,
    rowList: [20,30],
    colNames:['Task#','Project ID','Task Name', 'Start Date', 'End Date', 'Created By', 'Created Date', 'Status', 'Action'],
    colModel:[
        {name:'USER_ID',index:'TASK_ID', align:'center',search:false },
        {name:'USER_NAME',index:'TASK_NAME', search:false},
        {name:'ACTION',index:'link', search:false,align:'center',sortable:false, formatter: 'actions',
        formatoptions: {
            keys: true,
            editformbutton: true,
            delOptions: { url: delete_task_url}
        }},
    ],
    pager: "#page",
    shrinkToFit :true,
    autowidth: true,
    viewrecords: true,
    sortname: 'TASK_ID',
    caption: "Task List",
    gridComplete: function () {
                    var recs = $("#grid").getGridParam("records");
                    $( ".mycontent" ).remove();
                    if (recs == 0 || recs == null) {
                        $('#grid').after("<div class='mycontent' style='color:red;text-align:center'>No Record Found</div>");

                    }

                }
}).navGrid('#page',{ edit:false,add:false,del:true,search:false,cloneToTop:true,refresh:false},
            {

             },{
             //add options


             },{

                        //msg: "do you really want delete this keyword? This delete affect on Eqms filter"

                });
                jQuery("#grid").jqGrid('filterToolbar', { autosearch: true  });
            var topPagerDiv = $('#grid_toppager')[0]; 
            jQuery("#grid_toppager_center", topPagerDiv).remove();

</script>

演示随后:

Working Example

我没有任何可以传递UserId的复选框,并根据该选项删除记录。如何在点击UserId图标时传递trash并删除记录?

感谢。

1 个答案:

答案 0 :(得分:1)

如果USER_ID列包含唯一ID数据,那么您只需将key: true属性添加到USER_ID中列colModel的定义即可。结果,jqGrid将以oper=del&id=48803的形式将数据发布到服务器。如果您想要oper=del&id=48803,则可以另外使用prmNames: { id: "USER_ID" } option。因此,在编辑/删除数据期间,将发布到服务器的参数名称将更改为oper=del&USER_ID=48803

顺便说一句,代码开头的行var gr = jQuery("#grid").jqGrid('getGridParam','selrow');应该被移除,因为在之前尝试获取selrow参数的值将创建网格。我建议您另外向网格添加gridview: true选项。