开发者

jqGrid reloadGrid not working when last record is removed

I have a jqGrid on my page that receives its records using a json post to the server. On the same page, I also have a delete button. Clicking the delete button uses an ajax post to the server to delete the selected record. After deleting the record, if the server returns a success code, I need the grid to refresh.

It seems to be working fine except when there is only one record in the grid. The last record I delete is never removed from the grid. Even if i press the refresh button on the footer it still won't go away. When there is more than one record it refreshes as I would expect it to.

I am new to jqGrid so I am sure I am doing something wr开发者_开发技巧ong. Any help would be appreciated.

jqGrid definition

    $('#gridOrgs').jqGrid({
        url: 'some url goes here',
        datatype: 'json',
        mtype: 'POST',
        loadonce:false,
        colNames: ['ID', 'Name', 'City', 'Province', 'Admin'],
        colModel: [
            { name: 'Id', index: 'Id', hidedlg: true, hidden: true, sortable: false },
            { name: 'CompanyName', index: 'CompanyName', width: 200, sorttype: 'text' },
            { name: 'City', index: 'City', width: 150, sorttype: 'text' },
            { name: 'Province', index: 'Province', width: 150, sorttype: 'text' },
            { name: 'IsAdmin', index: 'IsAdmin', width: 50, sorttype: 'text', formatter: 'checkbox', align: 'center'},
            ],
        pager: '#pagerOrgs',
        jsonReader: {
            repeatitems: false,
            id: 'Id' },
        rowNum: 10,
        rowList: [10, 25, 50, 75, 100],
        sortname: 'CompanyName',
        sortorder: 'desc',
        viewrecords: true,
        caption: 'Companies',
        hidegrid: false,
        width: 650,
        height: 400,
        onSelectRow: function (id) {
                if (id)
                    RowSelected(id, $('#gridOrgs').getCell(id,'IsAdmin'));
                else
                    NoRowSelected();
            }
    });
    jQuery("#gridOrgs").jqGrid('navGrid','#pagerOrgs',{edit:false,add:false,del:false});

Delete button click event:

    $('#btnDelete').click(function() {
        var id = jQuery("#gridOrgs").jqGrid('getGridParam','selrow');

        if (id)
           $.post('@Url.Action("Json_Delete", "Organization")', {'id': id}, function(data){ProcessDeleteResponse(data.result);}, 'json');
        else
            $('#dialogNothingSelected').dialog('open');
    });

    function ProcessDeleteResponse(resultCode) {
        if (resultCode == 'success')
            $('#gridOrgs').trigger('reloadGrid'); 
    }

I have also tried

.trigger('reloadGrid', [{page:1}]);

.trigger('reloadGrid', [{current:true}]);

No matter what I do, the last record stays in the grid.

One last thing: When I trigger reloadGrid, the grid DOES make a call to the server and receives the updated information. The updated information contains 0 for the total number of records.

Thanks Again.


It seems I was able to resolve this issue by making a call to the following method:

$('#gridOrgs').jqGrid('delRowData', id);

Let me know if anyone has a better solution.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜