开发者

delete record in jqgrid in asp.net

I want to delete a record in jqgrid. For this I have the image and when the user clicks on this the record is getting deleted.

But I want to show the confirm box and when true then only the record should get deleted.

So any one can tell how to call javascript in jqgrid.

My jqgrid is

jQuery(document).ready(function() {
    jQuery("#list47").jqGrid({
        url: 'AddFilterGrid.aspx?Show=ViewFilter',
        datatype: "json",
        id: "F开发者_Python百科ilterName",
        colNames: ["SubCategory", "Filter", 'Delete', 'Edit'],
        colModel: [{
                name: 'CategoryName',
                index: 'CategoryName',
                width: 150,
                align: 'left',
                sortable: true,
                sorttype: 'text'
            }, {
                name: 'FilterName',
                index: 'FilterName',
                width: 150,
                align: 'left',
                sortable: true,
                sorttype: 'text'
            }, {
                name: 'f',
                index: 'f',
                width: 100,
                align: "center",
                formatter: 'showlink',
                formatter: formateadorLinkDelete
            }, {
                name: 'FilterId',
                index: 'FilterId',
                width: 100,
                align: "center",
                formatter: 'showlink',
                formatter: formateadorLinkEdit
            },

        ],
        height: 280,
        width: 650,
        //autowidth: true,
        mtype: "GET",
        pager: '#plist47',
        rowNum: 10,
        rowList: [10, 20, 30, 40],
        repeatitems: false,
        viewrecords: true,
        sortname: 'FilterName',
        viewrecords: true,
        sortorder: "desc",
        gridview: true,
        imgpath: '/Scripts/themes/redmond/images'
    });

});


Make a column with a delete button, give your button an attribute with the id, so you can post that id to delete it.

do a post to your delete controller

$.post('url/delete/$(this).val("deletid")', function(data) {
  $('.result').html(data);
});

@ edit: create a delete link in one of your colums, with class="delete" and deleteid="the id" you can create a confirm popup box:

$(function(){
    $(.delete).foreach(function(){
        $('#dialog').dialog({
            autoOpen: false,
            width: 400,
            modal: true,
            resizable: false,
            buttons: {
                "Submit":  function(){
                             $.post('url/delete/$(this).val("deletid")', function(data) {

                                //find your tr and hide it
                                $(this).parent().parent.... .hide();
                             });
                           };
                },
                "Cancel": function() {
                    $(this).dialog("close");
                }
            }
        });  
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜